Skip to content

hardening 051726#9

Merged
ntner merged 2 commits into
masterfrom
updates-051726
May 20, 2026
Merged

hardening 051726#9
ntner merged 2 commits into
masterfrom
updates-051726

Conversation

@ntner
Copy link
Copy Markdown
Contributor

@ntner ntner commented May 17, 2026

Summary

  • Add Secure flag to session cookies (conditional on TLS or X-Forwarded-Proto: https)
  • Add HttpOnly flag to session cookies to prevent JavaScript access
  • Set ReadHeaderTimeout: 30s to mitigate slowloris-style header attacks
  • Set IdleTimeout: 120s to reclaim idle keep-alive connections

Details

Cookie Secure flag is set dynamically based on r.TLS != nil || strings.EqualFold(r.Header.Get("X-Forwarded-Proto"), "https"). This ensures cookies are marked Secure when served over HTTPS (direct or behind a TLS-terminating proxy) while preserving local development over plain HTTP.

ReadHeaderTimeout and IdleTimeout are the two safe timeouts for a server that handles streaming responses and websocket connections. ReadTimeout and WriteTimeout are intentionally not set to avoid breaking long-lived connections.

@ntner ntner merged commit e3ea263 into master May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants