Repository navigation
fix(auth): remove stale query-param comment — limiter identity chain v9 #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // src/middleware/bearerToken.js | ||
| // Bearer-token extraction shared by apiKeyAuth (auth.js) and the rate limiter | ||
| // (rateLimiter.js). Both MUST recognize exactly the same Authorization forms: | ||
| // a case-sensitive "Bearer " scheme prefix with a single literal space. A | ||
| // looser recognizer on the limiter side re-opens the bucket-rotation bypass | ||
| // (rotating non-Bearer headers to mint fresh buckets); a stricter one would | ||
| // throttle callers apiKeyAuth accepts. Before this module existed the two | ||
| // implementations were unlinked copies kept in sync by comments — the corpus | ||
| // contract test in rate-limiter-identity.test.js now pins this one function | ||
| // for both callers. | ||
|
|
||
| /** | ||
| * Extract the Bearer token from an Authorization header value. | ||
| * | ||
| * Recognition is apiKeyAuth-EXACT: case-sensitive "Bearer " prefix (single | ||
| * literal space), then slice(7).trim(). Returns "" for every other form — | ||
| * wrong case ("bearer x"), tab separator ("Bearer\tx"), bare "Bearer", | ||
| * whitespace-only token, or a missing/non-string header. | ||
| * | ||
| * @param {string | undefined} authHeader | ||
| * @returns {string} the token, or "" when the header is not a well-formed | ||
| * Bearer credential. | ||
| */ | ||
| export function extractBearerToken(authHeader) { | ||
| return typeof authHeader === "string" && authHeader.slice(0, 7) === "Bearer " | ||
| ? authHeader.slice(7).trim() | ||
| : ""; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.