Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Security: allow the Unsplash background image in the CSP (CFG-07b)

Omega (QA)ed899a69fa35
diff --git a/backend/__init__.py b/backend/__init__.py
index f410f67..20f5946 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -175,15 +175,16 @@ def ensure_owner_exists():
# styles throughout, so script-src and style-src keep 'unsafe-inline';
# the policy still pins the fetchable origins, blocks plugins and
# foreign framing, and keeps form submissions and base URIs
-# same-origin. The two third-party allowances are load-bearing: the
-# About page loads the Buy Me a Coffee button script, which fetches
-# its font and images from the buymeacoffee and Google Fonts hosts,
-# and version-checker.js fetches the latest release from api.github.com.
+# same-origin. The third-party allowances are load-bearing: the About
+# page loads the Buy Me a Coffee button script, which fetches its
+# font and images from the buymeacoffee and Google Fonts hosts,
+# version-checker.js fetches the latest release from api.github.com,
+# and style.css uses an Unsplash photo as a page background.
_CONTENT_SECURITY_POLICY = (
"default-src 'self'; "
"script-src 'self' 'unsafe-inline' https://cdnjs.buymeacoffee.com; "
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; "
- "img-src 'self' data: blob: https://*.buymeacoffee.com; "
+ "img-src 'self' data: blob: https://*.buymeacoffee.com https://images.unsplash.com; "
"font-src 'self' data: https://fonts.gstatic.com; "
"connect-src 'self' https://api.github.com; "
"frame-src 'self' https://*.buymeacoffee.com; "
diff --git a/nginx.conf b/nginx.conf
index 5d59e24..56c746f 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -13,7 +13,7 @@ server {
# Locations below that define their own add_header directives do
# not inherit these, so the HTML location repeats them.
add_header X-Frame-Options "SAMEORIGIN" always;
- add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.buymeacoffee.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.buymeacoffee.com; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.github.com; frame-src 'self' https://*.buymeacoffee.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests" always;
+ add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.buymeacoffee.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.buymeacoffee.com https://images.unsplash.com; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.github.com; frame-src 'self' https://*.buymeacoffee.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Suppress the nginx version number in error pages and the Server
@@ -130,7 +130,7 @@ server {
# Repeated: locations with their own add_header do not inherit
# the server-level security headers (CFG-07a/b/d).
add_header X-Frame-Options "SAMEORIGIN" always;
- add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.buymeacoffee.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.buymeacoffee.com; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.github.com; frame-src 'self' https://*.buymeacoffee.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests" always;
+ add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.buymeacoffee.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.buymeacoffee.com https://images.unsplash.com; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self' https://api.github.com; frame-src 'self' https://*.buymeacoffee.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
}
diff --git a/tests/test_security_headers.py b/tests/test_security_headers.py
index c2e38d2..c48512d 100644
--- a/tests/test_security_headers.py
+++ b/tests/test_security_headers.py
@@ -52,6 +52,7 @@ def test_csp_allows_the_about_page_widget_and_version_check():
assert "https://cdnjs.buymeacoffee.com" in _CONTENT_SECURITY_POLICY
assert "https://*.buymeacoffee.com" in _CONTENT_SECURITY_POLICY
assert "https://api.github.com" in _CONTENT_SECURITY_POLICY
+ assert "https://images.unsplash.com" in _CONTENT_SECURITY_POLICY
def test_csp_blocks_plugins_and_foreign_framing():