Skip to content

fix(limiter): complete pre-auth family coverage (auth + bootstrap) + new advisory bumps - #461

Closed
Alajmah wants to merge 1 commit into
masterfrom
security/limiter-identity-v6
Closed

Alajmah wants to merge 1 commit into
masterfrom
security/limiter-identity-v6

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Final branch of the limiter identity remediation (supersedes #454 → #456 → #458 → #459 → #460; branch updates ruleset-refused). Two things on this head:

1. The required pre-auth family extension

Your finding was right — /api/auth/check (session-cookie Redis lookup) and /api/bootstrap/state + /first (anonymous DB work) both mount before apiKeyAuth and carried the same bucket-rotation mechanism. The pre-auth match now covers the complete /api/auth/* and /api/bootstrap/* families — prefix regex, case + trailing-slash tolerant. Bearer identity unchanged for ordinary authenticated routes.

New regressions (3):

  • AUTH-CHECK: 130 requests, one valid session, rotating Bearer tokens → 429 at 121 on ONE shared IP bucket.
  • BOOTSTRAP-STATE: 130 anonymous rotating-Bearer requests → 429 at 121 on ONE bucket.
  • FAMILY VARIANTS: 8 path forms (logout, check, first, state, bare prefixes, case + trailing-slash) all key on the IP — the token never appears in any bucket key.

All prior regressions carry: the session-cookie reproducer-fixed, login end-to-end, variant tolerance, TTL pin, fail-open documentation.

2. Newly published advisories — the #457 master-push CI already failed on them

The push CI for the #457 merge (37ea5c4) failed production-dependency-audit on seven newly published advisories (three critical): next ≤16.4.0 (critical GHSA-2464, critical GHSA-673q, high GHSA-p3m5 — affects both the dashboard's 16.3.8 and the landing's 15.5.24), body-parser <1.20.9 (high), zod <4.6.6 (high). This branch carries the bumps: next 16.4.6 (dashboard), next 15.5.28 (landing), body-parser 1.20.9 (override), zod 4.6.7 — lockfile entries hand-carried with registry integrities (the known Windows npm override quirk). Local audit gate: 0 high/critical. Production is still at 8c9b93b (the deploy correctly skipped on the failed audit); merging this branch restores the audit gate and deploys both the limiter fix and the #457 body cap together.

Identity suite 17 + behavior suite 9 — all green locally. Holding at the merge gate — exact head 5722a74fbc1e77c5382c7c26f23b314878bc5019.

PRE-AUTH EXTENSION (maintainer finding on #460): two additional route
families execute before apiKeyAuth and were susceptible to the same
bucket-rotation mechanism the login fix closed — /api/auth/check
(session-cookie Redis lookup; rotating Bearer headers mint buckets while
the cookie authenticates) and /api/bootstrap/state + /first (anonymous
DB work; rotating Bearer values get fresh buckets). The pre-auth match
now covers the COMPLETE /api/auth/* and /api/bootstrap/* families
(prefix regex, case + trailing-slash tolerant). Bearer identity is
unchanged for ordinary authenticated routes.

Three-layer remediation summary (all carried from v2-v5):
1. Session-cookie rotation bypass CLOSED (apiKeyAuth-exact Bearer
   recognition; both parses byte-identical).
2. Pre-auth login bypass CLOSED (login keys on IP).
3. Route-variant bypass CLOSED (trailing slash + case tolerated).
Now: complete pre-auth family coverage (auth + bootstrap).

ADVISORY BUMPS (newly published; the #457 master-push CI already
failed on them): next 16.3.8→16.4.6 (dashboard; critical GHSA-2464,
GHSA-673q, high GHSA-p3m5), next 15.5.24→15.5.28 (landing),
body-parser 1.20.6→1.20.9 (override; high GHSA-27r3), zod
3.25.76→4.6.7 (web; high GHSA-mrhx). Lockfile entries hand-carried
with registry integrities. Local audit gate: 0 high/critical.

Identity suite 17 + behavior suite 9 — all green locally.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-20T18:45:29.049547Z
We couldn’t complete this review. Comment @codex review to try again.
5722a74 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/gitwire run review

@gitwire-hq

gitwire-hq Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

▶️ GitWire: Re-evaluation triggered for review. Results will appear shortly.

@gitwire-hq gitwire-hq Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review — 💬 Needs discussion

Confidence: low · Findings: 8
AI judgment: NEEDS DISCUSSION · Evidence: COMPLETE · Authority: advisory
Evidence complete · 7/7 changed files accounted for

Other findings (8)

  • [medium] zod major upgrade (^3.22.0 -> ^4.6.6) bundled into a security patch with no visible migration changes
  • [medium] Landing app next 15.5.28 bump claimed in the PR description is absent from the diff ⚠️ unverified
  • [low] Pre-auth IP-keying depends on a hardcoded prefix allowlist that must stay in sync with app.js and assumes root mounting
  • [low] Residual (pre-existing): well-formed but invalid Bearer tokens still mint unlimited buckets on ordinary paths
  • [medium] IP-derivation trust unexamined: spoofable X-Forwarded-For would defeat the fix at the IP layer ⚠️ unverified

🔮 Devil's Advocate (2 turns): 4 missed risks found · 4 upheld


GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority

Finding details (not annotatable inline)

  • [MEDIUM] Landing app next 15.5.28 bump claimed in the PR description is absent from the diff (package.json)

    The description states this branch carries 'next 15.5.28 (landing)' to clear the critical advisories (GHSA-2464, GHSA-673q) that 'affect both the dashboard's 16.3.8 and the landing's 15.5.24', and that merging restores the audit gate. However, the only next change in the 6 changed files is the dashboard's bump (web-dashboard 16.3.8 -> 16.4.6); packages/web's manifest changes only the zod line, and no landing manifest appears in the diff at all. If the landing app (at 15.5.24 per the description) lives in this monorepo and was not already patched on master, the production-dependency-audit gate will still fail after merge and the critical next advisories remain unpatched in production. Verify the landing's next version is >= 15.5.28 (or that its bump landed separately) before merging; otherwise include the manifest change here.

  • [MEDIUM] IP-derivation trust unexamined: spoofable X-Forwarded-For would defeat the fix at the IP layer

    The review scrutinized token rotation (the old keying basis) but never asked how the NEW keying basis — the IP — is derived. If the limiter or the app trusts X-Forwarded-For without a trusted-proxy allowlist (Express 'trust proxy' misconfiguration is extremely common), an unauthenticated caller can rotate spoofed source IPs on /api/auth and /api/bootstrap just as they rotated Bearer tokens, and the entire fix is cosmetic. Additionally, blind XFF trust enables bucket-filling attacks against a victim IP (forced 429 lockout of a specific client). This is conditional — req.ip behind a correctly configured proxy is fine — but it is the single highest-value question this PR's diff raises and the review never asked it. Verify the identity-derivation code path before merge.

  • [MEDIUM] No regression test asserted for the core fix: distinct unauthenticated credentials on pre-auth routes must share one IP-keyed bucket

    The PR's stated purpose is 'complete pre-auth family coverage', yet the review flagged no test evidence anywhere: nothing asserting that two requests to /api/bootstrap with different garbage credentials land in the same bucket, that the prefix matching works per family, or that Bearer presentation on pre-auth routes doesn't fork a new bucket. Finding #2 establishes that the fix depends on a fragile prefix list with no structural link to app.js — without a characterization test, the exact regression this PR fixes can silently return via any future mount change and no CI gate would notice. For a fix PR, the absence of a pinned regression test is a first-class gap.

  • [LOW] IP-keying pre-auth families (especially /api/bootstrap) creates shared-IP collateral lockout for NAT/office/corporate egress

    Moving pre-auth identity from per-credential to per-IP concentrates all users behind a shared egress (office NAT, corporate proxy, mobile carrier CGNAT) into one bucket. A single noisy client — or one security scanner hitting /api/bootstrap — can 429 the bootstrap/first-load path for an entire building, turning a brute-force mitigation into an availability regression for legitimate users. The review analyzed attacker-side bypass thoroughly but never assessed the legitimate-user side of the trade-off. Worth at least confirming the bucket limits are sized for shared-IP populations, not per-individual.

  • [LOW] Zod version-skew / lockfile consistency across the monorepo not checked

    The review flagged the zod major bump itself (Finding #0) but not its monorepo mechanics: the PR spans multiple packages/projects ('Octo-Lex/GitWire'), and bumping zod only in packages/web's manifest can leave other workspace packages pinned on v3 via a stale lockfile, producing dual zod copies, dedupe drift, or instanceof/schema-brand mismatches at boundaries where v3-validated data crosses into v4-validated code. If the lockfile wasn't regenerated in the same commit, CI may silently install mixed majors. Cheap to verify: one lockfile diff inspection and a workspace-wide 'zod' grep.

Comment thread packages/web/package.json
"pino-pretty": "^10.0.0",
"yaml": "^2.9.0",
"zod": "^3.22.0"
"zod": "^4.6.6"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] zod major upgrade (^3.22.0 -> ^4.6.6) bundled into a security patch with no visible migration changes

packages/web/package.json jumps zod across a major version (^3.22.0 -> ^4.6.6) inside a PR otherwise scoped to a rate-limiter fix and audit bumps. Zod v4 ships documented breaking changes: z.record() now requires an explicit key schema, error-customization options (invalid_type_error/required_error) were replaced by error, default error messages and some inferred types changed. No call-site changes accompany the bump in this diff, so any web package validation code relying on v3-only APIs or messages will either throw at runtime (500s) or silently change validation/error behavior. Suggested fix: grep the zod call sites in packages/web, run the full integration suite against v4 before merge, or split this major bump into its own reviewed PR and keep the security patch minimal (if the advisory is only fixed in 4.x, that constraint should be stated in the PR body).

export function deriveLimiterIdentity(req) {
const authHeader = req.headers.authorization;
const isPreAuthPath = typeof req.path === "string"
&& (/^\/api\/auth(\/.*)?\/?$/i.test(req.path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Pre-auth IP-keying depends on a hardcoded prefix allowlist that must stay in sync with app.js and assumes root mounting

deriveLimiterIdentity hardcodes /api/auth and /api/bootstrap prefixes as the set of pre-authentication families. Two concrete fragilities: (1) if a future route is mounted before apiKeyAuth under any other prefix (or a new pre-auth route appears in app.js), it silently reverts to Bearer-keyed buckets and reintroduces the rotation bypass this PR fixes; nothing structural links this list to the actual mount order. (2) The check tests req.path, which is relative to the middleware's mount point; if rateLimiter is ever mounted under a sub-path (app.use('/api', rateLimiter)), req.path becomes '/auth/login', the prefixes stop matching, and Bearer-keyed buckets return on pre-auth routes. Suggested fix: export a single PRE_AUTH_PREFIXES constant consumed by both app.js and the limiter, and match against req.originalUrl (or normalize baseUrl + path) so the contract survives re-mounting.

const isPreAuthPath = typeof req.path === "string"
&& (/^\/api\/auth(\/.*)?\/?$/i.test(req.path)
|| /^\/api\/bootstrap(\/.*)?\/?$/i.test(req.path));
const bearerToken = !isPreAuthPath && typeof authHeader === "string" && authHeader.slice(0, 7) === "Bearer "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Residual (pre-existing): well-formed but invalid Bearer tokens still mint unlimited buckets on ordinary paths

The fix closes the non-Bearer rotation bypass, but on non-pre-auth paths the identity is still the raw token before it is validated (limiter runs before apiKeyAuth). An unauthenticated caller can rotate syntactically valid Bearer strings ('Bearer random-N') on any ordinary /api/* route to create a fresh Redis bucket per request; each request fails auth so protected handlers are never reached, but per-IP throttling never applies and Redis key churn is unbounded apart from the 60s TTL. This is the documented design contract (and is pre-existing), but since this PR is the identity-remediation, consider noting the residual explicitly in the contract comment or capping distinct buckets per source IP.

@gitwire-hq

gitwire-hq Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

✅ GitWire: A review is already published for this head — no new review was posted. Outcome: NEEDS_DISCUSSION.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the v7 PR: adds the next 16.4.6 build fixes (proxy.ts rename + SWC binary alignment) the v6 CI exposed, on top of the family extension and advisory bumps.

@Alajmah Alajmah closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant