CSP アロウリスト実験:サンドボックス環境でのエラー処理と許可ドメイン追加機能
Simon Willison は、CSP で保護されたサンドボックス iframe 内でエラーをキャッチし、ユーザーの承認を得て動的にドメインを追加する実験ツールを発表した。
キーポイント
動的 CSP 許可リストの実装
従来の静的な設定ではなく、実行時に発生した CSP エラーを intercept し、ユーザーの承認を経て許可リストに追加する仕組みを実証している。
サンドボックス環境での安全な拡張
CSP で厳格に制限された iframe 内でも、外部 API への接続が必要な際、ユーザーインターフェースを介して一時的・選択的に権限を付与できる。
開発者体験の向上
デバッグ時に手動でヘッダーを書き換える手間を省き、エラー発生時に即座にユーザーに確認を求めることで、セキュリティと利便性のバランスを図る。
影響分析・編集コメントを表示
影響分析
この実験は、Web セキュリティの標準である CSP が持つ「堅牢さ」と「柔軟性」の狭間で、ユーザー参加型の動的解決策を提示した点で意義深い。特に、厳格なサンドボックス環境下での開発や、サードパーティ連携が必要なアプリケーションにおいて、セキュリティ設定の複雑さを軽減する実用的なパターンを提供する。
編集コメント
セキュリティ設定の硬直性を打破する興味深いアプローチだが、現時点では実験段階であり、本番環境での実装には追加の検証が必要である。
ツール: CSP Allow-list Experiment
これは、CSP で保護されたサンドボックス化された iframe 内でアプリを読み込み(以前のノート参照)、カスタムの fetch() を使用して CSP エラーをインターセプトし、親ウィンドウへ転送する実験です。その後、ユーザーにそのドメインを許可リストに追加するよう促し、ページを更新することができます。
右側のパネルには、CSP ヘッダー default-src 'none'; script-src 'unsafe-inline'; style-s... のデフォルト設定で表示されるプレビューと、「Sandbox fetch test」という見出しが表示されています。また、tools.simonwillison.net からのモーダルダイアログが重ねられており、内容は「サンドボックスは https://api.inaturalist.org への接続を試みました。このオリジンを CSP connect-src の許可リストに追加してページを更新しますか?」です。チェックボックス「tools.simonwillison.net に再度プロンプトを表示しない」は未選択で、「キャンセル」と「OK」ボタンがあります。その下には「サンドボックスからのメッセージ」が表示され、fetch-catch により https://api.inaturalist.org/v1/observations?per... connect-src · https://api.inaturalist.org がブロックされたことが示されています。左下には「許可された fetch() オリジン」とあり、入力フィールドに https://api.github.com が含まれており、「追加」ボタンとタグ https://api.github.com x が表示されています。
原文を表示
Tool: CSP Allow-list Experiment
An experiment that shows that you can load an app in a CSP-protected sandboxed iframe (see previous note) and have a custom fetch() that intercepts CSP errors and passes them up to the parent window... which can then prompt the user to add that domain to an allow-list and then refresh the page.
. Right panel shows Preview with CSP header default-src 'none'; script-src 'unsafe-inline'; style-s... and heading "Sandbox fetch test". A modal dialog from tools.simonwillison.net is overlaid reading: "The sandbox tried to connect to: https://api.inaturalist.org Add this origin to the CSP connect-src allow-list and refresh the page?" with an unchecked checkbox "Don't allow tools.simonwillison.net to prompt you again" and Cancel and OK buttons. Below is "Messages from sandbox" showing fetch-catch blocked https://api.inaturalist.org/v1/observations?per... connect-src · https://api.inaturalist.org. At the bottom left is "Allowed fetch() origins" 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" />
Tags: content-security-policy, iframes, security
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み