Skip to content

fix: case-insensitive Bearer scheme check in resolvePublicAuthContext #53

Description

@coderabbitai

Summary

In apps/public-api/src/middlewares/resolvePublicAuthContext.js (Line 12), the Authorization header check uses authHeader.startsWith('Bearer '), which is case-sensitive and will silently ignore valid tokens sent with bearer <token> or BEARER <token>.

Per RFC 7235 §2.1, the auth-scheme token is case-insensitive.

Suggested Fix

- if (!authHeader || !authHeader.startsWith('Bearer ')) {
+ if (!authHeader || !/^bearer\s/i.test(authHeader)) {

And extract the token accordingly:

- const token = authHeader.split(' ')[1];
+ const token = authHeader.replace(/^bearer\s+/i, '');

Context

Identified during review of PR #51 (#51 (comment)) as a minor issue deferred for a follow-up.

Requested by @yash-pouranik.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions