Skip to content

fix: case-insensitive Bearer token scheme matching#2387

Merged
cstockton merged 2 commits intomasterfrom
or/bearer_ci
Feb 23, 2026
Merged

fix: case-insensitive Bearer token scheme matching#2387
cstockton merged 2 commits intomasterfrom
or/bearer_ci

Conversation

@olirice
Copy link
Contributor

@olirice olirice commented Feb 23, 2026

fix: case-insensitive Bearer token scheme matching

bearerRegexp only accepted Bearer and bearer
RFC 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

  • Added TestExtractBearerTokenCaseInsensitive covering Bearer, bearer, BEARER, bEaReR, BeArEr

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Bearer token authentication now properly handles case-insensitive headers (Bearer, bearer, BEARER, etc.) in compliance with RFC 7235.
  • Tests

    • Added test coverage for case-insensitive Authorization header parsing.

Walkthrough

The 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 (B|b)earer to a unified case-insensitive pattern (?i)^bearer, which achieves the same functionality with cleaner syntax. A new test TestExtractBearerTokenCaseInsensitive was introduced to validate that the Authorization header parsing handles bearer scheme names in any case variation (Bearer, bearer, BEARER, etc.) according to RFC 7235 §2.1, using multiple header examples and verifying correct token extraction.


Comment @coderabbitai help to get the list of available commands and usage tips.

@cstockton cstockton changed the title Or/bearer ci fix: case-insensitive Bearer token scheme matching Feb 23, 2026
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.
@cstockton cstockton marked this pull request as ready for review February 23, 2026 16:45
@cstockton cstockton requested a review from a team as a code owner February 23, 2026 16:45
@cstockton
Copy link
Contributor

Looks good 👍 - my force push was rebase reword on commit prefix

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 53021f6 and 7fbce5e.

📒 Files selected for processing (2)
  • internal/api/api.go
  • internal/api/auth_test.go

@cstockton cstockton merged commit 36d712d into master Feb 23, 2026
9 checks passed
@cstockton cstockton deleted the or/bearer_ci branch February 23, 2026 22:17
cstockton pushed a commit that referenced this pull request Feb 24, 2026
🤖 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>
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.

2 participants