-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
chore: Enable CSP by default #24262
chore: Enable CSP by default #24262
Changes from 6 commits
d049b27
bb6511a
f4fb6dc
ce51a8a
8a7f720
ba3b963
37698f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1363,13 +1363,43 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument | |
CONTENT_SECURITY_POLICY_WARNING = True | ||
|
||
# Do you want Talisman enabled? | ||
TALISMAN_ENABLED = False | ||
TALISMAN_ENABLED = True | ||
# If you want Talisman, how do you want it configured?? | ||
TALISMAN_CONFIG = { | ||
"content_security_policy": None, | ||
"force_https": True, | ||
"content_security_policy": { | ||
"default-src": ["'self'"], | ||
"img-src": ["'self'", "data:"], | ||
"worker-src": ["'self'", "blob:"], | ||
"connect-src": [ | ||
"'self'", | ||
"https://api.mapbox.com", | ||
"https://events.mapbox.com", | ||
], | ||
"object-src": "'none'", | ||
"style-src": ["'self'", "'unsafe-inline'"], | ||
"script-src": ["'self'", "'strict-dynamic'"], | ||
}, | ||
"content_security_policy_nonce_in": ["script-src"], | ||
"force_https": False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kgabryje curious why this force_https change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to limit the scope of the changes in this PR just to CSP - and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with keeping this disabled by default - I would wager that by far the majority of prod Superset deployments terminate SSL/TLS on the LB. |
||
"force_https_permanent": False, | ||
} | ||
# React requires `eval` to work correctly in dev mode | ||
TALISMAN_DEV_CONFIG = { | ||
"content_security_policy": { | ||
"default-src": ["'self'"], | ||
"img-src": ["'self'", "data:"], | ||
"worker-src": ["'self'", "blob:"], | ||
"connect-src": [ | ||
"'self'", | ||
"https://api.mapbox.com", | ||
"https://events.mapbox.com", | ||
], | ||
"object-src": "'none'", | ||
"style-src": ["'self'", "'unsafe-inline'"], | ||
"script-src": ["'self'", "'unsafe-inline'", "'unsafe-eval'"], | ||
}, | ||
"content_security_policy_nonce_in": ["script-src"], | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup nice catch! |
||
|
||
# | ||
# Flask session cookie options | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -613,7 +613,11 @@ def __call__( | |
|
||
# Talisman | ||
talisman_enabled = self.config["TALISMAN_ENABLED"] | ||
talisman_config = self.config["TALISMAN_CONFIG"] | ||
talisman_config = ( | ||
self.config["TALISMAN_DEV_CONFIG"] | ||
if self.superset_app.debug | ||
else self.config["TALISMAN_CONFIG"] | ||
) | ||
Comment on lines
+616
to
+620
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if it's a good idea to have separate dev and non-dev configs. Should these maybe be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must have "unsafe-eval" in dev mode - React and Webpack use it and there's no way around it |
||
csp_warning = self.config["CONTENT_SECURITY_POLICY_WARNING"] | ||
|
||
if talisman_enabled: | ||
|
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.
Calling
new Function()
breaks the CSP rule that disallows usingeval
in scripts.Extending
Function
is a nice hack that let's us make a class instance (in most cases it's a formatter) callable - for example instead of callingformatter.format(value)
we callformatter(value)
. Removingsuper()
does not break that behaviour while also letting us avoid calling Function constructor.