-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Ensure GetCSRF
doesn't return an empty token
#32130
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2cbc7d6
test: fix GetCSRF
wolfogre 74cf5a8
test: fix TestCreateAnonymousAttachment
wolfogre 3b07e1f
test: drop csrf token for GET requests
wolfogre 10b2d63
chore: use /explore/repos
wolfogre 9338b41
Revert "chore: use /explore/repos"
wolfogre 60b4259
chore: use different urls
wolfogre 58bc786
chore: improve createAttachment
wolfogre 4c4233d
fix lint
wxiaoguang 0bea254
Merge branch 'main' into bugfix/get_csrf
GiteaBot 7d4d180
Merge branch 'main' into bugfix/get_csrf
GiteaBot 58630f8
Merge branch 'main' into bugfix/get_csrf
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
I don't know if someone looking at this code in two months knows why an attachment test calls a login endpoint...
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 reads as this: when
TestCreateAnonymousAttachment
, it needs toGetCSRF
from/user/login
, it sounds reasonable.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.
If the CSRF token is not action related why can't we have a
GetCSRF
method without passed url? If/user/login
is a redirect call/user/settings
. One of both requests contains a 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.
It is user-related.
And I guess just no one has interest to work on #32130 (comment) , and no one has the explicitly said that "that FIXME could be removed and Gitea will always use a common CSRF token for current user"
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.
I think what @KN4CK3R wants to say is
we should document exactly that with a comment
…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.
I know it's user-related, that's the reason why there is the
session
.If we decide to use action-related CSRF tokens the
GetCSRF
method with an url must change too because then a single page can contain multiple forms with different tokens butdoc.GetCSRF()
currently just returns the first 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.
It would slow down many tests by using the extra request.
In most cases, the test writer clearly knows what CSRF token they would like to use: anonymous, or a signed-in user.
If you prefer to do so, I think it needs 2 functions:
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.
(while these improvements could be in a separate PR but not in this PR's scope)
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.
@KN4CK3R
a separate PR
-> Refactor CSRF token #32216