Skip to content

fix(authn): match the Bearer scheme case-insensitively - #27

Closed
bfs2021 wants to merge 1 commit into
priompt:mainfrom
bfs2021:fix/bearer-scheme-case-insensitive
Closed

bfs2021 wants to merge 1 commit into
priompt:mainfrom
bfs2021:fix/bearer-scheme-case-insensitive

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

Both auth providers require the authorization header to start with the literal Bearer , so clients that send bearer/BEARER (permitted: HTTP auth scheme names are case-insensitive, RFC 7235) or add surrounding whitespace are rejected with credential not recognized / invalid or missing token even with a valid token. Fixes #21.

Root cause

StaticProvider stored "Bearer " + token and compared the whole header with subtle.ConstantTimeCompare; JWKSProvider used strings.CutPrefix(header, "Bearer "). Both hard-code the scheme as a case-sensitive literal and never split scheme from credential.

Fix

Added a shared bearerCredential helper that trims the header with strings.Fields, checks the scheme with strings.EqualFold, and returns just the credential. StaticProvider now stores the bare token and constant-time-compares it against the parsed credential (still no early break — timing independent of which key matches); JWKSProvider uses the same helper. Different schemes such as Basic are still rejected.

Testing

  • Added TestBearerSchemeCaseInsensitive: Bearer, bearer, BEARER, and a whitespace-padded header all authenticate; Basic is still rejected. Confirmed it fails against the unfixed code (3 cases) and passes after the fix.
  • go test ./... — all packages pass (authn, cmd/priompt-auth); go vet ./... clean; gofmt applied.
  • Existing TestInterceptor, TestWriteGrant, TestInterceptorJWT still pass. Token comparison remains constant-time.

HTTP auth scheme names are case-insensitive, but both providers required
the literal "Bearer " prefix: StaticProvider compared the whole header
against a stored "Bearer "+token string, and JWKSProvider used
strings.CutPrefix with the same literal. Clients that lowercase the scheme
or add surrounding whitespace were rejected with 'credential not recognized'
even with a valid token.

Parse the header once with a shared helper that trims whitespace and compares
the scheme with strings.EqualFold, then compare only the credential. The
static-token comparison stays constant time across all configured keys.
Fixes priompt#21.

Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @bfs2021! Before a maintainer reviews it, please check the contribution process:

Pull requests that do not follow the process may be closed.

@sujal-maheshwari2004

Copy link
Copy Markdown
Member

Hi @bfs2021, thanks for the work on this. We're closing this PR, and here is why.

Your account opened about 100 PRs across GitHub in the past week. Three of your four PRs to Priompt were closed (ui#42, proto#16, python-sdk#28), and this one was opened before the issue was claimed or assigned. The assignment on #21 was given in good faith, but good first issues are reserved for newcomers (CONTRIBUTING §2), and this pattern looks like the bulk submission that §4 says will be closed. The PR also doesn't say whether AI tools were used, which §4 requires.

This is about the process and not the quality of the fix, which passes tests. We'll reassign #21 to a newcomer. If you'd like to contribute again, please pick a help wanted issue, claim it and wait for assignment, keep to the 2-open-PR limit, and disclose any AI use. Thank you.

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.

The Bearer scheme is matched case-sensitively

2 participants