fix(19.3-06): credentialed CORS refuses wildcard-host and unanchored origins (WR-04)

- with supports_credentials, a * origin must be the whole leftmost host
  label, patterns must be anchored with ^ and $, and no origin rule may
  match the probe origins outside any configured domain
- globally and per profile; non-credentialed configs load as before
This commit is contained in:
Jakub Zych
2026-10-15 22:25:43 +02:00
parent 072353663e
commit e32940d90f
4 changed files with 131 additions and 4 deletions

View File

@@ -71,6 +71,25 @@ cors:
`)); err != nil {
t.Fatalf("credentials with exact origins: %v", err)
}
// A wildcard host and an unanchored pattern are the same exposure under
// another spelling (WR-04): refused with credentials, loaded without.
for _, tc := range []struct{ key, value, want string }{
{"allowed_origins", "https://*", "http.cors.allowed_origins[1]"},
{"allowed_origins_patterns", `https://.*\.example\.com`, "http.cors.allowed_origins_patterns[1]"},
} {
list := `["https://www.example.com", '` + tc.value + `']`
if tc.key == "allowed_origins_patterns" {
list = `['^https://www\.example\.com$', '` + tc.value + `']`
}
yaml := "cors:\n paths: [\"api/*\"]\n " + tc.key + ": " + list + "\n"
if _, err := LoadCORSConfig(writeHTTPConfig(t, yaml+" supports_credentials: true\n")); err == nil || !strings.Contains(err.Error(), tc.want) {
t.Errorf("%s with credentials: error = %v, want one naming %s", tc.value, err, tc.want)
}
if _, err := LoadCORSConfig(writeHTTPConfig(t, yaml)); err != nil {
t.Errorf("%s without credentials: %v", tc.value, err)
}
}
}
func TestCORSPatternErrors(t *testing.T) {