fix: case-insensitive Bearer token scheme matching#2387
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe pull request refactors the bearer token extraction regex in the API authentication handler and adds a corresponding test. The regex pattern was simplified from an explicit case enumeration Comment |
RFC 7235 §2.1 requires HTTP auth scheme names to be case-insensitive. The current regex only accepts "Bearer" and "bearer", rejecting spec-compliant variants like "BEARER".
Change bearerRegexp to use (?i) flag so all capitalizations of "bearer" are accepted, as required by the HTTP authentication framework spec.
e1f399f to
7fbce5e
Compare
|
Looks good 👍 - my force push was rebase reword on commit prefix |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/api/auth_test.go`:
- Around line 62-84: The test TestExtractBearerTokenCaseInsensitive uses a
JWT-like hardcoded string in the variable token which is flagged as a potential
secret; update the token used in that test (and any other tests using similar
values) to a clearly fake value (e.g., "fake-token-value" or "token1234") that
contains no dot-separated JWT pattern but still has no spaces, or replace it
with a shared constant like testFakeToken and use that in the call to
a.extractBearerToken(req) to avoid gitleaks false positives while preserving
test semantics.
ℹ️ Review info
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
internal/api/api.gointernal/api/auth_test.go
🤖 I have created a release *beep* *boop* --- ## [2.187.0](v2.186.0...v2.187.0) (2026-02-23) ### Features * add metadata field to all hooks ([#2365](#2365)) ([c675749](c675749)) * check current password on change ([#2364](#2364)) ([33b87ae](33b87ae)) * **indexworker:** add max users threshold for rollout ([#2374](#2374)) ([a2066c6](a2066c6)) * **metrics:** added a gauge with version information ([#2375](#2375)) ([911ad0b](911ad0b)) * support custom oauth & oidc providers ([#2357](#2357)) ([53021f6](53021f6)) ### Bug Fixes * case-insensitive Bearer token scheme matching ([#2387](#2387)) ([36d712d](36d712d)) * correctly parse JWT ValidMethods from env by enabling split_words ([#2334](#2334)) ([a6076bc](a6076bc)) * flaky index worker test ([#2366](#2366)) ([961a7e6](961a7e6)) * **hooks:** propagate error objects from hook calls ([#2380](#2380)) ([3ca1e88](3ca1e88)) * session upgrade percentage should be based on session, not request ([#2371](#2371)) ([510e68b](510e68b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
fix: case-insensitive Bearer token scheme matching
bearerRegexponly acceptedBearerandbearerRFC 7235 §2.1 requires auth scheme names to be case-insensitive.
Changed the regex to use the
(?i)flag so all capitalizations (e.g.BEARER) are accepted.Test plan
TestExtractBearerTokenCaseInsensitivecoveringBearer,bearer,BEARER,bEaReR,BeArEr