Repository navigation
Conversation
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>
|
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. |
|
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 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 |
Problem
Both auth providers require the authorization header to start with the literal
Bearer, so clients that sendbearer/BEARER(permitted: HTTP auth scheme names are case-insensitive, RFC 7235) or add surrounding whitespace are rejected withcredential not recognized/invalid or missing tokeneven with a valid token. Fixes #21.Root cause
StaticProviderstored"Bearer " + tokenand compared the whole header withsubtle.ConstantTimeCompare;JWKSProviderusedstrings.CutPrefix(header, "Bearer "). Both hard-code the scheme as a case-sensitive literal and never split scheme from credential.Fix
Added a shared
bearerCredentialhelper that trims the header withstrings.Fields, checks the scheme withstrings.EqualFold, and returns just the credential.StaticProvidernow stores the bare token and constant-time-compares it against the parsed credential (still no early break — timing independent of which key matches);JWKSProvideruses the same helper. Different schemes such asBasicare still rejected.Testing
TestBearerSchemeCaseInsensitive:Bearer,bearer,BEARER, and a whitespace-padded header all authenticate;Basicis 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;gofmtapplied.TestInterceptor,TestWriteGrant,TestInterceptorJWTstill pass. Token comparison remains constant-time.