mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 15:20:23 +00:00
fix(gateway): honor trusted proxy hook auth rate limits
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
import {
|
||||
authorizeHttpGatewayConnect,
|
||||
isLocalDirectRequest,
|
||||
resolveRequestClientIp,
|
||||
type GatewayAuthResult,
|
||||
type ResolvedGatewayAuth,
|
||||
} from "./auth.js";
|
||||
@@ -351,9 +352,13 @@ export function createHooksRequestHandler(
|
||||
bindHost: string;
|
||||
port: number;
|
||||
logHooks: SubsystemLogger;
|
||||
getClientIpConfig?: () => {
|
||||
trustedProxies?: string[];
|
||||
allowRealIpFallback?: boolean;
|
||||
};
|
||||
} & HookDispatchers,
|
||||
): HooksRequestHandler {
|
||||
const { getHooksConfig, logHooks, dispatchAgentHook, dispatchWakeHook } = opts;
|
||||
const { getHooksConfig, logHooks, dispatchAgentHook, dispatchWakeHook, getClientIpConfig } = opts;
|
||||
const hookAuthLimiter = createAuthRateLimiter({
|
||||
maxAttempts: HOOK_AUTH_FAILURE_LIMIT,
|
||||
windowMs: HOOK_AUTH_FAILURE_WINDOW_MS,
|
||||
@@ -364,7 +369,14 @@ export function createHooksRequestHandler(
|
||||
});
|
||||
|
||||
const resolveHookClientKey = (req: IncomingMessage): string => {
|
||||
return normalizeRateLimitClientIp(req.socket?.remoteAddress);
|
||||
const clientIpConfig = getClientIpConfig?.();
|
||||
const clientIp =
|
||||
resolveRequestClientIp(
|
||||
req,
|
||||
clientIpConfig?.trustedProxies,
|
||||
clientIpConfig?.allowRealIpFallback === true,
|
||||
) ?? req.socket?.remoteAddress;
|
||||
return normalizeRateLimitClientIp(clientIp);
|
||||
};
|
||||
|
||||
return async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user