fix(19.3-06): production refuses an inferred insecure token cookie (WR-05)

- LoadCookieConfig refuses a Secure that resolves to false in production,
  also when inferred from an http or unset app.url, naming
  auth.cookie.secure and app.url
This commit is contained in:
Jakub Zych
2026-10-15 22:26:43 +02:00
parent e32940d90f
commit 4dae8331c5
4 changed files with 22 additions and 13 deletions

View File

@@ -39,16 +39,19 @@ func TestLoadCookieConfigDefaults(t *testing.T) {
t.Fatalf("nil source = %+v", cfg)
}
// An http or unset app.url infers Secure false outside production only;
// production refuses it (TestLoadCookieConfigErrors).
for _, tc := range []struct {
url string
env string
secure bool
}{
{"https://app.example.com", true},
{"HTTPS://app.example.com", true},
{"http://localhost:8000", false},
{"", false},
{"https://app.example.com", "production", true},
{"HTTPS://app.example.com", "production", true},
{"http://localhost:8000", "development", false},
{"", "development", false},
} {
cfg, err := LoadCookieConfig(cookieSource{values: map[string]any{"app.url": tc.url}, env: "production"})
cfg, err := LoadCookieConfig(cookieSource{values: map[string]any{"app.url": tc.url}, env: tc.env})
if err != nil {
t.Fatalf("app.url %q: %v", tc.url, err)
}
@@ -104,6 +107,8 @@ func TestLoadCookieConfigErrors(t *testing.T) {
{"same_site none on http app", map[string]any{"auth.cookie.same_site": "none", "app.url": "http://localhost"}, "", "auth.cookie.same_site"},
{"secure false in production", map[string]any{"auth.cookie.secure": false}, "production", "auth.cookie.secure"},
{"secure string false in production", map[string]any{"auth.cookie.secure": "false"}, "Production", "auth.cookie.secure"},
{"secure inferred from http app.url in production", map[string]any{"app.url": "http://api.example.com"}, "production", "app.url"},
{"secure inferred from unset app.url in production", map[string]any{}, "production", "auth.cookie.secure resolves to false"},
{"secure not a bool", map[string]any{"auth.cookie.secure": "maybe"}, "", "auth.cookie.secure"},
{"secure wrong type", map[string]any{"auth.cookie.secure": 1}, "", "auth.cookie.secure"},
{"unknown same_site", map[string]any{"auth.cookie.same_site": "relaxed"}, "", "auth.cookie.same_site"},