-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add support for CSRF tokens #5055
Conversation
Co-authored-by: Restyled.io <commits@restyled.io>
client/app/services/axios.js
Outdated
@@ -14,6 +15,8 @@ axios.interceptors.request.use(config => { | |||
const apiKey = Auth.getApiKey(); | |||
if (apiKey) { | |||
config.headers.Authorization = `Key ${apiKey}`; | |||
} else { | |||
config.headers.common["X-CSRF-TOKEN"] = Cookies.get("csrf_token"); |
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.
We should probably:
- Encapsulate the logic to get the CSRF token, so we can replace it.
- Not set anything if no
csrf_token
available?
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.
flask_wtf
handles the generation and verifications. I'm not sure it can be replaced (nor should it be?)- 8babdd0
@@ -20,6 +20,8 @@ | |||
# Make sure rate limit is enabled | |||
os.environ["REDASH_RATELIMIT_ENABLED"] = "true" | |||
|
|||
os.environ["REDASH_ENFORCE_CSRF"] = "false" |
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.
Don't we want to have some tests with CSRF? Or it's covered by Cypress?
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.
It felt like a behaviour that should be evaluated in an E2E perspective, so Cypress does the trick.
@@ -15,6 +15,7 @@ x-redash-environment: &redash-environment | |||
REDASH_RATELIMIT_ENABLED: "false" | |||
REDASH_MAIL_DEFAULT_SENDER: "redash@example.com" | |||
REDASH_MAIL_SERVER: "email" | |||
REDASH_ENFORCE_CSRF: "true" |
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.
Don't you need to do the same in Cypress' docker-compose?
I thought the Cypress failure is temporary so triggered another build, but it failed in the same way. Maybe somehow related to the changes? |
* add flask-wtf * add CSRF tokens to all static forms * add CSRF tokens to all axios requests * disable CSRF validation in unit tests * support CSRF-protected requests in *most* cypress tests * don't enfroce CSRF checks by default * avoid CSRF enforcement in unit tests * remove redundant spread * some camel casing hiccups * always yield the CSRF cookie, but avoid enforcing it if CSRF toggle is off * Restyled by prettier (getredash#5056) Co-authored-by: Restyled.io <commits@restyled.io> * set a CSRF header only if cookie is present * enforce CSRF in CI * install lodash directly for Cypress * install request-cookies directly for Cypress. We should probably start loading package.json deps * enable CSRF support when logout and login happen within the same spec Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
What type of PR is this? (check all applicable)
Description
This PR adds CSRF protection for all forms and API calls. CSRF protection is turned off by default and can be turned on in
settings.ENFORCE_CSRF
.If CSRF enforcement is turned on, it will protect:
It does not apply to requests authenticated using an api key.