Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 2909af6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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 |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-biometrics
@clerk/expo-google-signin
@clerk/expo-native-components
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/mosaic
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
6f43dec to
ee29bd5
Compare
| throw tokenExchangeRequestError( | ||
| 'Each `scope` element must be a non-empty scope token without spaces, `"`, `\\`, or non-ASCII characters.', | ||
| ); | ||
| for (const token of scope ?? []) { |
There was a problem hiding this comment.
for...of accepts any iterable, so a JavaScript caller passing scope: new Set(['read']) now passes this check. tokenExchangeBody then sees scope.length === undefined and omits scope entirely, so the exchange is sent asking for the authorization server's default scopes instead of read. Before this change, scope?.some(...) threw a TypeError for a Set, so the silent drop is new.
A plain string has a related problem: scope: 'read' passes here because each character is a valid token, and then fails in tokenExchangeBody with TypeError: params.scope.join is not a function rather than invalid_request. That mistake seems plausible because CreateOAuthApplicationParams.scopes in this file is a space-separated string.
Since this check exists to reject runtime values the types don't cover, please reject anything that isn't an array (Array.isArray(scope)) before the loop, and add a Set and a string case to the rejection tests.
~ 🤖
There was a problem hiding this comment.
Fixed in ee3bc70. assertValidTokenExchangeScope now returns early only for a missing scope and throws invalid_request for anything where Array.isArray(scope) is false, before it checks the elements (
javascript/packages/backend/src/api/endpoints/OAuthApplicationsApi.ts
Lines 165 to 170 in 2909af6
Set or a plain string now fails with an OAuthTokenExchangeError instead of being dropped or reaching join. This keeps the request's scope as the space-delimited token list from RFC 6749 §3.3. I added both cases to the rejection table (javascript/packages/backend/src/api/__tests__/OAuthApplicationsApi.test.ts
Lines 601 to 602 in 2909af6
|
|
||
| const rfc3986AbsoluteUriPattern = | ||
| /^[A-Za-z][A-Za-z0-9+.-]*:\/\/(?:[A-Za-z0-9\-._~:/?@!$&'()*+,;=[\]]|%[0-9A-Fa-f]{2})*$/; | ||
| /^[A-Za-z][A-Za-z0-9+.-]*:\/\/(?:(?:[A-Za-z0-9\-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})*@)?(?:\[[0-9A-Fa-f:.]+\]|(?:[A-Za-z0-9\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)(?::[0-9]*)?(?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/]|%[0-9A-Fa-f]{2})*)?(?:\?(?:[A-Za-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*)?$/; |
There was a problem hiding this comment.
Optional hardening: the plain-http exception is decided on the WHATWG-normalized hostname, but resource is sent as written. The reg-name branch here accepts digits and percent-encoding, so http://2130706433/, http://0x7f.1/, and http://%6c%6fcalhost/ all pass as loopback (new URL normalizes them to 127.0.0.1 or localhost) and are sent over plain http in their raw form, which the authorization server won't read as a loopback host.
This predates the PR, but since the change is about keeping the raw string and the parsed URL in agreement, consider matching the loopback case against the raw host instead, so only a literal localhost, 127.0.0.1, or [::1] (case-insensitive) qualifies.
~ 🤖
There was a problem hiding this comment.
Fixed in 2909af6. isAllowedResourceUrl now reads the host from the raw resource (rawResourceHost: the authority with any userinfo and port removed, lowercased) and allows plain http only when that host is literally localhost, 127.0.0.1, or [::1] and equals the WHATWG hostname (
javascript/packages/backend/src/api/endpoints/OAuthApplicationsApi.ts
Lines 137 to 145 in 2909af6
http://2130706433/, http://0x7f.1/, and http://%6c%6fcalhost/ are now rejected, and HTTP://LOCALHOST:3000/api and http://user:pass@localhost/... still pass, since the host is case-insensitive per RFC 3986 §3.2.2. Tests: javascript/packages/backend/src/api/__tests__/OAuthApplicationsApi.test.ts
Lines 543 to 545 in 2909af6
Description
What: Reject malformed resource URI components and sparse or non-string scope entries in
oauthApplications.__experimental_exchangeToken()before making a request.Why: The client currently accepts raw brackets in resource paths and can serialize sparse scope arrays into invalid values such as
read, forwarding requests that do not meet the token-exchange parameter grammar.How:
invalid_requesterror contract.Checklist
pnpm testruns as expected (backend Node and edge suites).pnpm buildruns as expected (backend and its dependencies).Type of change