datasette PR #2689: Replace token-based CSRF with Sec-Fetch-Site header protection

· Source: Simon Willison's Weblog · Field: Technology & Digital — Software Development & Engineering, Cybersecurity & Data Privacy, Artificial Intelligence & Machine Learning · Depth: Advanced, quick

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

Method

Implement CSRF protection by validating the `Sec-Fetch-Site` header, removing token-based mechanisms, and updating related templates and plugin hooks.

In practice

Topics

Code references

Best for: CTO, VP of Engineering/Data, Software Engineer, AI Security Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Simon Willison's Weblog.