Public: anyone can read this; the crew can change it.
Auth scheme `bearer` in any letter case resolves the caller, and the 401 challenge tells the truth #14998
Check · Review · Land · Live done — Landed and live in production.
A token sent as bearer (lowercase, or any other letter case) now signs the caller in, the same as Bearer . The 401 challenge now says error="invalidtoken" only when a bearer was actually checked and refused. The finding.
shipped production is serving it deploy 6dfa34b
A token sent as bearer <secret> (lowercase, or any other letter case) now signs the caller in, the same as Bearer <secret>. The 401 challenge now says error="invalid_token" only when a bearer was actually checked and refused.
The finding. src/http/token_header.ts only recognised the exact spelling Bearer , so bearer x was treated as no credentials at all. But the challenge in src/http/oauth.ts (bearerChallenge) detected a bearer ignoring case (/^Bearer\s+\S/i). So a valid lowercase token got a 401 saying the token was invalid, even though it was never checked. The same was true of headers like Bearer<TAB>x.
The fix.
token_header.tsnow matchesBearerandtokenin any letter case, as the HTTP spec says schemes should be (RFC 9110 §11.1).- It adds
bearerSecret(), which reads only theBearerscheme. bearerChallengenow usesbearerSecret(), so the challenge and the sign-in check read the header the same way.
The other callers of tokenSecret / isTokenScheme in server.ts, api/timers.ts, api/print.ts and spawn/vouch.ts give the same answers for every header they accepted before. They now also accept other letter cases of the scheme.
The finding sits in token_header.ts and oauth.ts. src/http/caller.ts, which the issue lists, contains no header parsing, so it is unchanged.
Not done here. The app-host proxy in src/apps/proxy.ts (bearerAdmission, navigating) still checks for startsWith("Bearer ") exactly. It is a separate boundary with its own rules; changing it is a follow-up, not part of this finding.
Tests. test/bearer-scheme-case.test.ts checks the parser and the challenge directly, and runs a real server. It shows:
bearer,BEARERandBearerall get 200 on/api/v1/useras the same account;- a refused lowercase bearer gets 401 with
invalid_token; Bearer<TAB>xandBearerget noinvalid_token.
On main the test fails. bun scripts/fast.ts named 2,267 test files for this change, too broad to run, so I ran these 19 instead: the new test plus every test file that mentions the challenge, invalid_token, www-authenticate or the token header. All 254 tests pass, and the gate and tsc --noEmit are clean.
For the finding in #14778, which is sealed so I could not read its exact wording:
To try it: make a token at /settings/tokens, then:
curl -H 'authorization: bearer <token>' <preview>/api/v1/useranswers with your account;curl -i -H 'authorization: bearer wrong' <preview>/api/v1/useranswers 401 withwww-authenticate: … error="invalid_token".
🤖 Generated with Claude Code
Clean, small, and correct. Scheme matching is case-insensitive per RFC 9110, the secret is still trimmed and required, and bearerChallenge now reads the header through the same bearerSecret parser as caller resolution, so invalid_token is only claimed for a bearer that was tried. No new dependency, no new input surface, tests cover parser, challenge and a real server. The app-host proxy still matching exact Bearer is disclosed as a follow-up; worth an issue.
A token sent as
bearer <secret>(lowercase, or any other letter case) now signs the caller in, the same asBearer <secret>. The 401 challenge now sayserror="invalid_token"only when a bearer was actually checked and refused.The finding.
src/http/token_header.tsonly recognised the exact spellingBearer, sobearer xwas treated as no credentials at all. But the challenge insrc/http/oauth.ts(bearerChallenge) detected a bearer ignoring case (/^Bearer\s+\S/i). So a valid lowercase token got a 401 saying the token was invalid, even though it was never checked. The same was true of headers likeBearer<TAB>x.The fix.
token_header.tsnow matchesBearerandtokenin any letter case, as the HTTP spec says schemes should be (RFC 9110 §11.1).bearerSecret(), which reads only theBearerscheme.bearerChallengenow usesbearerSecret(), so the challenge and the sign-in check read the header the same way.The other callers of
tokenSecret/isTokenSchemeinserver.ts,api/timers.ts,api/print.tsandspawn/vouch.tsgive the same answers for every header they accepted before. They now also accept other letter cases of the scheme.The finding sits in
token_header.tsandoauth.ts.src/http/caller.ts, which the issue lists, contains no header parsing, so it is unchanged.Not done here. The app-host proxy in
src/apps/proxy.ts(bearerAdmission,navigating) still checks forstartsWith("Bearer ")exactly. It is a separate boundary with its own rules; changing it is a follow-up, not part of this finding.Tests.
test/bearer-scheme-case.test.tschecks the parser and the challenge directly, and runs a real server. It shows:bearer,BEARERandBearerall get 200 on/api/v1/useras the same account;invalid_token;Bearer<TAB>xandBearerget noinvalid_token.On main the test fails.
bun scripts/fast.tsnamed 2,267 test files for this change, too broad to run, so I ran these 19 instead: the new test plus every test file that mentions the challenge,invalid_token,www-authenticateor the token header. All 254 tests pass, and the gate andtsc --noEmitare clean.For the finding in #14778, which is sealed so I could not read its exact wording:
To try it: make a token at
/settings/tokens, then:curl -H 'authorization: bearer <token>' <preview>/api/v1/useranswers with your account;curl -i -H 'authorization: bearer wrong' <preview>/api/v1/useranswers 401 withwww-authenticate: … error="invalid_token".🤖 Generated with Claude Code
Closes #14988