Repository navigation
fix(auth): remove stale query-param comment — limiter identity chain v9 - #464
Conversation
…n (next 16.4.6, body-parser, zod) PRE-AUTH EXTENSION (maintainer finding on #460): /api/auth/check (session-cookie Redis lookup) and /api/bootstrap/state + /first (anonymous DB work) 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. Three new regressions: AUTH-CHECK end-to-end (130 rotating-Bearer session requests → 429@121 ONE bucket); BOOTSTRAP-STATE end-to-end (130 anonymous → 429@121 ONE bucket); FAMILY VARIANTS (8 path forms all key on the IP). THREE-LAYER REMEDIATION (carried): session-cookie rotation closed (apiKeyAuth-exact recognition); pre-auth login closed (IP-keyed); route-variant closed (trailing slash + case); derivation isolated (derived as an exported function — the CodeQL missing-rate-limiting model pairing resolved without behavior change). ADVISORY REMEDIATION (the #457 master-push CI failed on seven new advisories, three critical, on next ≤16.4.0): - next 16.3.8→16.4.6 (dashboard; GHSA-2464 critical, GHSA-673q critical, GHSA-p3m5 high): requires middleware.ts→proxy.ts rename (function export renamed too) + @next/swc platform binaries hand-carried to 16.4.6 (the version mismatch crashed builds with 'Cannot read properties of undefined (reading project)'). - next 15.5.24→15.5.28 (landing; same advisories' 13.x-15.x range). - body-parser 1.20.6→1.20.9 (override; GHSA-27r3 high). - zod 3.25.76→4.6.7 (web; GHSA-mrhx high). Lockfile entries hand-carried with registry integrities (npm on Windows refused to re-resolve overrides + platform binaries — the known quirk). VERIFICATION: audit gate 0 high/critical; limiter identity (17) + behavior (9) + webhook body-limit (14) = 40 tests green; dashboard 5 suites / 66 tests green; dashboard build verified locally (compiled successfully, 29/29 static pages). Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
…t; demo-dashboard manifest sync Adjudication corrections for the v7 chain (#462 review): - apiKeyAuth and deriveLimiterIdentity held unlinked copies of the same Bearer recognition rule, kept in sync only by comments. Both now call a shared extractBearerToken() (bearerToken.js), and a 12-case corpus contract test pins the one rule both mechanisms depend on — divergence in either direction becomes a test failure, not a silent re-opening of the bucket-rotation bypass. - Fixed a garbled test comment that cited a nonexistent ^Bearer\s+ regex for the tab-scheme case; apiKeyAuth actually uses a literal starts-with "Bearer " check, byte-identical to the limiter's recognition. - demo-dashboard manifest pinned next 15.5.24 while the hand-carried lockfile resolves 15.5.28 — any npm install would have silently reverted the advisory floor. Manifest now matches the lockfile (npm ci dry-run verified); demo dashboard build verified green under 15.5.28. Limiter semantics unchanged: 38 limiter tests + 15 triage-pr-guards green. Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
The comment said 'Extract key from header or query param' but no
query-parameter authentication path exists (nor has one in the current
implementation's history) — the header is the only in-band key channel.
Confirmed against the code: zero req.query reads in auth.js. The stale
line drew a review finding ('query-param auth has no limiter identity
counterpart') whose premise was the comment, not the code.
Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
🤖 AI Code Review — ✅ Approved
Confidence: high · Findings: 4
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 11/11 changed files accounted for
Other findings (4)
- [low] Pre-auth path families duplicated as a hardcoded regex in the limiter; drift silently re-opens bucket minting
- [medium] IP-fallback keying on pre-auth routes is spoofable if trust proxy is misconfigured — the mirror of the Bearer-minting problem
⚠️ unverified - [medium] No regression test pinning that pre-auth requests carrying arbitrary Bearer tokens collapse into a single bucket
⚠️ unverified - [low] Deleting the query-param comment removes the recorded rationale for excluding query-param identity, inviting reintroduction for SSE/websocket support
⚠️ unverified
🔮 Devil's Advocate (2 turns): 3 missed risks found · 1 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] IP-fallback keying on pre-auth routes is spoofable if trust proxy is misconfigured — the mirror of the Bearer-minting problem
The review scrutinized attacker-controlled Bearer tokens as an identity source but never examined the other half of the identity chain: for pre-auth families the limiter falls back to client IP. If app.set('trust proxy') doesn't match the actual proxy topology, req.ip is derived from a spoofable X-Forwarded-For header and an attacker mints IP buckets exactly as they minted token buckets. The review applied 'is this identity attacker-controlled?' to tokens but not to IPs — an asymmetric audit of the same mechanism.
-
[MEDIUM] No regression test pinning that pre-auth requests carrying arbitrary Bearer tokens collapse into a single bucket
The corpus test pins token recognition, and existing limiter tests presumably pin keying for the two current families — but nothing asserts the actual invariant ('a request to any pre-auth path with a fresh attacker-supplied Bearer must reuse the path's bucket, not mint a new one'). That invariant-level test would also catch the future-drift scenario in finding #0 for free, making the review's suggested family-list pinning partially redundant; the review proposed the weaker of the two tests.
-
[LOW] Deleting the query-param comment removes the recorded rationale for excluding query-param identity, inviting reintroduction for SSE/websocket support
The PR's entire content is removing the 'stale' query-param comment. Stale-looking comments about rejected designs usually encode a decision ('tokens in query strings are attacker-controlled and leak into logs/proxy caches, so never key identity on them'). The first future contributor adding EventSource/SSE endpoints — where browsers cannot set Authorization headers — has no in-code pointer explaining why query-param identity was rejected, making v10 of this chain a reintroduction rather than a hypothetical. A one-line redirect to the corpus test or an ADR would have preserved the rationale at zero cost.
| // tolerance (Express's default non-strict, case-insensitive-to-route | ||
| // routing serves those variants to the same handlers). | ||
| // - Everything else falls back to the request IP. | ||
| export function deriveLimiterIdentity(req) { |
There was a problem hiding this comment.
[LOW] Pre-auth path families duplicated as a hardcoded regex in the limiter; drift silently re-opens bucket minting
deriveLimiterIdentity() hardcodes the pre-auth families (/api/auth/, /api/bootstrap/) as regex literals, but the same 'which routes are pre-auth' decision also lives in app.js mount order / auth.js's skip check. This PR carefully factored the Bearer-recognition rule into a single shared helper (bearerToken.js) plus a corpus contract test to prevent drift, yet the path-family rule remains copy-encoded. Concrete failure mode: a future pre-auth family (e.g., /api/register) added to auth but not to this regex will be keyed by the limiter on the attacker-controlled Bearer token, silently restoring the per-request bucket-minting/throttle-escape this chain fixes — with no test failing, since the corpus test only pins Bearer recognition, not the family list. Suggestion: export a shared isPreAuthPath()/family-constant module (analogous to bearerToken.js) consumed by both the limiter and the auth skip logic, and pin the family list in rate-limiter-identity.test.js so adding a family forces a coordinated change. Not blocking for this PR (the two prefixes are correct today and the regex's case/trailing-slash tolerance matches Express defaults), but it leaves the same class of drift the PR set out to eliminate.
Review adjudication (all 4 findings) — evidence-closed, none blockingVerdict per finding, with code and production evidence: F1 [low] Family set duplicated as hardcoded regex; drift re-opens minting. Valid hardening observation, non-blocking (review is APPROVE). The families live in two places: the F2 [medium] IP fallback spoofable if trust proxy misconfigured. Adjudicated with production evidence — the premise cannot arise in the current topology, and the actual property is the opposite one:
F3 [medium] No regression test pinning pre-auth + arbitrary Bearer → single bucket. Contradicted by the suite — three tests assert exactly the named invariant against the real middleware:
The residual gap is F1's: a future family added to app.js without extending the regex would not be covered by today's enumerated tests. That is the shared-constant follow-up, not a missing test of current behavior. F4 [low] Deleting the comment removed the rationale for excluding query-param identity. Premise false — no rationale was deleted. The removed line ("Extract key from header or query param") described an implementation detail that never existed: zero State for clearance: head |
Post-merge deployment verification — master
|
| Step | Result |
|---|---|
| Merge | #464 squash-merged at 2026-11-20T21:33:36Z → master 89d5e519c743b9851279ad506db01905ed17a719 |
| Push CI | PASS (the advisory failure that skipped #457's deploy is cleared by the bumps in this unit) |
| CodeQL (master) | PASS |
| Deploy to Production | completed success (run 44822373702) — staged recreation |
/health |
status: ok, git_sha: 89d5e519c743b9851279ad506db01905ed17a719 — exact match, not unknown |
| Containers | 10/10 healthy; app / executor-service / dashboard recreated at deploy, rest long-running |
| Migrations | 49/49 applied |
Deployed limiter — production proof (live, just now)
Two properties, each exercised with 3 requests (no threshold hammering):
- Ordinary route + rotating non-Bearer headers (
Basic scheme-rot-1..3→/api/repos, 401s): all three fell into the ONE shared tunnel-IP bucket — zero per-header buckets minted. (Pre-fix: each distinct header minted a fresh bucket.) - Pre-auth route + rotating well-formed Bearer (
Bearer family-rot-1..3→/api/auth/check, 200s): all three fell into the same ONE shared bucket — zero token buckets minted. (Pre-fix: each token minted a fresh bucket — the login brute-force bypass.)
Redis held exactly one shared key (ratelimit:::ffff:172.18.0.3) plus three 60s-TTL per-credential keys from a deliberately misdesigned earlier probe of mine (Bearer rot-* on an ordinary route — per-token buckets there are the documented intended behavior for distinct credentials, not a bypass).
CodeQL alert matrix — actual states at 89d5e51 (inspected via API, not inferred)
Closed since the last ledger (2):
- feat(governance): receipt evidence binding + pass-gate rewiring (v0.23.0 Task 6) #28
js/unvalidated-dynamic-method-call— fixed (fix(28): webhook dispatcher selects handlers by own property only #446 dispatch guard, deployed earlier; CodeQL confirms). - v0.20.3: Governance hardening — drift re-check, blocked reasons, marker comments #12
js/code-injection(plugins/loader.js:55) — fixed, correcting the running ledger that had it "open pending OS-boundary disposition": the Security-hardening unit: CodeQL alert triage and fixes (Critical #12 lead) #425 sandbox isolation chain (digest-pinned execution, identifiers-only protocol) closed it and CodeQL agrees. That hold is satisfied.
Open (22), by disposition:
| Set | Alerts | Classification vs deployed state |
|---|---|---|
| 13 API-route | #14-17 (config), #23/25/26 (maintainer), #29 (triageOperations), #31-35 (rollouts) | False positive — classification re-established, now WITH deployed evidence. All mount behind the app-level limiter (app.js:84, before every /api router). The query pairs in-handler credential reads with per-handler limiter sinks and cannot see app-level mounting. Production-proven rotation-proof identity above. Dismissals: 13, require authorization. |
| Same family, outside the counted 13 | #9 (phase4.js:352; mounts app.js:175 behind the limiter) | Same false-positive evidence as the 13-set; listed separately because the original classification set boundary excluded it. Dismissal requires authorization. |
| #10 | webhooks.js:33 | Open by design: /webhooks is deliberately limiter-exempt (GitHub HMAC-authenticated deliveries; a limiter would throttle GitHub retry behavior). The underlying resource-consumption concern is now bounded by the deployed 25MiB streaming cap (#457). Candidate false positive; dismissal requires authorization. |
| #13 | app.js:108 (routeAuthObserver mount) |
Retains its explicit hold (risk-acceptance authorization required before any disposition). Same model-pairing shape as the limiter's own mount was. |
| #36/#37 | parse.js:79, resolve.js:151 (prototype-pollution-utility) | Open; direct-path regressions deployed (#451). Dismissals require authorization. |
| Regex/sanitization/identity tranches | #1/2/3 (polynomial-redos), #5 (incomplete-sanitization), #4 (identity-replacement) | Held in the agreed sequence. |
No dismissals were performed. Every closed state above was read from the alerts API; nothing was inferred from green CI.
CodeQL disposition execution — 15 authorized dismissals + 2 read-only dispositions (2026-11-21)Inventory reconciliation (resolved first, as directed)The API open inventory was 23 alerts, not 22 — my "22" in the previous matrix was a counting error in the report, not a missing or extra alert. Group arithmetic 13 API + #9 + #10 + #13 + #36/#37 + #1–#5 = 23 matches the API exactly. No alert was resolved, absent, or double-counted. 15 individually verified dismissals executed (all pre-checked open + exact location match before each PATCH)13 API-route (reason: false positive — rate limiting enforced by upstream application middleware):
Every dismissal comment carries: app-level limiter mount (app.js:84) preceding the router mount, skip-list scope (/health exact, /webhooks prefix only), deployed rotation-proof identity (89d5e51, #464), the 38-test pin, production proof date, and the documented Redis-failure fail-open residual (per the directive that it remain visible in the security record). 2 prototype-pollution-utility (reason: false positive — flagged assignments unreachable for dangerous keys):
Post-execution inventory (API-verified)
#9 — read-only disposition (authorized; NOT dismissed, per directive)
#13 — corrected classification (read-only; NOT dismissed, per directive)
No-action confirmations
|
CodeQL #9/#13 dismissal record + #1–#5 read-only verification (no source changes)#9/#13 dismissal record (authorized 2026-11-21)| Alert | Pre-check (rule|state|location) | Dismissed at | Reason | Inventory after (API-verified): open = 6 (#1–#5, #10), dismissed = 18. Matches the directive's expected table exactly. #1–#5 read-only verification — order #1→#2→#3→#5→#4Shared input path for #1–#3 (polynomial-redos,
|
CodeQL #10 — bounded residual-risk assessment of the
|
| Control | Verification |
|---|---|
| 25 MiB streaming body cap | Deployed via #457; actual-byte counting, declared-length early-out, drain-without-buffering on rejection; 14-test suite including late-stream-error and listener-preservation regressions |
| Early header rejection | Live-probed: POST without the GitHub header set → 400 {"error":"Missing required webhook headers"} in 0.28 s — the cheapest rejection path fires before any HMAC work |
| HMAC signature gate | Live-probed: complete header set + bogus signature → 401 in 0.27 s; route order confirmed in source (webhooks.js:38 header check → :52 verifyAndReceive → 401) — no DB, Redis, or GitHub-API work occurs before HMAC passes |
| Ingress topology | gitwire-app publishes no host ports (PortBindings {}) — the only ingress is the cloudflared tunnel (plus the LAN); Cloudflare edge confirmed in path (CF-RAY, Server: cloudflare) |
| Limiter exemption | By design (rateLimiter skips /webhooks) — GitHub HMAC-authenticated deliveries; this exemption is the alert's subject |
2. Request and connection timeouts (verified, not assumed)
Production runs Node 20.20.2; index.js performs a plain app.listen with no timeout overrides, so the platform defaults bind: headersTimeout 60 s (slowloris bounded), requestTimeout 300 s (a slow-drip body is killed at 5 minutes — the maximum socket-hold per request), keepAliveTimeout 5 s. These are Node's documented defaults for the verified version, not app-level configuration.
3. Concurrent-request exposure
Single Node process (Express + all 14 workers). No container resource limits (Memory=0, NanoCpus=0, no PidsLimit); fd ceiling 1024 — concurrent sockets are bounded by file descriptors, not configuration. No per-source concurrency limit at the application layer. Bandwidth for all external traffic transits the single cloudflared container.
4. Resource cost of accepted bodies approaching 25 MiB
- Rejected (over-cap): memory bounded — the body is drained without buffering; cost is byte transit + counting.
- Complete bodies: an HMAC sha256 over ≤25 MiB (tens of ms CPU), and a ≤25 MiB buffer exists only for bodies that streamed to completion. A 25 MiB buffered body requires completing the stream — any attacker can do that, but it then hits the 401 (bogus signature) and the buffer is released; genuine 25 MiB accepted payloads require the webhook secret, whose holder is trusted. Real GitHub payloads are KB-scale.
- Downstream isolation: PostgreSQL (pool max 20), Redis, and the GitHub API are untouched until HMAC passes — verified by route order and the live 401.
5. GitHub delivery reliability requirements (external documentation, not host-verified)
GitHub retries failed and timed-out deliveries automatically, and manual redelivery exists. Consequence for any control: a rate limiter placed in front of /webhooks returns 429s to legitimate deliveries under burst (e.g., an event storm from a mass-PR wave), interacting with retry/backoff and potentially delaying or dropping real events. The exact retry policy should be cited from GitHub's docs at decision time; nothing in this assessment depends on its precise parameters.
6. Can repeated unauthenticated requests still consume material resources despite the cap?
Yes — bounded per request, unbounded in aggregate. Per request: ≤25 MiB transit + counting + (on completion) one HMAC pass; no memory accumulation, no downstream work. Aggregate: nothing at the application layer bounds the rate or concurrency of such requests; a flood consumes tunnel bandwidth and CPU and can occupy up to ~1024 concurrent sockets. Cloudflare edge protections (WAF/rate rules/bot mitigation) sit in front but are not verifiable from the host — these are operator-dashboard verification items:
- zone WAF managed rules / custom rules for
gitwire.erlab.uk - zone rate-limiting rules
- bot fight mode / TLS minimums
7. Recommendation (for the maintainer's decision)
Retain the exception with formally accepted residual risk. Rationale: the residual is bandwidth/CPU-only — bounded memory, zero pre-HMAC downstream work, no state corruption, self-recovering; the deployment is single-operator behind a Cloudflare edge; and the main alternative (a rate limiter on /webhooks) has a demonstrated interaction with legitimate-delivery retries.
If a control is nonetheless wanted, the narrowly scoped option that does not touch delivery rates: an in-flight streaming concurrency cap on /webhooks only (reject with 503 when more than N webhook bodies are streaming concurrently, N ≈ 8–16). It bounds aggregate flood cost while leaving sequential delivery bursts and retries unaffected. This is a design sketch, not an authorized implementation.
No dismissal action is taken on #10 either way — it remains open pending the maintainer's explicit decision between formal risk acceptance (with this assessment as the record) and the compensating-control unit.
CodeQL #10 — CORRECTION to the residual-risk assessment (supersedes §4 and §6 of comment 7053523524; recommendation revised)My earlier assessment contained a material error, and the maintainer's correction is confirmed against the deployed source. I claimed memory "does not accumulate before a request completes" and that the residual was "bandwidth/CPU-only." That is wrong for the accepted-body path. What the deployed implementation actually does (verified at master
|
| Factor | Value |
|---|---|
| Host memory (CT 115) | 16 GiB total, ~15 GiB available (containers idle at ~650 MiB combined) |
| Container memory limit | none (Memory=0) — exhaustion lands on the kernel OOM killer, which can take any service, not just the app |
| Per-connection retention | up to 25 MiB (chunk array) + transient ~2× at Buffer.concat |
| Concurrency ceiling | fd limit 1024 (≈ upper bound on concurrent bodies; each request also occupies a tunnel socket) |
| Per-request maximum hold | 300 s (requestTimeout, Node default — verified no override) |
An unauthenticated flood holding ~600 concurrent near-cap bodies approaches the 16 GiB host budget; a sustained drip-pace flood (each body transmitted slowly within the 300 s window) maintains that working set indefinitely. The fd ceiling bounds this below the naive ∞ but is not a memory-exhaustion control at these sizes — agreeing with the maintainer's analysis. This is a genuine memory-exhaustion vector, not bandwidth/CPU-only.
What stands unchanged from the verified-controls table
Node 20.20.2 with default timeouts; no published ports (tunnel-only ingress); Cloudflare edge in path (CF-RAY); 400/401 live probes; DB/Redis/GitHub-API untouched before HMAC; GitHub retry interaction argument. Cloudflare zone-side protections remain unverified from the host — if the zone has effective rate/concurrency controls, the flood math above changes materially; that verification is an operator-dashboard action.
Revised recommendation (for the maintainer's decision)
Formal risk acceptance is not supported by the current record — the previous recommendation is withdrawn. The options that survive the corrected math:
- Narrow compensating control (now materially justified): in-flight webhook-body concurrency cap — reject with 503 when more than N webhook bodies are concurrently streaming/buffered. Sized by budget: N=16 bounds worst-case webhook buffering to ~400 MiB (+ concat transients) on the 16 GiB host; N=64 to ~1.6 GiB. Sequential legitimate deliveries (GitHub's burst/retry pattern is sequential per hook) are unaffected at any of these N. Threshold + GitHub behavior verification = separate implementation decision, per the directive.
- Alternative/complementary: reduce the per-connection cap. Real GitHub webhook payloads are KB-scale; 25 MiB was already generous. A 4 MiB cap cuts the worst-case aggregate 6×. Changes the deployed fix(10): streaming 25MiB webhook body cap — explicit disposition, swallowed late errors, no blanket listener removal #457 contract — separate decision.
- Retain-with-acceptance only after (a) Cloudflare zone-side protections are verified effective by the operator, or (b) the maintainer explicitly accepts memory-exhaustion DoS as within the threat model for this single-operator deployment.
No dismissal or configuration change made; #10 remains open.
Summary
v9 of the limiter identity remediation chain: #460 → #462 → #463 → here. One surgical correction over #463 (v8); everything else carried unchanged. Supersedes #463.
What this round fixes
The #463 review's finding 2 pointed at
auth.js's comment "Extract key from header or query param" — no query-parameter authentication path exists (zeroreq.queryreads in auth.js; the header is the only in-band key channel). The stale line predates this chain (introduced at 39826c9) but was preserved by the v8 refactor, so it is corrected here rather than left to mislead the next reader into designing a limiter identity for a channel that does not exist.That is the only change in this PR.
The chain this PR carries (from #460/#462/#463, all held and superseded)
/api/auth/*and/api/bootstrap/*always key the limiter on the request IP (8 path-form regressions: case, trailing slash).extractBearerToken()(bearerToken.js) called by bothapiKeyAuthandderiveLimiterIdentity; 12-case corpus contract test pins the one recognition rule both depend on.Adjudication of the #463 review (5 findings)
parsed.error.issues,.refine(fn, "msg"),z.coerce); covered by green suites (config-validator, ci-heal-job-service, issue-fix-analysis-safety). Bundling is deliberate: the master-push CI failed on all 7 advisories at once (fix(10): streaming 25MiB webhook body cap — explicit disposition, swallowed late errors, no blanket listener removal #457 deploy skip); this chain clears the deploy blocker in one unit.extractBearerToken()performs no secret comparison (prefix slice + trim only). The one comparison,keys.has(providedKey)in auth.js, is unchanged by this refactor and pre-dates the chain. (Practical note: API keys are high-entropy random values; Set-membership timing does not practically leak them.)Verification
mergeStateStatus: CLEANat e4b17b7