-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Initial code parts for CSP implementation for sentry and self-hosted #47980
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #47980 +/- ##
=========================================
Coverage ? 76.26%
=========================================
Files ? 4775
Lines ? 201355
Branches ? 11515
=========================================
Hits ? 153568
Misses ? 47532
Partials ? 255
|
src/sentry/conf/server.py
Outdated
@@ -301,6 +301,7 @@ def env( | |||
# response modifying middleware reset the Content-Length header. | |||
# This is because CommonMiddleware Sets the Content-Length header for non-streaming responses. | |||
MIDDLEWARE = ( | |||
"csp.middleware.CSPMiddleware", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you done any testing on how this will interact with the CSP header middleware we have in getsentry? Having one way to do CSP in both would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am planning to swap custom implementation with django-csp in getsentry.
"'self'", | ||
] | ||
CSP_FRAME_ANCESTORS = [ | ||
"'none'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few integrations that need to frame sentry (jira).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a special case, implemented here with the new middleware:
11a5d72
Sanity check:
$ curl -si 'localhost:8000/extensions/jira/issue/ABC-123/' | grep -i content-security
content-security-policy-report-only: connect-src 'self' ws://127.0.0.1:8000; style-src 'self' 'unsafe-inline'; font-src 'self' data:; object-src 'none'; default-src 'none'; frame-ancestors 'self' http://localhost:8000; base-uri 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' blob: data: https://secure.gravatar.com
$ curl -si 'localhost:8000/extensions/jira/issue/ABC-123/?xdm_e=https%3A%2F%2Ftest.atlassian.net' | grep -i content-security
content-security-policy-report-only: connect-src 'self' ws://127.0.0.1:8000; style-src 'self' 'unsafe-inline'; font-src 'self' data:; object-src 'none'; default-src 'none'; frame-ancestors 'self' https://test.atlassian.net http://localhost:8000; base-uri 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' blob: data: https://secure.gravatar.com
"data:", | ||
] | ||
CSP_CONNECT_SRC = [ | ||
"'self'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll need some atlassian domains in here for the jira integrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was violation by connect-cdn.atl-paas.net
, added it to script-src:
34e1dfe
This view has to have a dynamic CSP (based on the xdm_e
parameter), so the standard approach with django-csp decorators does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The new middleware is default to off which will avoid disrupting saas.
PR reverted: d5c1595 |
…48507) Another attempt of #47980 (which was reverted due to bugs). This PR adds some preliminary code for adding a `Content-Security-Policy-Report-Only` header with minimal required permissions (at least I could not find any violations on `sentry devserver` and self-hosted). - The CSP middleware is disabled (commented in the `MIDDLEWARE`) - There is no report collecting enabled by default (`CSP_REPORT_URI` is not set), the intent is to customize it depending on the use case.
…48699) Another attempt of #47980 and #48507 (which were reverted due to bugs). This PR adds some preliminary code for adding a Content-Security-Policy-Report-Only header with minimal required permissions (at least I could not find any violations on sentry devserver and self-hosted). The CSP middleware is disabled (commented in the MIDDLEWARE) There is no report collecting enabled by default (CSP_REPORT_URI is not set), the intent is to customize it depending on the use case.
This PR was deployed then reverted. See #48507 for the new attempt.