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

Improve CSRF #908

Merged
merged 2 commits into from
Jan 26, 2024
Merged

Improve CSRF #908

merged 2 commits into from
Jan 26, 2024

Conversation

jwag956
Copy link
Collaborator

@jwag956 jwag956 commented Jan 25, 2024

Added testing to /tf-setup - there wasn't any CSRF issue - all working.

CSRF handling is complex and there are few unit tests.

  • Added @pytest.mark.csrf to make it easier to turn on and test CSRF w/o lots of boilerplate
  • Added tests and improved many templates to show CSRF errors - mostly for developers - but otherwise CSRF errors tent do just disappear and are difficult to debug
  • Found issue with WTFforms with the new form-level errors - it uses a None key - which, if there are multiple errors, isn't sortable by Flasks default JSON serializer. Filed issue and now change if from None to ""
  • Fixed issue in webauthn with CSRF errors causing exceptions - added tests.
  • In the case of CSRFprotect() (the app configuring CSRF for the entire app) a CSRF error would raise an exception which would always return an HTML response - added code to return a JSON response if desired.

closes #905

Copy link

codecov bot commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a2ae67c) 98.38% compared to head (0363354) 98.39%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #908   +/-   ##
=======================================
  Coverage   98.38%   98.39%           
=======================================
  Files          34       34           
  Lines        4465     4484   +19     
=======================================
+ Hits         4393     4412   +19     
  Misses         72       72           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Added testing to /tf-setup - there wasn't any CSRF issue - all working.

CSRF handling is complex and there are few unit tests.

- Added @pytest.mark.csrf to make it easier to turn on and test CSRF w/o lots of boilerplate
- Added tests and improved many templates to show CSRF errors - mostly for developers - but otherwise CSRF errors tent do just disappear and are difficult to debug
- Found issue with WTFforms with the new form-level errors - it uses a `None` key - which, if there are multiple errors, isn't sortable by Flasks default JSON serializer. Filed issue and now change if from `None` to ""
- Fixed issue in webauthn with CSRF errors causing exceptions - added tests.
- In the case of CSRFprotect() (the app configuring CSRF for the entire app) a CSRF error would raise an exception which would always return an HTML response - added code to return a JSON response if desired.

closes #905
Added testing to /tf-setup - there wasn't any CSRF issue - all working.

CSRF handling is complex and there are few unit tests.

- Added @pytest.mark.csrf to make it easier to turn on and test CSRF w/o lots of boilerplate
- Added tests and improved many templates to show CSRF errors - mostly for developers - but otherwise CSRF errors tent do just disappear and are difficult to debug
- Found issue with WTFforms with the new form-level errors - it uses a `None` key - which, if there are multiple errors, isn't sortable by Flasks default JSON serializer. Filed issue and now change if from `None` to ""
- Fixed issue in webauthn with CSRF errors causing exceptions - added tests.
- In the case of CSRFprotect() (the app configuring CSRF for the entire app) a CSRF error would raise an exception which would always return an HTML response - added code to return a JSON response if desired.
- Add more documentation...

closes #905
@jwag956 jwag956 merged commit 8ccd05e into master Jan 26, 2024
19 checks passed
@jwag956 jwag956 deleted the 905tfsetup branch January 26, 2024 18:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Verify that two-factor setup properly handles CSRF
1 participant