Skip to content

fix(helpers): preserve multiple Set-Cookie headers in withCookie - #838

Open
pcbeingused333 wants to merge 1 commit into
descope:mainfrom
pcbeingused333:fix/preserve-multiple-set-cookie
Open

pcbeingused333 wants to merge 1 commit into
descope:mainfrom
pcbeingused333:fix/preserve-multiple-set-cookie

Conversation

@pcbeingused333

Copy link
Copy Markdown

Related Issues

No existing issue.

Description

withCookie read response.headers.get('set-cookie') and pushed that single string into cookies. Headers.get() joins repeated Set-Cookie headers with a comma, so when Descope returns both the DS and DSR cookies, cookies holds one combined entry. Forwarding it (as the README middleware does with res.set('Set-Cookie', out.cookies)) sends a single Set-Cookie header, and the browser only stores the first cookie; the second one is read as an attribute of the first.

This adds a small getSetCookies helper that uses Headers.getSetCookie() when available and falls back to the combined value on runtimes without it (same behaviour as before there). Every Set-Cookie header becomes its own entry in cookies, and the refresh token is looked up across all of them. No comma-splitting is attempted, since Expires contains commas.

New test in lib/index.test.ts: a response with two Set-Cookie headers (both with Expires) must come back as two separate cookies entries, with refreshJwt taken from the second. It fails on main (one combined entry) and passes with this change.

Must

  • Tests
  • Documentation (if applicable) — not applicable, no public API change

This PR was prepared with the help of an AI coding assistant (Claude) and submitted on the author's behalf; the change and tests were produced by that assistant.

Headers.get('set-cookie') joins repeated Set-Cookie headers with a comma, so
withCookie returned DS and DSR as one cookie string. Read each header
separately via getSetCookie (falling back to the combined value on runtimes
without it) and look for the refresh token across all of them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@shuni-bot

shuni-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🐕 Shuni Review

No new issues found.

Approval outcome: APPROVED
Reason: Full review completed with no findings and clear review threads.

🤖 Model: claude-opus-5.5 · Effort: high


Review scope: Full review

Reviewed files (2)
  • lib/helpers.ts
  • lib/index.test.ts

🐕 Review complete — View session on Shuni Portal 🐾

🤖 Model: claude-opus-5.5 · Effort: high

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant