Repository navigation
Conversation
…ant-tolerant)
Three-layer remediation of the rate-limit identity bypass family:
1. Session-cookie rotation bypass (CLOSED): limiter identity recognizes
EXACTLY apiKeyAuth's scheme and parse ('Bearer ' prefix,
case-sensitive single space, slice(7).trim() — both middlewares
parse identically, verified byte-for-byte). Every other
Authorization form falls back to the request IP. End-to-end:
130 rotating-Basic session requests → 429 at 121 on ONE bucket.
2. Pre-authentication login bypass (CLOSED): the limiter cannot
validate Bearer tokens (it runs before auth) and /api/auth/login
authenticates by body password — login attempts ALWAYS key on the
request IP. End-to-end: 130 login attempts with rotating random
Bearer tokens → 429 at 121 on ONE bucket (each still 401s).
3. Route-variant bypass (CLOSED): Express's default non-strict,
case-insensitive-to-route matching serves '/api/auth/login/',
'/API/AUTH/LOGIN' to the same handler — the pre-auth check is a
trailing-slash-and-case tolerant regex so no variant re-opens the
mint. Regression drives all three variants; the bucket is the IP.
Unchanged: 120/min threshold, /health + /webhooks exclusions, Redis
fail-open, TTL, valid-Bearer per-token buckets on non-login paths
(pinned). Deployment facts on record: no trust proxy (req.ip = socket
address; forwarded headers cannot mint buckets); tunnelled traffic
shares the tunnel peer's bucket (pre-existing, errs safe);
invalid-Bearer Redis-key growth = TTL-bounded documented follow-up.
Identity suite 14 tests + behavior suite 9 — all green.
Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
|
/gitwire run review |
|
|
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
🤖 AI Code Review — ✅ Approved
Confidence: high · Findings: 2
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 3/3 changed files accounted for
Other findings (2)
- [low] Hardcoded pre-auth path regex silently re-opens the bucket-mint bypass for any future public endpoint
- [low] 'Exactly apiKeyAuth recognition' parity is asserted in comments but never pinned; suite itself hedges on the scheme regex
🔮 Devil's Advocate (2 turns): 2 upheld
GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority
| // the same handler; an exact-equality list would re-open the mint on | ||
| // '/api/auth/login/'. | ||
| const isPreAuthPath = (path) => | ||
| typeof path === "string" && /^\/api\/auth\/login\/?$/i.test(path); |
There was a problem hiding this comment.
[LOW] Hardcoded pre-auth path regex silently re-opens the bucket-mint bypass for any future public endpoint
The fix correctly special-cases /api/auth/login, but the mechanism is a string allowlist in the limiter that must be kept in lockstep with auth.js's set of unguarded routes. The bypass exists on ANY endpoint where an unauthenticated caller can reach real handler work while sending an arbitrary Bearer value (register, refresh, password-reset request, logout, etc.). If a new public route is added to auth.js and someone forgets to extend this regex, per-token bucket minting silently re-opens with no failing test to catch it, because the identity suite only pins the login path. Suggested hardening: export the public/pre-auth path list (or a shared matcher) from the auth module and have both apiKeyAuth's skip logic and the limiter consume the same source of truth, plus an identity-suite test that iterates that shared list so new entries are automatically covered.
| expect([...redisState.counts.keys()].join("|")).toContain("key-two"); | ||
| // A LOWERCASE scheme is not Bearer for apiKeyAuth (starts-with "Bearer "), | ||
| // so it must not be Bearer for the limiter either — it falls to the IP. | ||
| redisState.counts.clear(); |
There was a problem hiding this comment.
[LOW] 'Exactly apiKeyAuth recognition' parity is asserted in comments but never pinned; suite itself hedges on the scheme regex
The whole security argument rests on the limiter's startsWith("Bearer ") matching apiKeyAuth's scheme recognition exactly, yet no test drives a token through the REAL apiKeyAuth to confirm agreement on the malformed variants. Worse, the identity suite's own it.each comment is self-contradictory: "Bearer\tgap-token" // malformed: tab not matched by \\s+? (regex ^Bearer\\s+ — tab IS \\s; assert below) — acknowledging that IF auth.js uses /^Bearer\s+/, tab-separated headers WOULD authenticate while the limiter IP-keys them, making the 'exactly apiKeyAuth' invariant comment in rateLimiter.js false. The failure direction is safe (under-keying to the shared IP bucket, no bypass), which is why this is not a bug, but the invariant is load-bearing and should be pinned: add one end-to-end case per malformed variant (lowercase scheme, tab separator, empty token) through the real apiKeyAuth asserting both the auth outcome and the limiter bucket key agree.
|
Superseded by the v4 PR: the CodeQL new-alert on the limiter mount was traced to the startsWith-on-credential-header shape; recognition now expressed as a byte-identical slice comparison. |
Final branch of the limiter identity remediation (supersedes #454 → #456; branch updates ruleset-refused). Adds the review-round corrections on top of everything prior:
The two review HIGHs, one fixed and one refuted with proof
/api/auth/login/and/API/AUTH/LOGINto the same login handler — an exact-equality path list would re-open the Bearer-mint on the slashed variant. The pre-auth check is now a trailing-slash-and-case tolerant regex; the regression drives all three variants and asserts the bucket is the IP, never the token..trim()parity (refuted with the source):apiKeyAuthitself parsesslice(7).trim()— the two middlewares' parses are byte-for-byte identical. A whitespace-variant token parses to the SAME identity in both, so no divergence and no rotation vector exists. (The test-title contradiction the review also flagged is fixed.)Everything from #456 stands
req.ip= socket address — forwarded headers cannot mint buckets); tunnelled traffic shares the tunnel peer's bucket (pre-existing, errs safe); invalid-Bearer Redis-key growth = TTL-bounded documented follow-up. Threshold, exclusions, and fail-open untouched.Identity suite 14 + behavior suite 9 — all green locally. Holding at the merge gate — exact head
21c8073a973f19e6a66ceea31ed2640374b2a7ff.