Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Content Security Policy from report-only to enforceable #498

Merged
merged 1 commit into from Dec 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions liberapay/security/__init__.py
Expand Up @@ -30,17 +30,17 @@ def set_default_security_headers(website, response, request=None):
# https://scotthelme.co.uk/content-security-policy-an-introduction/
if b'content-security-policy' not in response.headers:
csp = (
b"default-src %(main_domain)s;"
b"script-src %(main_domain)s 'unsafe-inline';"
b"style-src %(main_domain)s 'unsafe-inline';"
b"default-src 'self' %(main_domain)s;"
b"script-src 'self' %(main_domain)s 'unsafe-inline';"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above this section of code suggests that we are using this CSP to prevent XSS, but by using 'unsafe-inline' you are doing precisely the opposite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not ready to drop 'unsafe-inline'. It's still better to have some protection than none at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Changaco, I agree, but is there a ticket addressing this concern somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now: #879.

b"style-src 'self' %(main_domain)s 'unsafe-inline';"
b"connect-src *;" # for credit card data
b"img-src *;"
b"reflected-xss block;"
) % {b'main_domain': website.canonical_host.encode('ascii')}
csp += website.env.csp_extra.encode()
if website.canonical_scheme == 'https':
csp += b"upgrade-insecure-requests;block-all-mixed-content;"
response.headers[b'content-security-policy-report-only'] = csp
csp += b"upgrade-insecure-requests;"
response.headers[b'content-security-policy'] = csp

# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
if b'X-XSS-Protection' not in response.headers:
Expand Down