fix(gateway): cap auth limiter entries#96224
Conversation
|
[CODEX BEHAVIORAL PROOF] I checked the live PR surfaces before posting this: there are no existing PR comments or review comments from ClawSweeper, and no existing eleqtrizit re-review comment to delete. What the change proves:
Focused regression coverage in this PR:
Behavioral probe I ran locally against the production authorization path: corepack pnpm exec tsx - <<'EOF_PROOF'
import {
AUTH_RATE_LIMIT_SCOPE_SHARED_SECRET,
createAuthRateLimiter,
} from "./src/gateway/auth-rate-limit.ts";
import { authorizeGatewayConnect } from "./src/gateway/auth.ts";
const limiter = createAuthRateLimiter({ pruneIntervalMs: 0 });
const attempts = 10_001;
const makeIp = (index: number) => `198.51.${Math.floor(index / 254)}.${(index % 254) + 1}`;
for (let i = 0; i < attempts; i += 1) {
const result = await authorizeGatewayConnect({
auth: { mode: "token", token: "expected-token", allowTailscale: false },
connectAuth: { token: "wrong-token" },
req: {
socket: { remoteAddress: "127.0.0.1" },
headers: { "x-forwarded-for": makeIp(i) },
} as never,
trustedProxies: ["127.0.0.1"],
rateLimiter: limiter,
});
if (result.ok || result.reason !== "token_mismatch") {
throw new Error(`unexpected auth result at ${i}: ${JSON.stringify(result)}`);
}
}
const firstClient = limiter.check(makeIp(0), AUTH_RATE_LIMIT_SCOPE_SHARED_SECRET);
const lastClient = limiter.check(makeIp(attempts - 1), AUTH_RATE_LIMIT_SCOPE_SHARED_SECRET);
const proof = {
attempts,
retainedEntries: limiter.size(),
firstClientRemaining: firstClient.remaining,
lastClientRemaining: lastClient.remaining,
firstClientAllowed: firstClient.allowed,
lastClientAllowed: lastClient.allowed,
};
if (proof.retainedEntries !== 10_000 || proof.firstClientRemaining !== 10 || proof.lastClientRemaining !== 9) {
throw new Error(`proof assertion failed: ${JSON.stringify(proof)}`);
}
console.log(JSON.stringify(proof, null, 2));
limiter.dispose();
EOF_PROOFOutput: {
"attempts": 10001,
"retainedEntries": 10000,
"firstClientRemaining": 10,
"lastClientRemaining": 9,
"firstClientAllowed": true,
"lastClientAllowed": true
}This exercises the real Validation run now:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Codex review: needs maintainer review before merge. Reviewed June 23, 2026, 11:09 PM ET / 03:09 UTC. Summary PR surface: Source +59, Tests +82. Total +141 across 2 files. Reproducibility: yes. Source inspection of current main and v2026.6.9 shows Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge one canonical normalized Gateway auth limiter cap after maintainer confirmation that this branch supersedes the older overlapping PR and that the fail-closed saturated-table behavior is the desired availability/security tradeoff. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection of current main and v2026.6.9 shows Is this the best way to solve the issue? Yes. The insert-time cap is the narrow Gateway-owned fix for the reported flood; keeping AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d15e89a83e61. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +59, Tests +82. Total +141 across 2 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
(cherry picked from commit bcbd521)
Summary
Caps the Gateway auth rate limiter's tracked client entries so failed-auth bookkeeping cannot grow without bound between prune sweeps.
Changes
maxEntriesoption with a default cap of 10,000 tracked identities.Validation
corepack pnpm exec oxfmt --check --threads=1 src/gateway/auth-rate-limit.ts src/gateway/auth-rate-limit.test.tsnode scripts/run-vitest.mjs src/gateway/auth-rate-limit.test.ts(4 files, 136 tests).agents/skills/autoreview/scripts/autoreview --mode local(clean)Notes
CHANGELOG.mdwas not updated.