datasette PR #2689: Replace token-based CSRF with Sec-Fetch-Site header protection
Summary
Datasette has replaced its token-based Cross-Site Request Forgery (CSRF) protection with a new system leveraging the `Sec-Fetch-Site` header, inspired by Filippo Valsorda's research and its implementation in Go 1.25. This change, documented in Datasette PR #2689, eliminates the need for CSRF tokens and the associated `` lines in templates, simplifying development. The update also removes the `skip_csrf` plugin hook and its related documentation and tests. The new approach is detailed in Datasette's updated CSRF protection documentation and its upgrade guide, with much of the implementation work attributed to Claude Code and cross-reviewed by GPT-5.4.
Key takeaway
For engineering teams building web applications, adopting `Sec-Fetch-Site` header-based CSRF protection, as demonstrated by Datasette and Go 1.25, can significantly streamline development by removing token management overhead. You should evaluate migrating from traditional CSRF tokens to this header-based approach to simplify your codebase and enhance security posture.
Key insights
Modern CSRF protection can effectively use the `Sec-Fetch-Site` header, simplifying web application security.
Principles
- Header-based CSRF protection reduces template complexity.
- External research can inform core security feature updates.
Method
Implement CSRF protection by validating the `Sec-Fetch-Site` header, removing token-based mechanisms, and updating related templates and plugin hooks.
In practice
- Review `Sec-Fetch-Site` header for CSRF defense.
- Eliminate CSRF tokens from forms and APIs.
- Simplify template rendering by removing hidden fields.
Topics
- CSRF Protection
- Sec-Fetch-Site Header
- Datasette
- Go 1.25
- Web Security
Code references
Best for: CTO, VP of Engineering/Data, Software Engineer, AI Security Engineer, AI Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Simon Willison's Weblog.