Skip to content

Commit 5a0338c

Browse files
authored
fix(csrf): allow to set trusted origins (#4347)
1 parent 049799e commit 5a0338c

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

config/flipt.schema.cue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import "list"
4343
csrf?: {
4444
key: string
4545
secure?: bool
46+
trusted_origins?: [...] | string | *[]
4647
}
4748
}
4849

config/flipt.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@
8585
"type": "object",
8686
"properties": {
8787
"key": { "type": "string" },
88-
"secure": { "type": "boolean" }
88+
"secure": { "type": "boolean" },
89+
"trusted_origins": {
90+
"type": ["array", "null"],
91+
"default": []
92+
}
8993
},
9094
"required": []
9195
}

internal/cmd/http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ func NewHTTPServer(
180180
handler.ServeHTTP(w, r)
181181
})
182182
})
183-
r.Use(csrf.Protect([]byte(key), csrf.Path("/"), csrf.Secure(cfg.Authentication.Session.CSRF.Secure)))
183+
r.Use(csrf.Protect(
184+
[]byte(key),
185+
csrf.Path("/"),
186+
csrf.Secure(cfg.Authentication.Session.CSRF.Secure),
187+
csrf.TrustedOrigins(cfg.Authentication.Session.CSRF.TrustedOrigins),
188+
))
184189
}
185190

186191
r.Mount("/api/v1", api)

internal/config/authentication.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ type AuthenticationSessionCSRF struct {
246246
Key string `json:"-" mapstructure:"key"`
247247
// Secure signals to the CSRF middleware that the request is being served over TLS or plaintext HTTP
248248
Secure bool `json:"secure,omitempty" mapstructure:"secure" yaml:"secure,omitempty"`
249+
// TrustedOrigins is a list of trusted origins that are allowed to send requests
250+
TrustedOrigins []string `json:"trustedOrigins,omitempty" mapstructure:"trusted_origins" yaml:"trusted_origins,omitempty"`
249251
}
250252

251253
// AuthenticationMethods is a set of configuration for each authentication

0 commit comments

Comments
 (0)