Skip to content

Self hosted instance creates insecure cookies on https potentially exposing better-auth.session_token plaintext #4709

Closed

Description

@samiyuru

To Reproduce

Configure dokploy instance on https. Login to the system on https. Check the browser cookies and locate 'better-auth.session_token'. The cookie is not secure. As a result the browser can send the session cookie plain text if the user uses http from an old link or by mistake etc making the deployment highly insecure.

Current vs. Expected behavior

better-auth.session_token should be secure on https.

Provide environment information

Default installation script was used.

Which area(s) are affected? (Select all that apply)

Remote server

Are you deploying the applications where Dokploy is installed or on a remote server?

Same server where Dokploy is installed

Additional context

No response

Will you send a PR to fix it?

No

Activity

  1. dosubot commented on Jun 30, 2026

    @dosubot

    Hi @samiyuru! I'm Dosu and I'm helping the Dokploy team.

    You're correct that the better-auth.session_token cookie is not marked as secure on self-hosted instances, even when served over HTTPS. This is because the cookie attributes are hardcoded in the auth configuration rather than being dynamically set based on the connection protocol.

    In packages/server/src/lib/auth.ts, when IS_CLOUD is false (i.e., all self-hosted deployments), the config explicitly sets:

    advanced: {
      useSecureCookies: false,
      defaultCookieAttributes: {
        sameSite: "lax",
        secure: false,
        httpOnly: true,
        path: "/",
      },
    }

    This means secure: false is applied regardless of whether HTTPS is configured via Traefik. The likely reason this was done is to support self-hosted instances that run over plain HTTP or sit behind reverse proxies handling TLS termination — but as you noted, it means the session token can be sent in plaintext if the browser makes an HTTP request.

    There's currently no environment variable to toggle this behavior. A fix could involve either:

    1. Detecting whether the instance is served over HTTPS (e.g., checking if a certificate resolver is configured in Traefik) and conditionally setting secure: true
    2. Adding an environment variable (e.g., SECURE_COOKIES=true) that users can set to enable the secure flag

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dokploy with Dosu Add Dosu to your team

  2. Siumauricio commented on Aug 4, 2026

    @Siumauricio
    Contributor

    Reproduced and confirmed on v0.29.13 — the session cookie is issued without the Secure attribute even when the request arrives over TLS.

    Test (local instance, login via /api/auth/sign-in/email):

    Plain HTTP request:

    set-cookie: better-auth.session_token=...; Max-Age=259200; Path=/; HttpOnly; SameSite=Lax
    

    Same request with X-Forwarded-Proto: https (what Traefik sends when the instance is served over TLS):

    set-cookie: better-auth.session_token=...; Max-Age=259200; Path=/; HttpOnly; SameSite=Lax
    

    Secure is absent in both cases, so a self-hosted instance behind HTTPS does hand out a cookie the browser will replay over plain HTTP — exactly as you described. HttpOnly and SameSite=Lax are set, which limits it, but this should carry Secure whenever the deployment is HTTPS.

    Keeping this open as a confirmed bug.

  3. added a commit that references this issue on Sep 29, 2026
    f5c21db
  4. added a commit that references this issue on Oct 5, 2026
    1049e62
  5. added a commit that references this issue on Oct 11, 2026
    28ebc38
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