mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 03:01:36 +00:00
feat(gateway): add auth rate-limiting & brute-force protection (#15035)
* feat(gateway): add auth rate-limiting & brute-force protection Add a per-IP sliding-window rate limiter to Gateway authentication endpoints (HTTP, WebSocket upgrade, and WS message-level auth). When gateway.auth.rateLimit is configured, failed auth attempts are tracked per client IP. Once the threshold is exceeded within the sliding window, further attempts are blocked with HTTP 429 + Retry-After until the lockout period expires. Loopback addresses are exempt by default so local CLI sessions are never locked out. The limiter is only created when explicitly configured (undefined otherwise), keeping the feature fully opt-in and backward-compatible. * fix(gateway): isolate auth rate-limit scopes and normalize 429 responses --------- Co-authored-by: buerbaumer <buerbaumer@users.noreply.github.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9131b22a28
commit
30b6eccae5
@@ -43,6 +43,7 @@ import { startDiagnosticHeartbeat, stopDiagnosticHeartbeat } from "../logging/di
|
||||
import { createSubsystemLogger, runtimeForLogger } from "../logging/subsystem.js";
|
||||
import { getGlobalHookRunner } from "../plugins/hook-runner-global.js";
|
||||
import { runOnboardingWizard } from "../wizard/onboarding.js";
|
||||
import { createAuthRateLimiter, type AuthRateLimiter } from "./auth-rate-limit.js";
|
||||
import { startGatewayConfigReloader } from "./config-reload.js";
|
||||
import { ExecApprovalManager } from "./exec-approval-manager.js";
|
||||
import { NodeRegistry } from "./node-registry.js";
|
||||
@@ -270,6 +271,12 @@ export async function startGatewayServer(
|
||||
let hooksConfig = runtimeConfig.hooksConfig;
|
||||
const canvasHostEnabled = runtimeConfig.canvasHostEnabled;
|
||||
|
||||
// Create auth rate limiter only when explicitly configured.
|
||||
const rateLimitConfig = cfgAtStart.gateway?.auth?.rateLimit;
|
||||
const authRateLimiter: AuthRateLimiter | undefined = rateLimitConfig
|
||||
? createAuthRateLimiter(rateLimitConfig)
|
||||
: undefined;
|
||||
|
||||
let controlUiRootState: ControlUiRootState | undefined;
|
||||
if (controlUiRootOverride) {
|
||||
const resolvedOverride = resolveControlUiRootOverrideSync(controlUiRootOverride);
|
||||
@@ -340,6 +347,7 @@ export async function startGatewayServer(
|
||||
openResponsesEnabled,
|
||||
openResponsesConfig,
|
||||
resolvedAuth,
|
||||
rateLimiter: authRateLimiter,
|
||||
gatewayTls,
|
||||
hooksConfig: () => hooksConfig,
|
||||
pluginRegistry,
|
||||
@@ -478,6 +486,7 @@ export async function startGatewayServer(
|
||||
canvasHostEnabled: Boolean(canvasHost),
|
||||
canvasHostServerPort,
|
||||
resolvedAuth,
|
||||
rateLimiter: authRateLimiter,
|
||||
gatewayMethods,
|
||||
events: GATEWAY_EVENTS,
|
||||
logGateway: log,
|
||||
@@ -657,6 +666,7 @@ export async function startGatewayServer(
|
||||
skillsRefreshTimer = null;
|
||||
}
|
||||
skillsChangeUnsub();
|
||||
authRateLimiter?.dispose();
|
||||
await close(opts);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user