Skip to content

Commit 3a2311e

Browse files
committed
fix(webserver): allow csp to be changed via config (fixes #435)
1 parent 5a988cf commit 3a2311e

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

go.mod

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ require (
1515
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de
1616
)
1717

18-
require github.com/dlclark/regexp2 v1.11.0 // indirect
18+
require (
19+
github.com/dlclark/regexp2 v1.11.0 // indirect
20+
golang.org/x/net v0.28.0 // indirect
21+
)
1922

2023
require (
2124
github.com/alecthomas/chroma/v2 v2.14.0
@@ -26,7 +29,7 @@ require (
2629
github.com/mattn/go-colorable v0.1.13 // indirect
2730
github.com/mattn/go-isatty v0.0.19 // indirect
2831
github.com/pmezard/go-difflib v1.0.0 // indirect
29-
golang.org/x/sys v0.12.0 // indirect
32+
golang.org/x/sys v0.23.0 // indirect
3033
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3134
gopkg.in/yaml.v3 v3.0.1 // indirect
3235
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
6060
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
6161
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de h1:l5Za6utMv/HsBWWqzt4S8X17j+kt1uVETUX5UFhn2rE=
6262
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
63+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
64+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
6365
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
6466
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
6567
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6668
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6769
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
6870
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
71+
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
72+
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6973
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7074
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
7175
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

internal/config/config.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ type Cfg struct {
2929
ConnectionURI string `env:"CONNECTION_URI" json:"-"`
3030

3131
// Web
32-
Headless bool `env:"HEADLESS" envDefault:"false" json:"headless"` // Enable website
33-
Analytics string `env:"ANALYTICS" envDefault:"" json:"analytics"` // <script> tag for analytics (leave blank to disable)
34-
Username string `env:"USERNAME" envDefault:"" json:"username"` // Basic Auth username. Required to enable Basic Auth
35-
Password string `env:"PASSWORD" envDefault:"" json:"password"` // Basic Auth password. Required to enable Basic Auth
32+
Headless bool `env:"HEADLESS" envDefault:"false" json:"headless"` // Enable website
33+
Analytics string `env:"ANALYTICS" envDefault:"" json:"analytics"` // <script> tag for analytics (leave blank to disable)
34+
Username string `env:"USERNAME" envDefault:"" json:"username"` // Basic Auth username. Required to enable Basic Auth
35+
Password string `env:"PASSWORD" envDefault:"" json:"password"` // Basic Auth password. Required to enable Basic Auth
36+
ContentSecurityPolicy string `env:"CSP" envDefault:"default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';" json:"csp"` // Content Security Policy. Must be changed if you are using analytics.
3637

3738
// Document
3839
IDLength int `env:"ID_LENGTH" envDefault:"8" json:"id_length"`

internal/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (s *Server) RegisterHeaders() {
124124
s.Router.Use(middleware.SetHeader("X-Content-Type-Options", "nosniff"))
125125
s.Router.Use(middleware.SetHeader("Referrer-Policy", "no-referrer-when-downgrade"))
126126
s.Router.Use(middleware.SetHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload"))
127-
s.Router.Use(middleware.SetHeader("Content-Security-Policy", "default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';"))
127+
s.Router.Use(middleware.SetHeader("Content-Security-Policy", config.Config.ContentSecurityPolicy))
128128
}
129129

130130
func (s *Server) MountStatic() {

0 commit comments

Comments
 (0)