mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:38:28 +00:00
fix: honor trusted proxy client IPs (PR #1654)
Thanks @ndbroadbent. Co-authored-by: Nathan Broadbent <git@ndbroadbent.com>
This commit is contained in:
@@ -70,7 +70,7 @@ function mergeActionIntoArgsIfSupported(params: {
|
||||
export async function handleToolsInvokeHttpRequest(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
opts: { auth: ResolvedGatewayAuth; maxBodyBytes?: number },
|
||||
opts: { auth: ResolvedGatewayAuth; maxBodyBytes?: number; trustedProxies?: string[] },
|
||||
): Promise<boolean> {
|
||||
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
||||
if (url.pathname !== "/tools/invoke") return false;
|
||||
@@ -80,11 +80,13 @@ export async function handleToolsInvokeHttpRequest(
|
||||
return true;
|
||||
}
|
||||
|
||||
const cfg = loadConfig();
|
||||
const token = getBearerToken(req);
|
||||
const authResult = await authorizeGatewayConnect({
|
||||
auth: opts.auth,
|
||||
connectAuth: token ? { token, password: token } : null,
|
||||
req,
|
||||
trustedProxies: opts.trustedProxies ?? cfg.gateway?.trustedProxies,
|
||||
});
|
||||
if (!authResult.ok) {
|
||||
sendUnauthorized(res);
|
||||
@@ -110,7 +112,6 @@ export async function handleToolsInvokeHttpRequest(
|
||||
: {}
|
||||
) as Record<string, unknown>;
|
||||
|
||||
const cfg = loadConfig();
|
||||
const rawSessionKey = resolveSessionKeyFromBody(body);
|
||||
const sessionKey =
|
||||
!rawSessionKey || rawSessionKey === "main" ? resolveMainSessionKey(cfg) : rawSessionKey;
|
||||
|
||||
Reference in New Issue
Block a user