Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace CSRF cookie withCrossOriginProtection#36183

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
silverwind wants to merge19 commits intogo-gitea:main
base:main
Choose a base branch
Loading
fromsilverwind:nocsrf

Conversation

@silverwind
Copy link
Member

@silverwindsilverwind commentedDec 17, 2025
edited by wxiaoguang
Loading

Removes the CSRF cookie in favor ofCrossOriginProtection which relies purely on HTTP headers.

Fixes:#11188
Fixes:#30333
Helps:#35107

TODOs:

  • Fix tests
  • Ideally add tests to validates the protection

@GiteaBotGiteaBot added the lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelDec 17, 2025
@github-actionsgithub-actionsbot added modifies/goPull requests that update Go code modifies/templatesThis PR modifies the template files modifies/frontend labelsDec 17, 2025
@github-actionsgithub-actionsbot added the docs-update-neededThe document needs to be updated synchronously labelDec 17, 2025
@silverwindsilverwind changed the titleReplace csrf cookie with Go 1.25 CrossOriginProtectionReplace csrf cookie withCrossOriginProtectionDec 17, 2025
@silverwindsilverwind changed the titleReplace csrf cookie withCrossOriginProtectionReplace CSRF cookie withCrossOriginProtectionDec 17, 2025
@silverwindsilverwind marked this pull request as draftDecember 17, 2025 23:14
@silverwind
Copy link
MemberAuthor

silverwind commentedDec 17, 2025
edited
Loading

Test failures need investigation. I think I was quite thorough with this removal,rg csrf returns clean.

@silverwindsilverwind added the pr/breakingMerging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! labelDec 18, 2025
@silverwind
Copy link
MemberAuthor

silverwind commentedDec 18, 2025
edited
Loading

Unexpectedly, the fix in1eb058d worked to fix the last issue. I think there may be a underlying bug why this test is sensitive to aGET request, but as far as this PR is concerned, its ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe use a new test forCrossOriginProtection

Copy link
MemberAuthor

@silverwindsilverwindDec 18, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes I would still like to add a integration test that leveragesSec-Fetch-Site to validate this protection.

@wxiaoguang
Copy link
Contributor

wxiaoguang commentedDec 18, 2025
edited
Loading

⚠️ BREAKING⚠️

The_crsf cookie will no longer be set and is no longer necessary to be sent. GET requests that were used to retrieve it are no longer neccessary.

"breaking" usually means end users or site admins must do something, or experience something totally different.

But for this one, I think it isn't really "breaking". WDYT?


