Datasette PR #2689:用Sec-Fetch-Site头部替代基于令牌的CSRF保护datasette PR #2689: Replace token-based CSRF with Sec-Fetch-Site header protection
Datasette项目计划弃用传统的CSRF令牌机制,转而采用更简洁的Sec-Fetch-Site HTTP头部进行同源策略验证。此举旨在简化模板代码,消除在每个表单中手动插入csrftoken隐藏字段的需求,同时利用浏览器内置的安全机制提升兼容性与可维护性。
Simon Willison
14th April 2026 - Link Blog
datasette PR #2689: Replace token-based CSRF with Sec-Fetch-Site header protection. Datasette has long protected against CSRF attacks using CSRF tokens, implemented using my asgi-csrf Python library. These are something of a pain to work with - you need to scatter forms in templates with <input type="hidden" name="csrftoken" value="{{ csrftoken() }}"> lines and then selectively disable CSRF protection for APIs that are intended to be called from outside the browser.
I've been following Filippo Valsorda's research here with interest, described in this detailed essay from August 2025 and shipped as part of Go 1.25 that same month.
I've now landed the same change in Datasette. Here's the PR description - Claude Code did much of the work (across 10 commits, closely guided by me and cross-reviewed by GPT-5.4) but I've decided to start writing these PR descriptions by hand, partly to make them more concise and also as an exercise in keeping myself honest.
New CSRF protection middleware inspired by Go 1.25 and this research by Filippo Valsorda. This replaces the old CSRF token based protection. Removes all instances of <input type="hidden" name="csrftoken" value="{{ csrftoken() }}"> in the templates - they are no longer needed. Removes the def skip_csrf(datasette, scope): plugin hook defined in datasette/hookspecs.py and its documentation and tests. Updated CSRF protection documentation to describe the new approach. Upgrade guide now describes the CSRF change.
需要完整排版与评论请前往来源站点阅读。