-
Notifications
You must be signed in to change notification settings - Fork 6
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
CSRF not on some POST forms. #28
Comments
I may be going down the wrong rabbit hole but it seems that This led me down to seeing why it was trying to treat it like a pylons request vs. flask as some of these have been migrated. I think when you make a call to the dataset edit page,
so the if statement evaluates to True but the actual value is an error. In the user profile edit page, the if statement evaluates to But, this may be the wrong rabbit-hole I've went down. |
This diff will get the token added to all POST forms by going up to But,
This also does not fix the
|
Thanks for looking into this. I may not be able to do much on it over the next few days, but I'll keep it on our radar. There should be time to work on it before Christmas. |
The |
FYI, I've got a hacked together version that kind of works now. I'll try to clean it up and share what I've done as a work in progress over the next few days. |
After digging into it and trying numerous different things I ended up creating a Flask based CSRF and using this CSRF for Pylons based requests. Then in the future I can just remove the Pylons based on once CKAN has fully migrated to Flask. I modified the ckanext-security CSRF implementation to handle flask, and using this CSRF implementation for Pylons (this one didn't require anything else and was a little simpler to setup I found). Some issues I ran into and general info:
|
hopefully tomorrow I can share what i have in a easily reproducible way. It's now been tested and held up which is a bonus. |
Alright, I wasn't sure how best to capture the changes and explain my approach so I put it in a post over here. I didn't want to try and do a PR against this repo as it may not be a fix you'd like to implement, or you may want to go a different direction. Basics:
|
Thanks, @boykoc ! We're definitely interested in this, and I'll assemble a pull request soon. Can you advise the simplest way to reproduce the problem, so that our testing team can be sure when it's resolved? |
Curious your timeline on upgrading to python 3 and ckan 2.9? Looks like pylons will finally be removed in PR #5712 and CSRF can be done just on Flask side. Super late reply on your question for simplest way to reproduce:
From my review and testing it seemed pylons controlled pages were protected by your or ckanext-security implementation. But Anything that had been migrated to flask was not; request "hooks" are different in these frameworks. My implementation described in the above link to the post has lots of extra stuff I know. I didn't want to hack apart what you all had done but that meant some unused pieces were left lying around. |
@boykoc I think I have a better handle on this now. You're right; the current implementation wouldn't protect anything implemented as a Flask blueprint, and I can see that the user edit page has no form token. I'm looking through the code in your blog post now, with a view to updating this. I'll offer the changes to ckanext-security when I'm done. |
@ThrawnCA Continuation of previous issue. I originally tried to implement CSRF protection from the ckanext-security extension but with various issues (likely my "user error") ended up jumping to this implementation so I'm moving the conversation here.
Potential Issue:
Token is not added to all post forms. Specifically, I've found that the token doesn't get added to the user edit form (user profile). Can you confirm this on your installation by chance? If it works there, it's something I've done.
So far I've found
intercept_csrf()
is successfully called when loading the user edit form but it appears that line 61 (anti_csrf_render_jinja2
) is not called. But when loading another form (e.g. the dataset edit form) it is called as expected. This happens beforeapply_token()
is called, which is where I suspected the issue to be at first.update:
The text was updated successfully, but these errors were encountered: