Add global CSRF token handlers for all jQuery AJAX and HTMX POST requests#3783
Add global CSRF token handlers for all jQuery AJAX and HTMX POST requests#3783lunkwill42 merged 3 commits intomasterfrom
Conversation
Test results 20 files 20 suites 25m 35s ⏱️ Results for commit 56d4a96. ♻️ This comment has been updated with latest results. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3783 +/- ##
==========================================
- Coverage 63.33% 63.32% -0.01%
==========================================
Files 619 619
Lines 45873 45873
Branches 43 43
==========================================
- Hits 29053 29051 -2
- Misses 16810 16812 +2
Partials 10 10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Claude was fairly correct in the suggested changes, but instead of re-using I have added two fixup commits:
These changes eliminate code duplication by using a single shared implementation in |
|
I merged in #3396 locally, and verified that the following smoke test locations worked (and included a CSRF token header):
|
lunkwill42
left a comment
There was a problem hiding this comment.
Looks good to me, @Simrayz - I approve (though I cannot approve through GH, since I authored the PR 😆 )
ced50bb to
fa6e3c2
Compare
|
Squashed the fixups, but now there's some unrelated GitHub Actions problems that wasn't there before 😝 |
Co-authored-by: Simen Abelsen <simen.abelsen@sikt.no>
Co-authored-by: Simen Abelsen <simen.abelsen@sikt.no>
fa6e3c2 to
56d4a96
Compare
|
rebaed on the latest master, which fixes the github issue |
|



Scope and purpose
I tested #3396 once more. While we remain pretty confident all Django/Python forms now provide CSRF tokens in a correct manner, the same cannot be said for various JS code that runs POST requests against the backend.
I kindly asked Claude to analyze the code base and find potential issues. It found a lot, and I sampled some of them and confirmed them to have issues when #3396 applied.
The fix Claude suggested (again) was to simply add a global handler for HTMX requests, and a similar handler for jQuery AJAX requests.
This PR provides both those solutions, and I hope @Simrayz can do a proper evaluation (I guess we should potentially add some tests as well)
The Claude analysis conclusion
Claude purported to find these issues with the codebase:
Contributor Checklist
Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.
Added/changed documentation<major>.<minor>.x). For a new feature or other additions, it should be based onmaster.If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be doneIf it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)If this results in changes in the UI: Added screenshots of the before and afterIf this adds a new Python source code file: Added the boilerplate header to that file