-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1259 from twm/style-nonce
Fix missing <style nonce> attrs
- Loading branch information
Showing
10 changed files
with
16 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright © 2013, 2015, 2016, 2017, 2018, 2020, 2022, 2023 Tom Most <[email protected]> | ||
# Copyright © 2013, 2015, 2016, 2017, 2018, 2020, 2022, 2023, 2025 Tom Most <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -303,20 +303,20 @@ def getChildWithDefault(self, name, request): | |
request.setHeader(b"X-Content-Type-Options", b"nosniff") | ||
request.setHeader(b"Cross-Origin-Opener-Policy", b"same-origin") | ||
|
||
script_nonce = b64encode(os.urandom(32)) | ||
request.requestHeaders.setRawHeaders(b"Yarrharr-Script-Nonce", [script_nonce]) | ||
csp_nonce = b64encode(os.urandom(32)) | ||
request.requestHeaders.setRawHeaders(b"Yarrharr-Csp-Nonce", [csp_nonce]) | ||
request.setHeader( | ||
b"Content-Security-Policy", | ||
( | ||
# b"default-src 'none'; " | ||
b"img-src *; " | ||
b"script-src 'self' 'nonce-%s'; " | ||
b"style-src 'self'; " | ||
b"style-src 'self' 'nonce-%s'; " | ||
b"frame-ancestors 'none'; " | ||
b"form-action 'self'; " | ||
b"report-uri /csp-report" | ||
) | ||
% (script_nonce,), | ||
% (csp_nonce, csp_nonce), | ||
) | ||
|
||
return super().getChildWithDefault(name, request) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright © 2022 Tom Most <[email protected]> | ||
# Copyright © 2022, 2025 Tom Most <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -29,13 +29,13 @@ def csp(request): | |
""" | ||
if settings.YARRHARR_SCRIPT_NONCE: | ||
try: | ||
nonce = request.headers["Yarrharr-Script-Nonce"] | ||
csp_nonce = request.headers["Yarrharr-Csp-Nonce"] | ||
except KeyError: | ||
if os.environ.get("YARRHARR_TESTING") == "yes": | ||
# Only ignore this in unit tests so we fail safe in production. | ||
nonce = None | ||
csp_nonce = None | ||
else: | ||
raise | ||
else: | ||
nonce = None | ||
return {"script_nonce": nonce} | ||
csp_nonce = None | ||
return {"csp_nonce": csp_nonce} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters