Skip to content

Commit 807b218

Browse files
committed
chore: remove nonce from the index.html
It doesn't help UserPilot and only breaks ApexChart for some weird reason. Signed-off-by: Artem Chernyshev <[email protected]>
1 parent 0558c18 commit 807b218

File tree

2 files changed

+6
-46
lines changed

2 files changed

+6
-46
lines changed

frontend/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta name="color-scheme" content="dark" />
88
<meta name="theme-color" content="#13141c" />
9-
<meta name="csp-nonce" content="{{.Nonce}}" />
109
<title>Omni</title>
1110
</head>
1211
<body>

internal/frontend/handler.go

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
package frontend
88

99
import (
10-
"crypto/rand"
1110
"errors"
1211
"fmt"
13-
"html/template"
1412
"io"
1513
"io/fs"
1614
"net/http"
@@ -19,8 +17,6 @@ import (
1917
"path/filepath"
2018
"strings"
2119
"time"
22-
23-
"github.com/jxskiss/base62"
2420
)
2521

2622
const index = "/index.html"
@@ -111,27 +107,13 @@ func (handler *StaticHandler) serveFile(w http.ResponseWriter, r *http.Request,
111107
if path != index {
112108
w.Header().Set("Vary", "Accept-Encoding, User-Agent")
113109
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d, immutable", handler.maxAgeSec))
114-
http.ServeContent(w, r, file.Name(), handler.modTime, file)
115110
} else {
116111
w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
117112

118-
b := make([]byte, 10)
119-
if _, err := rand.Read(b); err != nil {
120-
writeHTTPError(w, fmt.Errorf("failed to read random bytes: %w", err))
121-
122-
return
123-
}
124-
125-
nonce := base62.EncodeToString(b)
126-
127-
w.Header().Set("Content-Security-Policy",
128-
"upgrade-insecure-requests"+
129-
fmt.Sprintf(";default-src 'self' 'nonce-%s'", nonce)+
130-
";img-src * data:"+
131-
";connect-src 'self' https://*.auth0.com https://*.userpilot.io wss://*.userpilot.io"+
132-
";font-src 'self' data:"+
133-
fmt.Sprintf(";style-src 'self' 'nonce-%s' data: https://fonts.googleapis.com https://fonts.gstatic.com", nonce)+
134-
";frame-src https://*.auth0.com",
113+
w.Header().Set("Content-Security-Policy", "default-src 'self' https://*.userpilot.io; img-src * data: ; "+
114+
";connect-src 'self' https://*.auth0.com https://*.userpilot.io wss://*.userpilot.io ;font-src 'self' data: "+
115+
";style-src 'self' 'unsafe-inline' https://fonts.googleapis.com data: ;upgrade-insecure-requests;"+
116+
";frame-src https://*.auth0.com",
135117
)
136118

137119
w.Header().Set("X-Frame-Options", "SAMEORIGIN")
@@ -142,31 +124,10 @@ func (handler *StaticHandler) serveFile(w http.ResponseWriter, r *http.Request,
142124
"magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials=(self),"+
143125
"screen-wake-lock=(), sync-xhr=(self), usb=(), web-share=(), xr-spatial-tracking=()",
144126
)
145-
146-
// Read index.html content
147-
content, err := io.ReadAll(file)
148-
if err != nil {
149-
writeHTTPError(w, err)
150-
151-
return
152-
}
153-
154-
tmpl, err := template.New("index.html").Parse(string(content))
155-
if err != nil {
156-
writeHTTPError(w, err)
157-
158-
return
159-
}
160-
161-
// Inject nonce into index.html
162-
err = tmpl.Execute(w, struct{ Nonce string }{Nonce: nonce})
163-
if err != nil {
164-
writeHTTPError(w, err)
165-
166-
return
167-
}
168127
}
169128

129+
http.ServeContent(w, r, file.Name(), handler.modTime, file)
130+
170131
return
171132
}
172133

0 commit comments

Comments
 (0)