all repos — homestead @ b9efca3f3332bbb0ef0bafbafe5ac58561893507

Code for my website

remove CSP header/custom style hashes

Alan Pearce
commit

b9efca3f3332bbb0ef0bafbafe5ac58561893507

parent

ba841774eb770dab4314da515cc462e9c7706eef

M domain/web/mux.godomain/web/mux.go
@@ -1,7 +1,6 @@
package website import ( - "fmt" "net/http" "regexp" "slices"
@@ -51,10 +50,6 @@ }
analytics.WithTitle(r, file.Title) w.Header().Add("ETag", file.Etag) w.Header().Add("Vary", "Accept-Encoding") - if file.StyleHash != "" { - CSPHeader.StyleSrc = append(CSPHeader.StyleSrc, fmt.Sprintf("'%s'", file.StyleHash)) - } - w.Header().Add("Content-Security-Policy", CSPHeader.String()) for k, v := range ExtraHeaders { w.Header().Add(k, v) }
M domain/web/website.godomain/web/website.go
@@ -5,7 +5,6 @@ "context"
"net/http" "os" "path/filepath" - "slices" "sync" "time"
@@ -27,7 +26,6 @@ "alin.ovh/x/log"
"github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" - "github.com/crewjam/csp" "github.com/osdevisnot/sorvor/pkg/livereload" )
@@ -52,21 +50,9 @@ log *log.Logger
reader storage.Reader calendar *calendar.Calendar identity *identity.Service - CSP *csp.Header *server.App } -var CSPHeader = csp.Header{ - DefaultSrc: []string{"'none'"}, - FormAction: []string{"'none'"}, - BaseURI: []string{"'none'"}, - ImgSrc: []string{"'self'", "https://pkg.go.dev/"}, - ScriptSrc: []string{"'self'"}, - StyleSrc: []string{"'self'"}, - FrameAncestors: []string{"https://kagi.com"}, - RequireTrustedTypesFor: []csp.RequireTrustedTypesFor{csp.RTTFScript}, -} - var ExtraHeaders = map[string]string{ "Cache-Control": "max-age=14400", "X-Content-Type-Options": "nosniff",
@@ -112,11 +98,6 @@ })
roots, err := fetcher.Subscribe() if err != nil { return nil, fault.Wrap(err, fmsg.With("could not set up fetcher")) - } - - if opts.Development { - CSPHeader.ScriptSrc = slices.Insert(CSPHeader.ScriptSrc, 0, "'unsafe-inline'") - CSPHeader.ConnectSrc = slices.Insert(CSPHeader.ConnectSrc, 0, "'self'") } firstUpdate := make(chan bool)
M go.modgo.mod
@@ -17,7 +17,6 @@ github.com/antchfx/xmlquery v1.4.4
github.com/antchfx/xpath v1.3.3 github.com/ardanlabs/conf/v3 v3.4.0 github.com/benpate/digit v0.13.4 - github.com/crewjam/csp v0.0.2 github.com/deckarep/golang-set/v2 v2.7.0 github.com/fsnotify/fsnotify v1.8.0 github.com/go-git/go-git/v5 v5.14.0
M go.sumgo.sum
@@ -111,8 +111,6 @@ github.com/creachadair/taskgroup v0.13.2 h1:3KyqakBuFsm3KkXi/9XIb0QcA8tEzLHLgaoidf0MdVc=
github.com/creachadair/taskgroup v0.13.2/go.mod h1:i3V1Zx7H8RjwljUEeUWYT30Lmb9poewSb2XI1yTwD0g= github.com/creack/pty v1.1.23 h1:4M6+isWdcStXEf15G/RbrMPOQj1dZ7HPZCGwE4kOeP0= github.com/creack/pty v1.1.23/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= -github.com/crewjam/csp v0.0.2 h1:fIq6o0Z6bkABlvLT3kB0XgPnVX9iNXSAGMILs6AqHVw= -github.com/crewjam/csp v0.0.2/go.mod h1:0tirp4wHwMLZZtV+HXRqGFkUO7uD2ux+1ECvK+7/xFI= github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
M gomod2nix.tomlgomod2nix.toml
@@ -136,9 +136,6 @@ hash = "sha256-jEaJSKcwmKtXFkvtxwpEdFMdazXZM6bY2u5TGBimklI="
[mod."github.com/coreos/go-iptables"] version = "v0.7.1-0.20240112124308-65c67c9f46e6" hash = "sha256-kjnry8ld5Keew5q+tX7GSdGVZaXlehs2Lt+z8Rokhns=" - [mod."github.com/crewjam/csp"] - version = "v0.0.2" - hash = "sha256-4vlGmDdQjPiXmueCV51fJH/hRcG8eqhCi9TENCXjzfA=" [mod."github.com/cyphar/filepath-securejoin"] version = "v0.4.1" hash = "sha256-NOV6MfbkcQbfhNmfADQw2SJmZ6q1nw0wwg8Pm2tf2DM="
M shared/storage/sqlite/db/models.goshared/storage/sqlite/db/models.go
@@ -18,7 +18,6 @@ ContentType string
LastModified int64 Title string Etag string - StyleHash string Headers []byte }
M shared/storage/sqlite/db/query.sql.goshared/storage/sqlite/db/query.sql.go
@@ -27,7 +27,7 @@ }
const getFile = `-- name: GetFile :many SELECT - file.file_id, file.url_id, file.content_type, file.last_modified, file.title, file.etag, file.style_hash, file.headers, + file.file_id, file.url_id, file.content_type, file.last_modified, file.title, file.etag, file.headers, content.content_id, content.file_id, content.encoding, content.body FROM url INNER JOIN file
@@ -59,7 +59,6 @@ &i.File.ContentType,
&i.File.LastModified, &i.File.Title, &i.File.Etag, - &i.File.StyleHash, &i.File.Headers, &i.Content.ContentID, &i.Content.FileID,
@@ -97,7 +96,7 @@ }
const insertFile = `-- name: InsertFile :execlastid INSERT INTO file ( - url_id, content_type, last_modified, etag, style_hash, title, headers + url_id, content_type, last_modified, etag, title, headers ) VALUES ( ?1,
@@ -105,8 +104,7 @@ ?2,
?3, ?4, ?5, - ?6, - ?7 + ?6 ) `
@@ -115,7 +113,6 @@ UrlID int64
ContentType string LastModified int64 Etag string - StyleHash string Title string Headers []byte }
@@ -126,7 +123,6 @@ arg.UrlID,
arg.ContentType, arg.LastModified, arg.Etag, - arg.StyleHash, arg.Title, arg.Headers, )
M shared/storage/sqlite/query.sqlshared/storage/sqlite/query.sql
@@ -3,14 +3,13 @@ INSERT INTO url (path) VALUES (?);
-- name: InsertFile :execlastid INSERT INTO file ( - url_id, content_type, last_modified, etag, style_hash, title, headers + url_id, content_type, last_modified, etag, title, headers ) VALUES ( @url_id, @content_type, @last_modified, @etag, - @style_hash, @title, @headers );
M shared/storage/sqlite/reader.goshared/storage/sqlite/reader.go
@@ -47,7 +47,6 @@ file.ContentType = row.File.ContentType
file.LastModified = time.Unix(row.File.LastModified, 0) file.Etag = row.File.Etag file.Title = row.File.Title - file.StyleHash = row.File.StyleHash if len(row.File.Headers) > 2 { err := json.Unmarshal(row.File.Headers, &file.Headers)
M shared/storage/sqlite/schema.sqlshared/storage/sqlite/schema.sql
@@ -13,7 +13,6 @@ content_type TEXT NOT NULL,
last_modified INTEGER NOT NULL, title TEXT NOT NULL, etag TEXT NOT NULL, - style_hash TEXT NOT NULL, headers BLOB NOT NULL, FOREIGN KEY (url_id) REFERENCES url (url_id) ) STRICT;
M shared/storage/sqlite/writer.goshared/storage/sqlite/writer.go
@@ -105,7 +105,6 @@ UrlID: urlID,
ContentType: file.ContentType, LastModified: file.LastModified.Unix(), Etag: file.Etag, - StyleHash: file.StyleHash, Title: file.Title, Headers: []byte{}, }