Replace CSRF cookie with CrossOriginProtection (#36183)
Removes the CSRF cookie in favor of [`CrossOriginProtection`](https://pkg.go.dev/net/http#CrossOriginProtection) which relies purely on HTTP headers. Fixes: https://github.com/go-gitea/gitea/issues/11188 Fixes: https://github.com/go-gitea/gitea/issues/30333 Helps: https://github.com/go-gitea/gitea/issues/35107 TODOs: - [x] Fix tests - [ ] Ideally add tests to validates the protection --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -49,7 +49,6 @@ func TestRepoMergeUpstream(t *testing.T) {
|
||||
|
||||
// create fork-branch
|
||||
req = NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/test-repo-fork/branches/_new/branch/master", forkUser.Name), map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, session),
|
||||
"new_branch_name": "fork-branch",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
@@ -81,7 +80,6 @@ func TestRepoMergeUpstream(t *testing.T) {
|
||||
t.Run("DetectSameBranch", func(t *testing.T) {
|
||||
// if the fork-branch name also exists in the base repo, then use that branch instead
|
||||
req = NewRequestWithValues(t, "POST", "/user2/repo1/branches/_new/branch/master", map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, sessionBaseUser),
|
||||
"new_branch_name": "fork-branch",
|
||||
})
|
||||
sessionBaseUser.MakeRequest(t, req, http.StatusSeeOther)
|
||||
@@ -99,14 +97,12 @@ func TestRepoMergeUpstream(t *testing.T) {
|
||||
})
|
||||
|
||||
// click the "sync fork" button
|
||||
req = NewRequestWithValues(t, "POST", mergeUpstreamLink, map[string]string{"_csrf": GetUserCSRFToken(t, session)})
|
||||
req = NewRequest(t, "POST", mergeUpstreamLink)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
checkFileContent("fork-branch", "test-content-1")
|
||||
|
||||
// delete the "fork-branch" from the base repo
|
||||
req = NewRequestWithValues(t, "POST", "/user2/repo1/branches/delete?name=fork-branch", map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, sessionBaseUser),
|
||||
})
|
||||
req = NewRequest(t, "POST", "/user2/repo1/branches/delete?name=fork-branch")
|
||||
sessionBaseUser.MakeRequest(t, req, http.StatusOK)
|
||||
})
|
||||
|
||||
@@ -151,7 +147,6 @@ func TestRepoMergeUpstream(t *testing.T) {
|
||||
t.Run("FastForwardOnly", func(t *testing.T) {
|
||||
// Create a clean branch for fast-forward testing
|
||||
req = NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/test-repo-fork/branches/_new/branch/master", forkUser.Name), map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, session),
|
||||
"new_branch_name": "ff-test-branch",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
Reference in New Issue
Block a user