CSP 白名单沙盒实验

Simon Willison··作者 Simon Willison

关键信息

这个演示运行在一个沙盒 iframe 中,并拦截由 CSP 的 connect-src 限制触发的 fetch 错误。父窗口随后可以弹出允许列表提示,截图还显示了重置示例、清空允许列表和刷新预览等控件。

资讯摘要

Simon Willison 介绍了一个名为“CSP Allow-list Experiment”的工具。作者明确把它描述为一个实验,而不是成熟产品。这个项目展示了应用可以在受 CSP 保护的沙盒 iframe 中运行,并通过自定义的 fetch() 实现来捕获 CSP 失败。当前请求被阻止时,沙盒会把错误报告给父窗口。

父窗口随后可以提示用户把对应域名加入允许列表,并在之后刷新页面。文章中的截图显示,预览区尝试连接 api.inaturalist.org 时被阻止,同时界面弹出允许列表提示,并展示来自沙盒的消息。这个工具还提供了重置示例、清空允许列表、刷新预览等控件,以及一个可视化的允许 fetch 来源列表。Willison 还提到,这个实验是用 Codex desktop app 里的 GPT-5.5 xhigh 构建的。

CSP 白名单沙盒实验

资讯正文

工具:<a href="https://tools.simonwillison.net/csp-allow">CSP 允许列表实验</a>

一个实验,展示了你可以在受 CSP 保护的沙盒 iframe 中加载一个应用(参见<a href="https://simonwillison.net/2026/Apr/3/test-csp-iframe-escape/">上一篇说明</a>),并使用一个自定义的 <code>fetch()</code> 来拦截 CSP 错误,把它们传递给父窗口……父窗口随后就可以提示用户将该域名添加到允许列表中,然后刷新页面。

<img alt="Screenshot of a web tool titled &quot;CSP Allow-list Experiment&quot; with buttons Reset sample, Clear allow-list, Refresh preview. Left panel shows HTML source code starting with &lt;!doctype html&gt;. Right panel shows Preview with CSP header default-src 'none'; script-src 'unsafe-inline'; style-s... and heading &quot;Sandbox fetch test&quot;. A modal dialog from tools.simonwillison.net is overlaid reading: &quot;The sandbox tried to connect to: https://api.inaturalist.org Add this origin to the CSP connect-src allow-list and refresh the page?&quot; with an unchecked checkbox &quot;Don't allow tools.simonwillison.net to prompt you again&quot; and Cancel and OK buttons. Below is &quot;Messages from sandbox&quot; showing fetch-catch blocked https://api.inaturalist.org/v1/observations?per... connect-src · https://api.inaturalist.org. At the bottom left is &quot;Allowed fetch() origins&quot; with an input field containing https://api.github.com, an Add button, and a tag https://api.github.com x." src="https://static.simonwillison.net/static/2026/csp-allow.jpg" />

我用在 Codex 桌面应用中运行的 GPT-5.5 xhigh 做了这个。

标签:<a href="https://simonwillison.net/tags/content-security-policy">content-security-policy</a>,<a href="https://simonwillison.net/tags/iframes">iframes</a>,<a href="https://simonwillison.net/tags/security">security</a>

来源与参考

  1. 原始链接
  2. Tool: CSP Allow-list Experiment

收录于 2026-05-14