fix(HttpApi): strip space delimiter when decoding bearer/http credentials#2306
Open
sam-goodwin wants to merge 1 commit into
Open
fix(HttpApi): strip space delimiter when decoding bearer/http credentials#2306sam-goodwin wants to merge 1 commit into
sam-goodwin wants to merge 1 commit into
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: 2c353b1 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 |
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.