News for hackers. Stuff that matters.
Re:A modern approach to preventing CSRF in Go by ale on Wednesday October 15, 2025 @01:47AM (#45588472)
Are CSRF attacks that common nowadays though? Even if your app is used by the 5% of browsers that don’t set the Origin header the chances of that being exploited are even more miniscule. Besides, most webdevs reach for token-based auth libraries before even knowing how to set a cookie header.
Re:A modern approach to preventing CSRF in Go by zwnow on Wednesday October 15, 2025 @03:28AM (#45589148)
Also cant you just spoof the origin header?
Re:A modern approach to preventing CSRF in Go by kevinyew on Wednesday October 15, 2025 @03:32AM (#45589187)
You can if you want to deliberately CORF yourself for some reason - it's there to protect you, but spoofing it doesn't give you any special access you wouldn't otherwise have.

The point is that arbitrary user's browsers out in the world won't spoof the Origin header, which is protecting them from CORF attacks.

Re:A modern approach to preventing CSRF in Go by masklinn on Wednesday October 15, 2025 @04:34AM (#45589629)
A CSRF is an attack against a logged in user, so has to be mediated via their browser.

If you can spoof the origin header of a second party when they navigate to a third party, a CSRF is a complete waste of whatever vulnerability you have found.

Re:A modern approach to preventing CSRF in Go by monster_truck on Wednesday October 15, 2025 @01:59AM (#45588551)
Yes
Re:A modern approach to preventing CSRF in Go by littlecranky67 on Wednesday October 15, 2025 @05:10AM (#45589851)
Curious about that too. In a modern web-app I always set HttpOnly cookies to prevent them being exposed to anything JavaScript, and SameSite=strict. Especially the later should prevent CSRF.
Re:A modern approach to preventing CSRF in Go by jeremyscanvic on Wednesday October 15, 2025 @05:50AM (#45590105)
Erratum: What I'm saying here only applies for cookies with the attribute SameSite=None so it's irrelevant here, see the comments below.

(Former CTF hobbyist here) You might be mixing up XSS and CSRF protections. Cookie protections are useful against XSS vulnerabilities because they make it harder for attackers to get a hold on user sessions (often mediated through cookies). It doesn't really help against CSRF attacks though. Say you visit attacker.com and it contains an auto-submitting form making a POST request to yourwebsite.com/delete-my-account. In that case, your cookies would be sent along and if no CSRF protection is there (origin checks, tokens, ...) your account might end up deleted. I know it doesn't answer the original question but hope it's useful information nonetheless!

Re:A modern approach to preventing CSRF in Go by RagingCactus on Wednesday October 15, 2025 @06:05AM (#45590206)
The SameSite cookie flag is effective against CSRF when you put it on your session cookie, it's one of its main use cases. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/... for more information.

SameSite=Lax (default for legacy sites in Chrome) will protect you against POST-based CSRF.

SameSite=Strict will also protect against GET-based CSRF (which shouldn't really exist as GET is not a safe method that should be allowed to trigger state changes, but in practice some applications do it). It does, however, also make it so users clicking a link to your page might not be logged in once they arrive unless you implement other measures.

In practice, SameSite=Lax is appropriate and just works for most sites. A notable exception are POST-based SAML SSO flows, which might require a SameSite=None cookie just for the login flow.

Re:A modern approach to preventing CSRF in Go by hmry on Wednesday October 15, 2025 @06:24AM (#45590336)
This page has some more information about the drawbacks/weaknesses of SameSite, worth a read: https://developer.mozilla.org/en-US/docs/Web/Security/Attack...

You usually need another method as well

Re:A modern approach to preventing CSRF in Go by RagingCactus on Wednesday October 15, 2025 @06:33AM (#45590389)
Yes, you're definitely right that there are edge cases and I was simplifying a bit. Notably, it's called SameSite, NOT SameOrigin. Depending on your application that might matter a lot.

In practice, SameSite=Lax is already very effective in preventing _most_ CSRF attacks. However, I 100% agree with you that adding a second defense mechanism (such as the Sec header, a custom "Protect-Me-From-Csrf: true" header, or if you have a really sensitive use case, cryptographically secure CSRF tokens) is a very good idea.

Re:A modern approach to preventing CSRF in Go by jeremyscanvic on Wednesday October 15, 2025 @06:16AM (#45590282)
Thanks for correcting me - I see my web sec knowledge is getting rusty!