mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
security: suppress Allow-Credentials on wildcard CORS origin (CORS-1) (#3980)
fix(security): suppress Allow-Credentials on wildcard CORS origin (CORS-1) Per CORS spec §3.2, Access-Control-Allow-Credentials must not be "true" when Access-Control-Allow-Origin is the wildcard "*". ACHeadersMiddleware (pkg/common/http_server.go) and getUIHeadersHandler (pkg/api/routes.go) now only emit the credentials header when an explicit, non-empty AllowOrigin is configured. Deployments that leave AllowOrigin blank (default wildcard) no longer produce a contradictory header pair. Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
eadc9b65ed
commit
bfc59ad120
@@ -38,9 +38,12 @@ func ACHeadersMiddleware(config *config.Config, allowedMethods ...string) mux.Mi
|
||||
resp.Header().Set("Access-Control-Allow-Methods", allowedMethodsValue)
|
||||
resp.Header().Set("Access-Control-Allow-Headers", "Authorization,content-type,"+constants.SessionClientHeaderName)
|
||||
|
||||
// Get auth config safely
|
||||
// Access-Control-Allow-Credentials must not be "true" when
|
||||
// Access-Control-Allow-Origin is the wildcard "*" (CORS spec §3.2).
|
||||
// Only advertise credentials support when an explicit origin is set.
|
||||
authConfig := config.CopyAuthConfig()
|
||||
if authConfig.IsBasicAuthnEnabled() {
|
||||
allowOrigin := strings.TrimSpace(config.GetAllowOrigin())
|
||||
if authConfig.IsBasicAuthnEnabled() && allowOrigin != "" && allowOrigin != "*" {
|
||||
resp.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user