Skip to content

Commit

Permalink
fix: disable csp headers in non-release mode for ui dev (#1304)
Browse files Browse the repository at this point in the history
* fix: disable csp headers in non-release mode for ui dev

* chore: cleanup
  • Loading branch information
markphelps authored Jan 30, 2023
1 parent a3e408e commit cecd7bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 1 addition & 3 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ import (
_ "github.com/golang-migrate/migrate/v4/source/file"
)

const devVersion = "dev"

var (
cfg *config.Config
cfgWarnings []string

cfgPath string
forceMigrate bool
version = devVersion
version = "dev"
commit string
date string
goVersion = runtime.Version()
Expand Down
7 changes: 5 additions & 2 deletions internal/cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ func NewHTTPServer(
logger.Info("CORS enabled", zap.Strings("allowed_origins", cfg.Cors.AllowedOrigins))
}

r.Use(middleware.SetHeader("X-Content-Type-Options", "nosniff"))
r.Use(middleware.SetHeader("Content-Security-Policy", "default-src 'self'; img-src * data:;"))
// TODO: replace with more robust 'mode' detection
if !info.IsDevelopment() {
r.Use(middleware.SetHeader("X-Content-Type-Options", "nosniff"))
r.Use(middleware.SetHeader("Content-Security-Policy", "default-src 'self'; img-src * data:;"))
}

r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
Expand Down
4 changes: 4 additions & 0 deletions internal/info/flipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type Flipt struct {
IsRelease bool `json:"isRelease"`
}

func (f Flipt) IsDevelopment() bool {
return f.Version == "dev" && !f.IsRelease
}

func (f Flipt) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var (
out []byte
Expand Down

0 comments on commit cecd7bc

Please sign in to comment.