ory / ory/sdk

@ory/client-fetch: toSession() overwrites Cookie header when using initOverrides.headers

Open
#445 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
178
Forks
96
Avg merge
6d 23h
Merged PRs (30d)
3

Description

Preflight checklist
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.