And, the TODOs are not necessary (or, we shouldn't "add additional trusted origins", there is no such use case)

@silverwind
Copy link
MemberAuthor

silverwind commentedDec 18, 2025
edited
Loading

And, the TODOs are not necessary (or, we shouldn't "add additional trusted origins", there is no such use case)

Yeah it's more of a "nice to have" thing. No known use case exists for adding more origins.

@silverwind
Copy link
MemberAuthor

TestOAuth2Provider/AuthorizeLoginRedirect still needs some fix it seems, it was passing earlier.

@wxiaoguang
Copy link
Contributor

wxiaoguang commentedDec 18, 2025
edited
Loading

TestOAuth2Provider/AuthorizeLoginRedirect still needs some fix it seems, it was passing earlier.

Because this review seems wrong#36183 (comment)

And I made a mistake for the middlewares, now onlyreqSignIn is used as the first commit.

@wxiaoguang
Copy link
Contributor

Fixes:#35107

I think this PR doesn't fix 35107. 35107 needs an API

@silverwind
Copy link
MemberAuthor

silverwind commentedDec 18, 2025
edited
Loading

I wonder if it's even necessary to disable COP on any endpoints. It's only active for browsers and if browser headers are not present, the protection will just allow the request which means any API client will be unaffected.

Requests without Sec-Fetch-Site or Origin headers are currently assumed to be either same-origin or non-browser requests, and are allowed.

@silverwind
Copy link
MemberAuthor

Fixes:#35107

I think this PR doesn't fix 35107. 35107 needs an API

It does fix the immediate issue, but I agree, what the autor really wants is a API to set up a mirror repo. Maybe we already have one?

@wxiaoguang
Copy link
Contributor

wxiaoguang commentedDec 18, 2025
edited
Loading

I wonder if it's even necessary to disable COP on any endpoints. It's only active for browsers and if browser headers are not present, the protection will just allow the request which means any API client will be unaffected.

I also consider that's unnecessary to disable CrossOriginProtection. So I think we can removeoptSignInAnyOrigin and only useoptSignIn

Not right, see below

@silverwind
Copy link
MemberAuthor

silverwind commentedDec 18, 2025
edited
Loading

Yeah I think we can go strict and have it enabled on all endpoints. If issues arise, we can think about solutions.

@silverwind
Copy link
MemberAuthor

Done inda28335, now it's always enabled unconditionally.

@wxiaoguang
Copy link
Contributor

Done inda28335, now it's always enabled unconditionally.

Wait, it will cause problems with CORS, according to AI:

If your server implements a policy that rejects Sec-Fetch-Site: cross-site for certain endpoints, the server can block it (e.g., respond 403) even if CORS would otherwise allow it.

So we still need to disable CrossOriginProtection for the CORS endpoints.

image

@silverwind
Copy link
MemberAuthor

For the record, if there are issues, COP offers 2 ways to disable it conditionally:

Both could be made configurable, if needed.

@wxiaoguangwxiaoguang marked this pull request as draftDecember 18, 2025 11:12
@silverwind
Copy link
MemberAuthor

So we still need to disable CrossOriginProtection for the CORS endpoints.

I'm not sure but yes sounds plausible that CORS is an exception.

@silverwind
Copy link
MemberAuthor

I've re-addedoptSignInAnyOrigin and added it anywhere whereoptionsCorsHandler is active. Maybe the option could also be combined intooptionsCorsHandler but I have no idea how to do that.

@silverwind
Copy link
MemberAuthor

I think combining these two options is still not good because those route groups also match on non-CORS requests but we probably only want to disable the protection when the request was identified as CORS, e.g. whencorsHandler is non-nil inside theoptionsCorsHandler callback.

@wxiaoguangwxiaoguang dismissed theirstale reviewDecember 18, 2025 11:23

Leave for a while. The current logic isn't right.

@GiteaBotGiteaBot added lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1This PR needs approval from one additional maintainer to be merged. labelsDec 18, 2025
@silverwind
Copy link
MemberAuthor

I think the cors handler could indicate in the request context that it had a match with a boolean flag, and then the COP handler could act on that flag and be disabled.

@silverwind
Copy link
MemberAuthor

silverwind commentedDec 18, 2025
edited
Loading

I'm not sure your AI answer is right. Go's protection relies onSec-Fetch-Site orOrigin headers and I think one, if not both headers will be present on CORS request, at least for the unsafe methods. There is even aSec-Fetch-Mode: cors, which further reinforces my assumption.

So I'd lean towards having all endpoints protected, without exception. Restrictions can be relaxed later if issues are demonstrated. I will push again the full strict settings.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lunnylunnylunny left review comments

@wxiaoguangwxiaoguangwxiaoguang left review comments

Assignees

No one assigned

Labels

docs-update-neededThe document needs to be updated synchronouslylgtm/need 2This PR needs two approvals by maintainers to be considered for merging.modifies/frontendmodifies/goPull requests that update Go codemodifies/templatesThis PR modifies the template filestype/refactoringExisting code has been cleaned up. There should be no new functionality.

Projects

None yet

Milestone

No milestone

4 participants

@silverwind@wxiaoguang@lunny@GiteaBot

[8]ページ先頭

©2009-2025 Movatter.jp