fix(security): secure session cookies and HSTS over https #30
No reviewers
Labels
No labels
bug
docs
duplicate
enhancement
help wanted
invalid
nice-to-have
pre-1.0
question
security
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/lamplighter!30
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/15-secure-cookies"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #15.
Session (
_lamplighter_key) and remember-me cookies weren'tsecure, and there was no HSTS.What changes
LamplighterWeb.Endpoint.https?/0: the endpoint's url scheme is https, whichruntime.exssets in production.Plug.Sessioninitialised per request from a function plug, sosecurecan follow runtime config) and the remember-me cookie aresecure, and the:browserpipeline sendsstrict-transport-security: max-age=31536000. NoincludeSubDomains, since homelab domains are often shared with http-only services.force_ssl: behind a TLS proxy the app sees plain http, and redirecting relies on the proxy sendingX-Forwarded-Proto, which risks redirect loops. HSTS plus secure cookies cover the issue without that.Tests:
secure_cookies_test.exs(sync) switches the endpoint url scheme: over https both cookies are secure and HSTS is sent; over http neither. The https test fails on main.mix precommit: 626 pass.Review (Nye) at
bf4a754: changes requested (F7, medium).Agree on leaving force_ssl off: the Secure flag and HSTS don't depend on conn.scheme, so they work behind a TLS proxy without redirect loops.
Problem: prod hard-codes url scheme https (config/runtime.exs), and cookies are now Secure whenever the scheme is https. A plain-http LAN install (docker run -p 4000:4000, browse http://nas:4000), which could log in before this PR, now can't: browsers drop Secure cookies set over http, and there's no way to opt out.
Fix: read PHX_SCHEME (default "https") and PHX_URL_PORT (default 443) in runtime.exs for the endpoint url, and document both in the README env table (this is also audit gap #7, the OIDC redirect_uri/links on http installs). Failing test: test/review/http_install_test.exs (sent to you).
Otherwise good: session and remember-me cookies both get secure, HSTS only on the https config, tests cover both schemes. mix precommit: 626 pass. CI green.
bf4a75485c7ba15f46267ba15f46265b8b776945Review (Nye): Re-reviewed at
7ba15f4: F7 fixed, PHX_SCHEME/PHX_URL_PORT read and validated, cookies secure + HSTS only over https, precommit 647 tests green. Ready.(Rebased onto main
8f9ff14as5b8b776after #31: kept url_scheme/url_port, dropped the dns_cluster_query line. Precommit 647 green.)5b8b7769459df63c9d05