refactor(gateway): split browser auth hardening paths
This commit is contained in:
@@ -110,6 +110,21 @@ const logWsControl = log.child("ws");
|
||||
const gatewayRuntime = runtimeForLogger(log);
|
||||
const canvasRuntime = runtimeForLogger(logCanvas);
|
||||
|
||||
type AuthRateLimitConfig = Parameters<typeof createAuthRateLimiter>[0];
|
||||
|
||||
function createGatewayAuthRateLimiters(rateLimitConfig: AuthRateLimitConfig | undefined): {
|
||||
rateLimiter?: AuthRateLimiter;
|
||||
browserRateLimiter: AuthRateLimiter;
|
||||
} {
|
||||
const rateLimiter = rateLimitConfig ? createAuthRateLimiter(rateLimitConfig) : undefined;
|
||||
// Browser-origin WS auth attempts always use loopback-non-exempt throttling.
|
||||
const browserRateLimiter = createAuthRateLimiter({
|
||||
...rateLimitConfig,
|
||||
exemptLoopback: false,
|
||||
});
|
||||
return { rateLimiter, browserRateLimiter };
|
||||
}
|
||||
|
||||
export type GatewayServer = {
|
||||
close: (opts?: { reason?: string; restartExpectedMs?: number | null }) => Promise<void>;
|
||||
};
|
||||
@@ -311,16 +326,10 @@ export async function startGatewayServer(
|
||||
let hooksConfig = runtimeConfig.hooksConfig;
|
||||
const canvasHostEnabled = runtimeConfig.canvasHostEnabled;
|
||||
|
||||
// Create auth rate limiter only when explicitly configured.
|
||||
// Create auth rate limiters used by connect/auth flows.
|
||||
const rateLimitConfig = cfgAtStart.gateway?.auth?.rateLimit;
|
||||
const authRateLimiter: AuthRateLimiter | undefined = rateLimitConfig
|
||||
? createAuthRateLimiter(rateLimitConfig)
|
||||
: undefined;
|
||||
// Always keep a browser-origin fallback limiter for WS auth attempts.
|
||||
const browserAuthRateLimiter: AuthRateLimiter = createAuthRateLimiter({
|
||||
...rateLimitConfig,
|
||||
exemptLoopback: false,
|
||||
});
|
||||
const { rateLimiter: authRateLimiter, browserRateLimiter: browserAuthRateLimiter } =
|
||||
createGatewayAuthRateLimiters(rateLimitConfig);
|
||||
|
||||
let controlUiRootState: ControlUiRootState | undefined;
|
||||
if (controlUiRootOverride) {
|
||||
|
||||
Reference in New Issue
Block a user