pre-commit-ci-lite[bot]
3 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
4 additions and
8 deletions
-
fastapi/middleware/security_headers.py
-
tests/test_security_headers_middleware.py
|
|
@ -40,8 +40,8 @@ class SecurityHeadersMiddleware: |
|
|
cross_origin_opener_policy.encode("latin-1") |
|
|
cross_origin_opener_policy.encode("latin-1") |
|
|
) |
|
|
) |
|
|
if content_security_policy is not None: |
|
|
if content_security_policy is not None: |
|
|
self._headers[b"content-security-policy"] = ( |
|
|
self._headers[b"content-security-policy"] = content_security_policy.encode( |
|
|
content_security_policy.encode("latin-1") |
|
|
"latin-1" |
|
|
) |
|
|
) |
|
|
if permissions_policy is not None: |
|
|
if permissions_policy is not None: |
|
|
self._headers[b"permissions-policy"] = permissions_policy.encode("latin-1") |
|
|
self._headers[b"permissions-policy"] = permissions_policy.encode("latin-1") |
|
|
|
|
|
@ -191,9 +191,7 @@ def test_cache_control(): |
|
|
return {"message": "hi"} |
|
|
return {"message": "hi"} |
|
|
|
|
|
|
|
|
response = client2.get("/") |
|
|
response = client2.get("/") |
|
|
assert ( |
|
|
assert response.headers["cache-control"] == "no-store, no-cache, must-revalidate" |
|
|
response.headers["cache-control"] == "no-store, no-cache, must-revalidate" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_custom_x_frame_options(): |
|
|
def test_custom_x_frame_options(): |
|
|
@ -235,9 +233,7 @@ def test_custom_cross_origin_opener_policy(): |
|
|
return {"message": "hi"} |
|
|
return {"message": "hi"} |
|
|
|
|
|
|
|
|
response = client2.get("/") |
|
|
response = client2.get("/") |
|
|
assert ( |
|
|
assert response.headers["cross-origin-opener-policy"] == "same-origin-allow-popups" |
|
|
response.headers["cross-origin-opener-policy"] == "same-origin-allow-popups" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_websocket_not_affected(): |
|
|
def test_websocket_not_affected(): |
|
|
|