package middleware import ( "net/http" "strings" ) // buildCSP constructs a Content-Security-Policy value. When scriptHashes // is non-empty, script-src uses those hashes instead of 'unsafe-inline'; // when empty, it falls back to 'unsafe-inline' so the server still works // when the embedded UI was not built (development, API-only deploys). func buildCSP(scriptHashes []string) string { scriptSrc := "'self' 'unsafe-inline'" if len(scriptHashes) > 0 { scriptSrc = "'self' " + strings.Join(scriptHashes, " ") } return "default-src 'self'" + "; script-src " + scriptSrc + "; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com" + "; font-src 'self' https://fonts.gstatic.com" + "; img-src 'self' data:" + "; connect-src 'self'" } // SecurityHeaders returns HTTP middleware that sets defensive security // headers on every response. scriptHashes are CSP-formatted SHA-256 // hashes of the embedded SPA's inline