fix(backend): preserve Set-Cookie headers through proxy#8162
Conversation
… of the same name
🦋 Changeset detectedLatest commit: 21a5805 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 |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
Classic headers issue! |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a changeset for a patch release to `@clerk/backend`. Implements an SSRF guard by deriving the expected frontend API host from `fapiBaseUrl` and rejecting proxied requests whose resolved `targetUrl.host` differs with a 400 `proxy_request_failed` JSON error. Adjusts proxy response handling to append upstream `Set-Cookie` headers (preserving multiple cookies) while setting other headers normally. Adds tests for ambiguous/protocol-relative target URLs and preservation of multiple `Set-Cookie` headers. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Use `headers.append()` instead of `headers.set()` for `set-cookie` headers when copying FAPI response headers, preventing multiple Set-Cookie values from being silently dropped (which caused OAuth callback failures due to missing `__client` cookies). Also add a host validation guard to prevent SSRF via protocol-relative paths (e.g., `//evil.com/steal`) that would cause the URL constructor to resolve to an attacker-controlled host, leaking the secret key. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…y construction Replace `new URL(path, base)` with string concatenation so that protocol-relative paths like `//evil.com` can never change the host. The defense-in-depth host check is kept as a belt-and-suspenders guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/backend/src/proxy.ts`:
- Around line 295-302: The bridge currently forwards response headers using
response.setHeader in the authenticateRequest flow which overwrites repeated
Set-Cookie values; update the header-forwarding loop in authenticateRequest (the
code that iterates response.headers and calls response.setHeader(key, value)) to
use response.appendHeader(key, value) for headers that may repeat (particularly
'set-cookie'), matching the approach used elsewhere (responseHeaders.append in
proxy.ts and the response.appendHeader call at line ~69), so multiple cookies
are preserved when sent to the client.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: 79a73bb2-ec07-4aa9-8ca1-0967c86d9033
📒 Files selected for processing (2)
packages/backend/src/__tests__/proxy.test.tspackages/backend/src/proxy.ts
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
headers.append()instead ofheaders.set()forset-cookieresponse headers inclerkFrontendApiProxy, fixing OAuth callback failures caused by dropped__client/__client_uatcookiesTest plan
Set-Cookieheaders are preserved through the proxy (usingresponse.headers.getSetCookie())🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Security
Tests