Repository navigation
Only allow modifying patches through POST requests - #127
Merged
Merged
Conversation
Changing the status of a patch, closing or moving it, becoming reviewer or committer, and (un)subscribing were all done through plain links, i.e. GET requests. Crawlers follow all of those links on every patch page, and since they're not logged in each of them resulted in a redirect to the login page, generating a lot of useless load. It also meant that anyone could trick a logged in user into modifying a patch by getting them to click a link, since GET requests aren't protected against CSRF. These buttons are now forms that POST, with a CSRF token. A GET request to one of these URLs now redirects to the patch page without doing anything, also when not logged in, so crawlers that still have the old URLs don't end up at the login page. The staff-only `importUser` AJAX call, which creates a user, now also uses POST. Fixes #116
The previous commit added a custom `patch_modification` decorator that redirected GET requests to the patch page, instead of using Django's `require_POST`. The only reason for that was a logged out user clicking one of the new POST buttons: `login_required` would then send them to the login page with the action URL as `next`, and after logging in the browser would do a GET to that URL. Instead, logged out users now don't get these POST buttons at all. The patch command bar shows a "Log in to edit" button (next to the Review button) and the reviewers row shows "Log in to become reviewer", both of which log in and return to the patch page. That allows using the standard `require_POST`, which returns a 405 for GET requests before the login check, so crawlers with the old URLs still don't end up at the login page. This also restores the Review button that opens the review popup, which was accidentally replaced by the old Comment/Review dropdown when merging main.
Now that these views use Django's `require_POST` and `login_required` directly, this test was mostly testing Django's own behaviour. POST requests to the patch modification views are already exercised by `test_remove_reviewer.py`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changing the status of a patch, closing or moving it, becoming reviewer or committer, and (un)subscribing were all done through plain links, i.e. GET requests. Crawlers follow all of those links on every patch page, and since they're not logged in each of them resulted in a redirect to the login page, generating a lot of useless load. It also meant that anyone could trick a logged in user into modifying a patch by getting them to click a link, since GET requests aren't protected against CSRF.
These buttons are now forms that POST, with a CSRF token. A GET request to one of these URLs now redirects to the patch page without doing anything, also when not logged in, so crawlers that still have the old URLs don't end up at the login page. The staff-only
importUserAJAX call, which creates a user, now also uses POST.Fixes #116