fix: case-insensitive ****** check in resolvePublicAuthContext - #55
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Agent-Logs-Url: https://github.com/yash-pouranik/urBackend/sessions/6390da0d-ed06-4b3a-ac6b-b0f5478315b9 Co-authored-by: yash-pouranik <172860064+yash-pouranik@users.noreply.github.com>
|
@coderabbitai checkout the PR, i think i should merge? here the issue #53 |
There was a problem hiding this comment.
Pull request overview
Updates the public API auth middleware to accept case-insensitive Authorization: Bearer <token> schemes per RFC 7235, ensuring valid tokens aren’t ignored when clients vary scheme casing.
Changes:
- Replaced
startsWith('Bearer ')with a case-insensitive/^bearer\s+/icheck. - Updated token extraction to remove the scheme via regex.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!authHeader || !/^bearer\s+/i.test(authHeader)) { | ||
| return next(); | ||
| } | ||
|
|
||
| const token = authHeader.slice(7).trim(); | ||
| const token = authHeader.replace(/^bearer\s+/i, ''); |
There was a problem hiding this comment.
The same /^bearer\s+/i literal is duplicated in both the presence check and extraction. Defining it once (e.g., const bearerPrefix = /^bearer\s+/i) reduces the chance of these drifting apart in future edits.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5184
✅ Summary: Safe to MergeWhat the PR doesThe PR replaces the case-sensitive Code ReviewThe diff is small and correct: // Presence check — now case-insensitive ✅
- if (!authHeader || !authHeader.startsWith('Bearer ')) {
+ if (!authHeader || !/^bearer\s+/i.test(authHeader)) {
// Token extraction — handles any casing and multiple spaces ✅
- const token = authHeader.slice(7).trim();
+ const token = authHeader.replace(/^bearer\s+/i, '');Notable improvement over issue Status Checklist
|
|
ok thankyou @coderabbitai, can u please create an issue to add unit tests? for auth only? auth for urabackend basically under ./apps/dashboard-api |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 718 🏁 Script executed: Length of output: 786 🏁 Script executed: Length of output: 52
Here's a quick summary of what it covers:
One thing worth noting: |
…outes - fix(dashboard-api): create `publicLimiter` for non-sensitive data queries - fix(dashboard-api): apply `publicLimiter` to `GET /api/waitlist/count` endpoint - fix(dashboard-api): apply strict `authLimiter` to `GET /api/waitlist/admin` endpoint - chore: address CodeQL alerts #55, #56, #57 regarding missing rate limiting
Per RFC 7235 §2.1, the auth-scheme token is case-insensitive, but the existing
startsWith('Bearer ')check silently drops valid tokens sent asbearer <token>orBEARER <token>.Changes
resolvePublicAuthContext.js— replacestartsWith('Bearer ')with/^bearer\s+/iregex for both the presence check and token extraction:The
\s+(vs.\s) is used consistently in both the check and extraction to correctly handle any amount of whitespace between the scheme and token.⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.