Skip to content

Safari localhost by default doesn't persist cookies created by H3 session #977

Open
@bhouston

Description

@bhouston

Environment

Latest Safari and MacOS.

This library is being used by TanStack Start and I reported the issue there:

TanStack/router#3492

This affects both the v1 and v2 branches.

Reproduction

The reproduction is given on TanStack Start example here: TanStack/router#3492

But basically cookies will persist by default in Chrome and Firefox on MacOS but not Safari (and I suspect this also happens on iOS.)

Describe the bug

The culprit is in H3 on this line:

secure: true,

Basically DEFAULT_COOKIE is used as defaults in updateSession:

...DEFAULT_COOKIE,
and also in
...DEFAULT_COOKIE,

DEFAULT_COOKIE has secure = true.

But if you use http localhost on Safari in dev mode, cookies will not persist by default not, they will fail silently.

So if you do not specify a value for "cookie.secure" it will end up as true and thus Safari development mode will fail to save cookies.

Note be careful when setting 'secure' to true, as compliant clients will not send the cookie back to the server in the future if the browser does not have an HTTPS connection.

Maybe automatically change cookie secure setting based on process.env.NODE_ENV === 'production' or something similar? That is what I am suggesting to TanStack Start.

Additional context

Again, you can read my original issue over on TanStack Start here describing the issue: TanStack/router#3492

Logs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions