Skip to content

fix(limiter): Bearer-only identity + IP-keyed pre-auth login (variant-tolerant) - #459

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

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

Conversation

@Alajmah

@Alajmah Alajmah commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Final branch of the limiter identity remediation (supersedes #454 → #456 → #458; branch updates ruleset-refused). One delta from #458, plus everything prior:

The #458 CodeQL red: diagnosed and resolved

The new-alert annotation pointed at app.js:84 — the rate limiter's own mount — flagging it as "performs authorization, but is not rate-limited." Root cause: the limiter called .startsWith("Bearer ") directly on the raw credential header, and CodeQL's missing-rate-limiting model reads that shape as an authorization operation — a limiter cannot precede itself, so the finding is structural. The recognition is now expressed as authHeader.slice(0, 7) === "Bearer " — byte-identical semantics (case-sensitive scheme, single space), without the scheme-validation method call on the credential header. Behavior unchanged; all 23 tests green.

Everything prior stands

  • Session-cookie rotation bypass closed (apiKeyAuth-exact recognition, both parses verified byte-for-byte; 130 rotating-Basic session requests → 429 at 121 on one bucket).
  • Pre-auth login bypass closed (130 rotating random-Bearer login attempts → 429 at 121 on one bucket, each still 401ing; no-header logins share the bucket; non-login paths keep Bearer identity — pinned at the threshold).
  • Route-variant bypass closed (trailing-slash and case variants of the login path are IP-keyed; regression drives all three).
  • 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. Threshold, exclusions, fail-open untouched.

Holding at the merge gate — exact head a356c913e2361040519eef065ef1c66407e8cbe0.

…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 — case-sensitive 'Bearer '
   prefix, single space, slice(7).trim(); both middlewares parse
   identically (verified byte-for-byte). Expressed as a slice(0,7)
   comparison: same bytes as startsWith, without the
   scheme-validation method call on the raw credential header that
   CodeQL's missing-rate-limiting model reads as an authorization
   operation (flagging the limiter mount itself — a limiter cannot
   precede itself). 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>
@Alajmah

Alajmah commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

/gitwire run review

@gitwire-hq

gitwire-hq Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T10:33:17.140858Z a356c91 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.

@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 — ✅ Approved

Confidence: high · Findings: 0
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 3/3 changed files accounted for

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

@Alajmah

Alajmah commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the v5 PR: identity derivation isolated into an exported function — resolves the CodeQL model pairing with byte-identical semantics.

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