SameSite=Lax vs SameSite=Strict: where ProxyAuth can reduce authentication exposure
Was this useful?
0 unique visitors
An authentication system is not secure because it uses an Identity Provider, nor because its cookie carries the right attribute. The exposure of a session depends on the whole path: redirects, cookies, server-side validation, CSRF, what the backend trusts, and how many components must trust each other correctly. This post starts with the cookie and widens from there.
What SameSite controls
SameSite tells the browser whether to attach a cookie to a request
initiated from another site.
Lax— sent on same-site requests, and on cross-site top-level navigations with safe methods (a link click that loads a page withGET). Not sent on cross-site subresource loads or cross-sitePOSTs.Strict— sent only when the request originates from the same site. A link from an email or another site loads the page without the cookie.None— always sent (requiresSecure).
Lax is a sound default for many applications: it blocks classic CSRF
while keeping “click a link, arrive logged in”. It is still a
compromise. Any state-changing action reachable by a cross-site GET
remains exposed, and a cookie that rides along on cross-site navigations
widens the set of situations in which it is presented at all.
The trade-off of Strict
With Strict, the first request after following an external link
arrives without the session. Users see a login page, or an anonymous
view, until the next same-site navigation. For an application that
relies on deep links from email, chat or a portal, that is friction.
There is a second, subtler cost. Many login flows are cross-site by
nature: the browser is sent to an external IdP and back. The callback
is a cross-site navigation, so application cookies that must be present
there cannot be Strict. This is one reason Lax is so common in
IdP-integrated applications.
The cookie ProxyAuth sets
With session_cookie: true, the cookie is always:
Set-Cookie: session_token=...; Secure; HttpOnly; SameSite=Strict; Max-Age=3600
Secure— HTTPS only. Browsers only store it over plain HTTP onlocalhost, which is why the plain-HTTP quick start is for local development only.HttpOnly— unreadable from JavaScript.SameSite=Strict— not negotiable per vhost.Max-Age—max_age_session_cookie(60 s to one year, default 3600), and never longer thantoken_expiry_seconds: the cookie cannot outlive the token it carries.
Why Strict is affordable at a gateway
Strict hurts most when authentication itself involves a cross-site round trip. In ProxyAuth’s gateway mode, it does not:
browser ──► ProxyAuth (same site)
├─ login page (static, same site)
├─ POST /auth (same site)
├─ 303 + cookie (same site)
└─ required_login → backend with X-User headers
Login, cookie issuance and enforcement all happen on the application’s own hostname. There is no external callback that needs the cookie.
The friction that remains is the first request from an external link,
which arrives without the cookie and therefore meets the login page. Any
same-site navigation after that carries the session again, and an
already-authenticated visitor who lands on the login page is sent to
login_redirect_url instead of the form. For internal tools and admin
surfaces, one extra click is usually a fair price.
CSRF is still on
SameSite=Strict is defence in depth, not a replacement for CSRF
tokens. Browser behaviour varies, “same site” is broader than “same
origin” (sibling subdomains are same-site), and a compromised or
user-controlled subdomain is same-site too.
ProxyAuth keeps CSRF on by default:
csrf_token(global) →tag_csrf_token(vhost) →need_csrf(route), combined with AND;- the login form carries
{{ csrf_token }}, filled bytag_proxyauth: true; - proxied HTML forms get the token injected automatically once session cookies and CSRF are on for the vhost.
Bearer-token APIs are the exception: a header is never attached by the
browser on its own, so there is nothing to forge. Set
session_cookie: false and csrf_token: false there.
Logout that actually ends the session
Clearing a cookie only asks the browser to forget. A copy captured earlier — XSS in a sibling app, a shared machine, a log that recorded headers — keeps working until expiry.
GET /logout in ProxyAuth revokes the token server-side, then
clears the cookie. Every later verification checks the revocation set,
so the copy dies at once. Across nodes, that takes redis and up to one
sync tick (15 s).
The backend never holds a credential
Behind a required_login route, the backend receives:
X-User: alice
X-User-Roles: admin,ops
X-User-Groups: engineering
never the password and never the token. Client-supplied copies of these headers are stripped. Compared with every application running its own IdP integration, fewer components ever handle identity tokens.
Where the argument is precise
It is not accurate to say ProxyAuth is more secure than an Identity Provider. A well-built IdP integration is strong. The precise claim is narrower:
For applications that do not need their own user model, enforcing authentication at the gateway can remove cross-site redirects from the login path, which makes
SameSite=Strictpractical, and reduces the number of components that handle credentials or tokens.
Concretely, it can reduce:
- public authentication endpoints (one per gateway, not per app);
- redirect and callback flows to validate;
- application-specific authentication code;
- components that ever see an identity token;
- places to audit and harden.
When an application does need its own user model, ProxyAuth can act as its OIDC provider instead. There the relying party owns its own session cookies, and the SameSite choice is the application’s.
A hardened browser vhost
vhosts:
- vhost: ["internal.example.com"]
allow_groups: ["staff"]
session_cookie: true
tag_csrf_token: true
login_via_otp: true
max_age_session_cookie: 1800
cors_origins: null
login_redirect_url: "/app"
logout_redirect_url: "/"
headers:
Strict-Transport-Security: "max-age=63072000; includeSubDomains"
Content-Security-Policy: "default-src 'self'"
X-Frame-Options: "DENY"
routes:
- prefix: "/"
static: "/var/www/login/"
static_index: "login.html"
tag_proxyauth: true
cache: false
- prefix: "/app"
target: "http://127.0.0.1:8000"
required_login: true
cache: false
{
"token_expiry_seconds": 1800,
"ratelimit_auth": { "requests_per_second": 2, "burst": 5, "block_delay": 5000 },
"redis": "redis://10.0.0.5:6379/3"
}
Bind the backend to 127.0.0.1 or a private interface so the gateway
is the only way in.
Security is a system property
SameSite=Strict does not replace session expiry, token integrity,
CSRF tokens, password hashing, authorization, TLS, backend isolation,
key management or revocation. The benefit comes from designing them
together — and from putting them at a boundary that is enforced the
same way for every application behind it.
Lax is a reasonable compromise when login needs cross-site redirects. When login happens on the application’s own hostname, Strict stops costing much — and paired with CSRF tokens, revocation on logout and identity-only headers, it closes more than any single attribute can.