Spaces:
Running
Running
Add CSP security headers, HTTP-to-HTTPS redirect, and security.txt
Browse filesFiles changed (5)
51 unmodified lines52535455565751 unmodified linesconst defaultCanonicalPanelURL = "https://panel.thtuanit.com"var hfHealthPaths = map[string]struct{}{"/health": {},"/healthz": {},51 unmodified lines525354555657585960616263646566676869707172737475767778798081828351 unmodified linesconst defaultCanonicalPanelURL = "https://panel.thtuanit.com"// PanelContentSecurityPolicy sets baseline XSS and framing protection for the Panel UI without breaking inline hydration scripts or PTY WebSockets.const PanelContentSecurityPolicy = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self' ws: wss:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests"var panelSecurityHeaders = [][2]string{{"Content-Security-Policy", PanelContentSecurityPolicy},{"X-Content-Type-Options", "nosniff"},{"X-Frame-Options", "SAMEORIGIN"},{"Cross-Origin-Opener-Policy", "same-origin-allow-popups"},{"Referrer-Policy", "strict-origin-when-cross-origin"},}// SecurityHeadersMiddleware attaches panel security headers (including Content-Security-Policy) to non-WebSocket, non-proxied-port responses.func SecurityHeadersMiddleware(next http.Handler) http.Handler {return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if !IsWebSocketUpgrade(r) && !strings.HasPrefix(r.URL.Path, "/port/") {h := w.Header()for _, kv := range panelSecurityHeaders {if h.Get(kv[0]) == "" {h.Set(kv[0], kv[1])}}}next.ServeHTTP(w, r)})}var hfHealthPaths = map[string]struct{}{"/health": {},"/healthz": {},
42 unmodified lines4344454647484942 unmodified linesreturn proxy.DomainProxyMiddleware(httpx.HfNoIndexMiddleware(httpx.GZipMiddleware(1000)(mux),),)}42 unmodified lines43444546474849505142 unmodified linesreturn proxy.DomainProxyMiddleware(httpx.HfNoIndexMiddleware(httpx.SecurityHeadersMiddleware(httpx.GZipMiddleware(1000)(mux),),),)}
704 unmodified lines70570670770870971022 unmodified lines733734735736737738704 unmodified linesif resp.StatusCode != http.StatusOK || !strings.Contains(string(body), "SPA_INDEX") {t.Fatalf("unexpected GET / response: %d %q", resp.StatusCode, string(body))}respAbout, err := http.Get(srv.URL + "/about")if err != nil {22 unmodified linesif respPort.StatusCode != http.StatusNotFound {t.Fatalf("expected 404 for unmapped port, got %d", respPort.StatusCode)}}func TestFileManagerCompressExtractAndBulkOps(t *testing.T) {704 unmodified lines70570670770870971071171271371422 unmodified lines737738739740741742743744745704 unmodified linesif resp.StatusCode != http.StatusOK || !strings.Contains(string(body), "SPA_INDEX") {t.Fatalf("unexpected GET / response: %d %q", resp.StatusCode, string(body))}csp := resp.Header.Get("Content-Security-Policy")if !strings.Contains(csp, "default-src 'self'") || !strings.Contains(csp, "frame-ancestors 'self'") {t.Fatalf("expected Content-Security-Policy on GET /, got %q", csp)}respAbout, err := http.Get(srv.URL + "/about")if err != nil {22 unmodified linesif respPort.StatusCode != http.StatusNotFound {t.Fatalf("expected 404 for unmapped port, got %d", respPort.StatusCode)}if portCSP := respPort.Header.Get("Content-Security-Policy"); portCSP != "" {t.Fatalf("did not expect Content-Security-Policy on /port/ proxy route, got %q", portCSP)}}func TestFileManagerCompressExtractAndBulkOps(t *testing.T) {
1234Contact: mailto:thtuanit@gmail.comExpires: 2027-11-30T00:00:00.000ZPreferred-Languages: vi, enCanonical: https://panel.thtuanit.com/.well-known/security.txt1234Contact: mailto:thtuanit@gmail.comExpires: 2027-11-30T00:00:00.000ZPreferred-Languages: vi, enCanonical: https://panel.thtuanit.com/.well-known/security.txtbackend/internal/httpx/httpx.go+26
backend/main.go+3-1
backend/main_test.go+7
frontend/out/.well-known/security.txtAdded+4
frontend/public/.well-known/security.txtAdded+4