You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Self hosted instance creates insecure cookies on https potentially exposing better-auth.session_token plaintext #4709
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?
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.
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:
Detecting whether the instance is served over HTTPS (e.g., checking if a certificate resolver is configured in Traefik) and conditionally setting secure: true
Adding an environment variable (e.g., SECURE_COOKIES=true) that users can set to enable the secure flag
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.
Activity
dosubot commentedon Jun 30, 2026
Hi @samiyuru! I'm Dosu and I'm helping the Dokploy team.
You're correct that the
better-auth.session_tokencookie is not marked assecureon 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, whenIS_CLOUDisfalse(i.e., all self-hosted deployments), the config explicitly sets:This means
secure: falseis 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:
secure: trueSECURE_COOKIES=true) that users can set to enable the secure flagTo reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
Siumauricio commentedon Aug 4, 2026
Reproduced and confirmed on v0.29.13 — the session cookie is issued without the
Secureattribute even when the request arrives over TLS.Test (local instance, login via
/api/auth/sign-in/email):Plain HTTP request:
Same request with
X-Forwarded-Proto: https(what Traefik sends when the instance is served over TLS):Secureis 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.HttpOnlyandSameSite=Laxare set, which limits it, but this should carrySecurewhenever the deployment is HTTPS.Keeping this open as a confirmed bug.
fix: mark session cookie as Secure when served over HTTPS
fix: mark session cookie as Secure when served over HTTPS
fix: mark session cookie as Secure when served over HTTPS
chore(release): 0.42.0 [skip ci]