|
59 | 59 | "referrer-policy": "strict-origin-when-cross-origin", |
60 | 60 | "x-xss-protection": "0", |
61 | 61 | "permissions-policy": "camera=(), microphone=(), geolocation=()", |
| 62 | + "cross-origin-opener-policy": "same-origin-allow-popups", |
62 | 63 | } |
63 | 64 | HSTS = "31536000" |
64 | 65 |
|
@@ -92,7 +93,8 @@ def _app(monkeypatch): |
92 | 93 | Router.clear() |
93 | 94 | Middleware.reset() |
94 | 95 | for name in ("TINA4_HSTS", "TINA4_CSP", "TINA4_FRAME_OPTIONS", |
95 | | - "TINA4_REFERRER_POLICY", "TINA4_PERMISSIONS_POLICY", "TINA4_CSRF"): |
| 96 | + "TINA4_REFERRER_POLICY", "TINA4_PERMISSIONS_POLICY", "TINA4_CSRF", |
| 97 | + "TINA4_COOP"): |
96 | 98 | monkeypatch.delenv(name, raising=False) |
97 | 99 |
|
98 | 100 | @route_get("/sec-probe") |
@@ -160,6 +162,20 @@ def test_each_response_gets_a_fresh_csp_nonce(): |
160 | 162 | assert n1 != n2, f"nonce was reused across responses: {n1}" |
161 | 163 |
|
162 | 164 |
|
| 165 | +def test_coop_defaults_to_same_origin_allow_popups(): |
| 166 | + """COOP defaults to same-origin-allow-popups — it isolates the page from |
| 167 | + whoever opened it while leaving popups the page opens (OAuth/payment) able to |
| 168 | + post back to their opener. Full isolation (same-origin) is opt-in.""" |
| 169 | + assert _header(_request(), "cross-origin-opener-policy") == "same-origin-allow-popups" |
| 170 | + |
| 171 | + |
| 172 | +def test_tina4_coop_overrides_the_cross_origin_opener_policy(monkeypatch): |
| 173 | + """TINA4_COOP replaces the default — same-origin for full isolation, or |
| 174 | + unsafe-none to opt out.""" |
| 175 | + monkeypatch.setenv("TINA4_COOP", "same-origin") |
| 176 | + assert _header(_request(), "cross-origin-opener-policy") == "same-origin" |
| 177 | + |
| 178 | + |
163 | 179 | # ------------------------------------------------------------ HSTS HTTPS-guarded |
164 | 180 |
|
165 | 181 | def test_hsts_is_present_on_an_https_request(monkeypatch): |
|
0 commit comments