mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-17 05:32:12 -05:00
Replace CRSF token with SameSite=strict #5290
Open
opened 2025-11-02 06:20:29 -06:00 by GiteaMirror
·
20 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1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rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/proposal
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#5290
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @silverwind on GitHub (Apr 23, 2020).
SameSite=stricteffectively prevents Cookie-based CRSF attacks and it also brings the benefit of simplifying our code. From Wikipedia:Browser support is pretty good on it. It also means cookies will never be send to other domains like when
STATIC_URL_PREFIXis set differently, but as far as I'm aware, cookies are not needed for static assets.Related: https://github.com/go-gitea/gitea/issues/5583
@silverwind commented on GitHub (Apr 23, 2020):
There is one concerning bit in the RFC draft which distinguishes a "registrable domain":
Unless I'm missing something, CRSF from
sub1.example.comtosub2.example.comwould still possible with that, thought I guess the risk is much lower in such a scenario.@lafriks commented on GitHub (Apr 23, 2020):
There is still problem if Gitea is hosted in subdir with other apps
@silverwind commented on GitHub (Apr 23, 2020):
@lafriks indeed, but I'd say that's a rare scenario and most of today's web's security relies on origins so they would be vulnerable to other attack vectors as well. Maybe we should just add a note that running on subdirectory is dangerous and should be avoided.
@guillep2k commented on GitHub (Apr 24, 2020):
I'd rather not rely on draft recommendations for security enforcement. Especially since older browsers will just not implement it.
@silverwind commented on GitHub (Apr 24, 2020):
I don't know why it's still draft but it's implemented since 4 years so it should be rather stable. Browsers are in process of enabling the lax setting for all sites (Chrome Status) which further reinforces the stability of that feature.
@CirnoT commented on GitHub (Apr 24, 2020):
There is a very limiting factor to
Strictcookies - if a link to Gitea issue or PR is provided on external site, clicking it will be seen as cross-site request and user will be logged out upon following it.Using
Laxwill ensure they are sent on cross-site request, but only for protocols deemed safe, so usuallyGETonly (note that this does include forms if their methods isGET)The subdomains are also an issue, imagine a situation where smaller company sets up web email and Gitea on two subdomains and user receives phishing email.
@mohe2015 commented on GitHub (Apr 24, 2020):
According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie subdomains don't get the cookies if no domain is set.
I think explicitly setting SameSite=Lax should be enough. According to https://web.dev/samesite-cookies-explained/: "The default behaviour applied by Chrome is slightly more permissive than an explicit SameSite=Lax as it will allow certain cookies to be sent on top-level POST requests"
@CirnoT commented on GitHub (Apr 24, 2020):
Laxis certainly a good idea to implement alone, but not as direct replacement for proper CSRF tokens as it still allows for misuse ofGETforms via cross-site requests and depends on user-agent support.@mohe2015 commented on GitHub (Apr 24, 2020):
According to https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html: "Do not use GET requests for state changing operations."
So I think these occurrences should be changed then.
Non state-changing should be fine AFAIK.
@silverwind commented on GitHub (Aug 1, 2020):
Pretty sure we have some non-semantic GETs which may block us to some degree here. One such example is https://github.com/go-gitea/gitea/issues/12403.
@DuckDuckWhale commented on GitHub (Dec 28, 2020):
#12403 and its original issue #10725 seems to be fixed. Any updates?
@silverwind commented on GitHub (Dec 28, 2020):
Some work had been done to get SameSite support into macaron but I'm not sure where it stands currently as there's also the migration to chi ongoing.
@lunny commented on GitHub (Feb 18, 2021):
9889eb38afhasn't been ported to Gitea based chi.@zeripath commented on GitHub (Mar 6, 2021):
#14900 will make all our cookies SameSite lax by default
@zeripath commented on GitHub (Mar 6, 2021):
I guess the next step would be then to add configuration to drop the csrf but leave it on unless a server admin wants it off.
@CirnoT commented on GitHub (Mar 7, 2021):
CSRF tokens should still be observed along with cookie configuration. Removal (or even adding option for it) of it would be a very premature action considering browsers are still not yet fully enforcing new cookie configuration in various edge scenarios as to not break the hell out of everything and we have to deal with multiple LTS releases such as Firefox ESR being used.
ref. https://medium.com/@renwa/bypass-samesite-cookies-default-to-lax-and-get-csrf-343ba09b9f2b
@mohe2015 commented on GitHub (Mar 7, 2021):
What about SameSite strict or a combination (lax for GET and both for POST as far as I can remember)?
@silverwind commented on GitHub (Mar 9, 2021):
CSRF removal would be nice to have to eliminate a few bugs we have around it. I'm not sure how those bugs exactly but there are ways CRSF tokens will be rejected by legimitate clients. I guess one way to reproduce may be to open form, restart server, send form. I guess it only is feasible once we enforce strict mode.
@jub0bs commented on GitHub (Jul 9, 2021):
I'm not part of the Gitea community, but I urge you not to rely solely on
SameSiteto the detriment of anti-CSRF tokens. TheSameSitecookie attribute is powerless against cross-origin, same-site attacks, and many orgs do not scrutinize the security level of their subdomains.@silverwind That section from Wikipedia that you quoted was incorrect and has since been corrected. It now reads:
(my emphasis)
@mohe2015 Whether the
Domainattribute was set or not in theSet-Cookieheader is irrelevant. Requests issued from same-site origins to the target origin will carry all relevant cookies associated with thatorigindomain.@mohe2015 commented on GitHub (Jul 9, 2021):
Great so now we have an RFC with a security feature that is not a security feature. Why is there no
SameOrigincookie-option...