A modern approach to preventing CSRF in Go
AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.
Why it matters
Go 1.25's built-in http.CrossOriginProtection could replace fragile hidden-form-field CSRF tokens in web apps today.
A web security writer, Alex Edwards, examined a new tool added to the Go programming language in version 1.25, released in August. The tool blocks cross-site request forgery (CSRF), an attack where a malicious website makes a victim's browser submit forms to your site. Instead of the old workaround of hidden tokens in forms, it reads a browser-supplied header, Sec-Fetch-Site, that reveals where a submission came from. It works in about 94% of browsers, with a fallback for the rest.
Applications built with Go 1.25 (August) can now stop CSRF attacks without deploying token-based checks, cutting implementation and maintenance cost for web teams. The mechanism relies on the Sec-Fetch-Site browser header, available in 94.18% of browsers globally, so a fallback comparing Origin and Host headers covers the remainder, mainly iOS before version 17 and legacy browsers. Teams still need HSTS enabled, since the fallback cannot verify the connection scheme.
Go 1.25 ships http.CrossOriginProtection (src/net/http/csrf.go). Requests with Sec-Fetch-Site: same-origin or none pass; cross-site and same-site submissions are rejected, subdomains like tools.simonwillison.net and til.simonwillison.net count as same-site, not same-origin, and are blocked. If the header is absent (~5.8% of browsers), it falls back to comparing Origin with Host, which cannot check scheme, hence the HSTS recommendation. Filippo Valsorda's research article covers the underlying design; Firefox's Frederik Braun confirmed *.localhost is a secure context and does send Sec-Fetch-Site.
Read the original
This summary exists to save you time, not to replace the source.
Key terms
Go http.CrossOriginProtection Sec-Fetch-Site HSTS iOS 17 Bluesky
Was this summary useful?
One click, anonymous. It tells us which summaries to re-run.
Related reading
Code-driven AI illustrations are more useful than images from dedicated image models
Code-driven AI illustrations let designers edit assets directly in code, saving time on iteration and ensuring consistency, which is a game-changer for teams that need rapid, reusable visual content.
A hierarchical note-taking app for building large personal knowledge bases
Trilium lets users build and navigate massive personal knowledge bases without duplicating content, saving time on organization and retrieval.
Desktop apps in Go with native UI or web frontend
Go developers can now ship cross-platform desktop and mobile apps in a single small binary without cgo or heavy runtimes, cutting build complexity and deployment size.
OpenBitFun: an agent workspace with four harness modes and phone remote control
OpenBitFun lets agents run on any machine and be controlled from a phone, eliminating the need to choose between local power and remote access, saving developers time switching contexts.
Intel One Mono: a monospaced font designed with low-vision developers
Developers with low vision or eye fatigue can read code more clearly, reducing errors and improving productivity.