@ory/client-fetch: toSession() overwrites Cookie header when using initOverrides.headers
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 178
- Forks
- 96
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Ory Network Project
No response
Describe the bug
When using @ory/client-fetch, the toSession() method allows passing a cookie parameter as part of requestParameters, which correctly sets the Cookie header — unless initOverrides.headers is also provided. In that case, the SDK silently overwrites the Cookie header with the contents of initOverrides.headers, leading to unexpected 401 Unauthorized response.
Reproducing the bug
const session = await api.toSession(
{ cookie },
{
headers: {
'Cache-Control': 'max-age=0'
}
}
);
Expected behavior:
The request sends both Cookie and Cache-Control headers
Actual behavior:
Only Cache-Control is sent. Cookie is silently overwritten. Request fails with 401 Unauthorized.
Workaround
Manually add the cookie into headers:
const session = await api.toSession(
{ cookie },
{
headers: {
'Cache-Control': 'max-age=0',
'Cookie': cookie
}
}
);
Relevant log output
Relevant configuration
Version
"@ory/client-fetch": "1.22.4"
On which operating system are you observing this issue?
None
In which environment are you deploying?
None
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the generated @ory/client-fetch implementation of toSession(), focusing on how requestParameters.cookie and initOverrides.headers are combined. Reproduce the example with both headers, then verify the fix preserves Cookie alongside Cache-Control and prevents the resulting 401 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100