Skip to content

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

@YanaHoncharova

Description

@YanaHoncharova

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions