fix(HttpApi): strip space delimiter when decoding bearer/http credentials#2306
Merged
tim-smart merged 2 commits intoJun 1, 2026
Merged
Conversation
…ials `securityDecode` sliced `schemeLength` off the `Authorization` header, but the header is `"<scheme> <credential>"`, so the single space separating the scheme from the credential was left attached (e.g. `Bearer abc123` decoded to `" abc123"`). Slice `schemeLength + 1` to skip the delimiter. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 4963a1f The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
IMax153
previously approved these changes
Jun 1, 2026
Member
|
@sam-goodwin - looks like there's a type error in CI. |
IMax153
reviewed
Jun 1, 2026
| Effect.provideService(HttpServerRequest.ParsedSearchParams, {}) | ||
| ) | ||
|
|
||
| describe("HttpApiSecurity", () => { |
Member
There was a problem hiding this comment.
We should also have a test that validates that credentials from a different scheme than the one specified are rejected.
See the tests in Julius' PR #2315
Contributor
Bundle Size Analysis
|
Contributor
Author
|
Thanks @tim-smart for driving it home. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2305
securityDecodeslicesschemeLengthoff theAuthorizationheader, but the header is"<scheme> <credential>"— so the single space separating the scheme from the credential stays attached to the decoded value. Everybearer/httpcredential decodes with a leading space (basicis unaffected — it still uses thebasicLen = "Basic ".lengthconstant).Regression
Introduced in 361ca30 (#2291, "Add HttpApiSecurity.http for passing custom schemes"), first released in
effect@4.0.0-beta.73. That change replaced the hard-codedconst bearerLen = `Bearer `.length(7, which included the delimiter space) withschemeLength: options.scheme.length(6) andslice(self.schemeLength), dropping the+ 1. Bisection:beta.72good,beta.73bad.Impact
Any HTTP API guarded by
HttpApiSecurity.bearer(or a customHttpApiSecurity.http({ scheme })) rejects valid credentials, because the server-side decoded token is one byte longer than what the client sent.Test
Added
HttpApiSecurity.test.tsexercisingsecurityDecodefor bothbearerand a customhttpscheme. Verified it fails onmain(Received: " abc123") and passes with the fix.