Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gnoweb): add secure headers by default & timeout configuration (#…
…3619) This PR adds the following secure headers by default `strict=true` to gnoweb: ```go func SecureHeadersMiddleware(next http.Handler, strict bool) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Prevent MIME type sniffing by browsers. This ensures that the browser // does not interpret files as a different MIME type than declared. w.Header().Set("X-Content-Type-Options", "nosniff") // Prevent the page from being embedded in an iframe. This mitigates // clickjacking attacks by ensuring the page cannot be loaded in a frame. w.Header().Set("X-Frame-Options", "DENY") // Control the amount of referrer information sent in the Referer header. // 'no-referrer' ensures that no referrer information is sent, which // enhances privacy and prevents leakage of sensitive URLs. w.Header().Set("Referrer-Policy", "no-referrer") // In `strict` mode, prevent cross-site resource forgery and enforce https if strict { // Define a Content Security Policy (CSP) to restrict the sources of // scripts, styles, images, and other resources. This helps prevent // cross-site scripting (XSS) and other code injection attacks. // - 'self' allows resources from the same origin. // - '*' allows images from any external source. // - data: is not included to prevent inline images (e.g., base64-encoded images). w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' *; font-src 'self'") // Enforce HTTPS by telling browsers to only access the site over HTTPS // for a specified duration (1 year in this case). This also applies to // subdomains and allows preloading into the browser's HSTS list. w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload") } next.ServeHTTP(w, r) }) } ``` I've also enforced a timeout on read/write/idle (default to 1 minute). cc @kristovatlas --------- Signed-off-by: gfanton <[email protected]> Co-authored-by: Antoine Eddi <[email protected]> Co-authored-by: alexiscolin <[email protected]> Co-authored-by: Morgan <[email protected]>
- Loading branch information