砂箱化

iframe 要素 sandbox 属性 (HTML)

[60] 砂箱化 (sandboxing) は、 スクリプト等により可能な操作を制限するものです。 iframe 要素sandbox 属性は、入れ子閲覧文脈砂箱化を指示するものです。 CSPsandbox 指令は、 資源砂箱化を指示するものです。

[40] UGC や外部提供の広告など、主たるページの著者が完全には制御できない内容を埋め込みたい時に、 埋め込まれる内容の著者が利用できる機能を制限するために使うことができます。

仕様書

意味

[32] sandbox 属性は、 iframe 要素の中の内容に追加の制限を加えるものです >>31

[36]属性が指定されていると、色々な制限が適用されます。 属性に値を指定することで、その制限の一部を緩和できます。

[37] なお、すべての値を指定しても、すべての制限を緩和できるわけではありません (属性を指定しない状態になるわけではありません)。

[38]属性の指定は、 navigate 時に適用されます。変更したり削除したりしても、 直ちに適用されるのではなく、次の navigate より適用されます。

[50] CSPsandbox 指令は、保護対象資源に適用するべき制限を指定するものです >>48CSP では閲覧文脈ではなく、閲覧文脈内の文書単位で制限を適用します。 最上位閲覧文脈でも使うことができます。

[73] 祖先すべての閲覧文脈を含めた HTML sandbox 属性CSP sandbox 指令の最も厳しい制限が適用されます。

属性名

[51] iframe 要素属性名 >>31 も、 CSP指令名 >>48 も、 sandbox です。

属性値

[33] iframe sandbox 属性値は、unordered set of unique space-separated tokens でなければなりません >>31

[52] CSP sandbox 指令の値は、 空文字列か、1つ以上字句を1つ以上WSP で区切った列のいずれかでなければなりません >>48

[53] 実質的に HTMLHTTP も同じ構文ですが、空白文字参照の扱いはそれぞれの通常の規定に準じています。

[34] 各値は、認められた値のいずれかでなければなりません。 ASCII大文字・小文字不区別です >>31

[49] HTML Standard では、認められる値がすべて規定されているため、 一般的な構文は規定されていません。 CSP では、HTTP字句であると構文を規定し >>48HTML で認められる値を使わなければならない >>48 と規定していますが、 HTML と違って同じ値の重複は禁止されていないようです。

砂箱化フラグ集合

[61] 砂箱化は、仕様書上はいくつかのフラグの集合として表されており、 これを砂箱化フラグ集合 (sandboxing flag set) >>57 といいます。

[62] 砂箱化の指定がない場合、砂箱化フラグ集合は空とされ、 砂箱化はまったく行われません。

[63] sandbox 属性 >>31sandbox 指令 >>48 などで砂箱化が指示されている場合、 parse a sandboxing directive >>31 操作により新たな砂箱化フラグ集合が作られます。 この操作では、明示的に除外することが指定されたフラグを除いたすべての砂箱化のフラグが設定されます。

この操作では、指定されたキーワードや、別途与えられた allow fullscreen flag により、砂箱化のフラグを設定します。詳しくは次表を参照。

[64] 属性値 >>31指令値 >>48 は、 間隔で分割しなければなりません。 その結果キーワードが含まれていれば、 次表の通り、フラグが設定されません。

[65] 属性値の定義よりASCII大文字・小文字不区別と思われますが、 処理方法の規定では明記されていません。

[35] 次のフラグがあります。

flag
フラグ
kwd
フラグを設定しない条件
flag
sandboxed navigation browsing context flag
flag
sandboxed top-level navigation without user activation browsing context flag
kwd
allow-top-navigation キーワードが指定された時
flag
sandboxed top-level navigation with user activation browsing context flag
kwd
allow-top-navigation キーワードまたは allow-top-navigation-by-user-activation キーワードが指定された時
flag
sandboxed plugins browsing context flag
flag
sandboxed auxiliary navigation browsing context flag
kwd
allow-popups キーワードが指定された時
flag
sandboxed origin browsing context flag
kwd
allow-same-origin キーワードが指定された時
flag
sandboxed forms browsing context flag
kwd
allow-forms キーワードが指定された時
flag
sandboxed pointer lock browsing context flag
kwd
allow-pointer-lock キーワードが指定された時
flag
sandboxed scripts browsing context flag
kwd
allow-scripts キーワードが指定された時
flag
sandboxed automatic features browsing context flag
kwd
allow-scripts キーワードが指定された時
flag
sandboxed document.domain browsing context flag
flag
sandbox propagates to auxiliary browsing contexts flag
kwd
allow-popups-to-escape-sandbox キーワードが指定された時
flag
sandboxed modals flag
kwd
allow-modals キーワードが指定された時
flag
sandboxed orientation lock browsing context flag
kwd
allow-orientation-lock キーワードが指定された時
flag
sandboxed presentation browsing context flag
kwd
allow-presentation キーワードが指定された時

[84] かつては他に

flag
フラグ
kwd
フラグを設定しない条件
flag
sandboxed seamless iframes flag
flag
sandboxed fullscreen browsing context flag
kwd
allow fullscreen flag が指定された時
flag
砂箱化利用者媒体閲覧文脈フラグ
kwd
allow user media flag が指定された時
flag
sandboxed storage area URLs flag
... がありましたが、廃止されました。

[66] 砂箱化フラグ集合は、次の4箇所で使われています。

name
名称
context
所属
populated
設定される場面
name
ポップアップ砂箱化フラグ集合 (popup sandboxing flag set)
context
最上位閲覧文脈
populated
rules for choosing a browsing context given a browsing context name
name
iframe sandboxing flag set
context
要素入れ子閲覧文脈
populated
>>40, >>41, >>42
name
活性砂箱化フラグ集合 (active sandboxing flag set)
context
文書
populated
砂箱化を実装 (>>67)
name
forced sandboxing flag set
context
navigate資源 (応答)
populated
CSPenforce

[76] 文書の色々な処理で実際に参照されるのは、このうちの active sandboxing flag set です。それ以外は、砂箱化の実装active sandboxing flag set を決定するための入力として使われます。

[116] 活性砂箱化フラグ群を決定する手順群では、 合同 (union) 演算が行われます。

処理

[99] sandbox 属性は、入れ子閲覧文脈閲覧文脈の作成が行われる際や、 属性変更手順群が呼び出された際に、処理されます。

iframe 参照。

[54] CSP sandbox 指令は、 monitoring の場合 (Content-Securiry-Policy-Report-Only) や meta 要素の場合、無視されます >>48

[55] それ以外の場合、 enforce 時に指令の値を parse a sandboxing directive し、結果を保護対象資源forced sandboxing flag set としなければなりません >>48

[58] frame-ancestor 指令の制限対象となる場合には、 空文字列が指定された場合と同様に parse a sandboxing directive し、結果を保護対象資源forced sandboxing flag set としなければなりません >>57

[74] CSP の処理は、 navigate から間接的に呼び出されます。

[67] 閲覧文脈閲覧文脈navigateする資源について (すな) (ばこ) () フラグ (ぐん) (けっ) (てい) (determine sandboxing flags) するには、 次のようにします。 >>31

  1. [114] 砂箱化フラグ集合を、 次の各砂箱化フラグ集合に含まれるフラグの合同に設定します。
  2. [95] 砂箱化フラグ集合を返します。
[72] 親閲覧文脈同じ起源でない場合、ほんの数ビット分ですが、 起源を超えて情報が「漏れる」ことになります。

[111] 新しい閲覧文脈の作成navigate から呼び出されます。

[120] この処理は、 iframesandbox 属性など、 適用対象となる sandbox の指定をすべて掛け合わせた結果を取得するものです。 フラグの合同ですから、すべての制限が適用されたもっとも厳しい制約となります。

[118] HTML Standard 改定以前は、 (かっ) (せい) (すな) (ばこ) () フラグ (ぐん) (けっ) (てい) (determine active sandboxing flags) と呼ばれていました。 >>117

[119] 変更以後 forced sandboxing flag setnavigate文書オブジェクトの作成と初期化で後から合同される形に変更されました。 (仕様の厳密性の向上のための改定であり、意図した挙動は変わっていません。)

[56] navigate ではなく run a Worker 時に enforce される場合は、 sandbox 指令が指定され allow-scripts が指定されていない時や、 sandbox 指令が指定され allow-same-origin が指定されておらず新しい実行文脈が同じ起源であることを求めている時には、 ネットワークエラーが返されたものとして扱わなければなりません >>48

[75] scriptimportScripts で既存の実行文脈内でスクリプトを読み込むときには、この処理は行われません。

[113] の改訂以前は、 文書砂箱化の実装 (implement the sandboxing) 手順群として規定されていました。

サーバー

[39] 危険かもしれないファイルを iframe文書と同じサーバーから提供するべきではありません。 直接アクセスさせられると、 sandbox を回避してファイルが処理されてしまうからです。 被害を抑えるため、異なるドメインに分けて提供するべきです>>31

[77] CSPsandbox 指令により危険性を緩和できるかもしれませんが、 異なるドメインに置く方がより安全と思われます。

利用者インターフェイス

[78] Webブラウザーによっては、入れ子閲覧文脈文書最上位閲覧文脈で開くメニュー等の指示機能を利用者に提供しているかもしれません。 利用者砂箱化されているものを、そうと気づかずに通常の閲覧文脈で開いてしまうかもしれず、 注意が必要です。 popup sandboxing flag set を活用するなど配慮が必要かもしれません。

HTMLIFrameElement インターフェイス sandbox 属性

[43] HTMLIFrameElement インターフェイスsandbox IDL属性は、 sandbox 内容属性反映しなければなりません >>31

[44] 取得器は、 DOMSettableTokenList として反映します >>31

[45] 設定器は、 value IDL属性PutForwards されます >>31

関連

[41] CSP の他の機能も更なる安全性の確保に有用かもしれません。

[42] 単一の文書の一部の内容のみを砂箱化することはできません。しかし iframe 要素srcdoc 属性と併用すれば、そのような効果が得られます。

歴史

[1] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=4576&to=4577

[2] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=4577&to=4578

[3] (X)HTML5 Tracking ( 版) http://html5.org/tools/web-apps-tracker?from=4579&to=4580

[4] HTML5 Revision Tracker ( 版) http://html5.org/tools/web-apps-tracker?from=4861&to=4862

[5] IRC logs: freenode / #whatwg / 20100408 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20100408

[6] [whatwg] Please consider dropping the "sandbox" attribute from the <iframe> element ( 版) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-August/027491.html

[7] IRC logs: freenode / #whatwg / 20100715 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20100715

[8] Web Applications 1.0 r5571 Better define how sets of unique space-separated tokens are handled in terms of case-sensitivity.Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=10781 ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5570&to=5571

[9] IRC logs: freenode / #whatwg / 20110714 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20110714

[10] IRC logs: freenode / #whatwg / 20111011 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20111011

[11] [whatwg] iframe sandbox, <object tag> ( ( 版)) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-January/034567.html

[12] Web Applications 1.0 r7054 sandbox='allow-popups' feature ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7053&to=7054

[13] IRC logs: freenode / #whatwg / 20120411 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20120411

[14] IRC logs: freenode / #whatwg / 20120414 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20120414

[15] [whatwg] Security Issue- Iframe Sandbox attribute - Clarity of operation ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-June/036530.html

[16] [whatwg] iframe sandbox attribute ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-July/036586.html

[17] [whatwg] Additional attribute value for iframe sandbox ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-July/036587.html

[18] [whatwg] sandboxed documents and cookies ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-July/036589.html

[19] Web Applications 1.0 r7485 Add sandbox=allow-pointer-lock, and some nearby cleanup. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7484&to=7485

[20] [whatwg] allowfullscreen vs sandbox="allow-fullscreen" ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-December/038258.html

[21] ChangeProposals/sandbox allow popups - HTML WG Wiki ( ( 版)) http://www.w3.org/html/wg/wiki/ChangeProposals/sandbox_allow_popups

[22] Web Applications 1.0 r7984 Sandboxing: prevent pages from closing their top-level browsing context (unless they can navigate it, in which case, whatever) ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7983&to=7984

[23] [whatwg] iframe sandbox and top navigation ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-July/040002.html

[24] [whatwg] Making cross-origin <iframe seamless=""> (partly) usable ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-July/040115.html

[25] [whatwg] iframes, more sandbox ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2014-May/254199.html

[26] Add a placeholder for filesystem and add the sandboxed storage area URLs... · e6fa889 · whatwg/fetch ( ( 版)) https://github.com/whatwg/fetch/commit/e6fa8899423652413287c0cf22cd074ffed12905

[27] Web Applications 1.0 r8706 Add a sandboxing flag for use by fetch ( ( 版)) http://html5.org/r/8706

[28] [whatwg] Proposal: Two changes to iframe@sandbox (Mike West 著, 版) https://lists.w3.org/Archives/Public/public-whatwg-archive/2015May/0035.html

[29] Iframe sandbox improvments - WHATWG Wiki ( 版) https://wiki.whatwg.org/wiki/Iframe_sandbox_improvments

[30] Re: [whatwg] Proposal: Two changes to iframe@sandbox (Mike West 著, 版) https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Jun/0098.html

[79] Block modal dialogs by default in sandboxed documents · whatwg/html@bbccfc9 ( 版) https://github.com/whatwg/html/commit/bbccfc976754def0c187ac8ce5891d2fb20dfc15

[80] Cleanup sandbox token lists · whatwg/html@36f2a65 ( 版) https://github.com/whatwg/html/commit/36f2a65398310be4aeef3e71bb01bb290589ecb3

[81] Clarify sandbox directive. · w3c/webappsec-csp@4568e26 ( 版) https://github.com/w3c/webappsec-csp/commit/4568e26ca6f58f6609c8b5d30b38f9992776256c

[82] Add supported tokens to relList and sandbox · whatwg/html@f7a66ed ( 版) https://github.com/whatwg/html/commit/f7a66ed52a93d3b63304f4a669e868684dc95b56

[83] No CSP report-uri|frame-ancestors|sandbox in meta · whatwg/html@3947072 ( 版) https://github.com/whatwg/html/commit/39470724136a366bab4e893efd889a513d61cc3e

[85] Remove <iframe seamless> · whatwg/html@1490eba ( 版) https://github.com/whatwg/html/commit/1490eba4dba5ab476f0981443a86c01acae01311

[86] Adding [SameObject] to DOMTokenLists · whatwg/html@ec1dc4d ( 版) https://github.com/whatwg/html/commit/ec1dc4d4571c61cf0c0dfe3e562898635886b412

[87] Restrict valid sandbox values to keywords in HTML · w3c/webappsec-csp@cfd12e8 ( 版) https://github.com/w3c/webappsec-csp/commit/cfd12e8828a431f4741942480bf501042ba7be1a

[88] We're not going to enable 'sandbox' in '<meta>'. · w3c/webappsec-csp@8ca78f0 ( 版) https://github.com/w3c/webappsec-csp/commit/8ca78f0ed12bbbde0a11c4d58fb936ce0a25f9d7

[89] Fold CSPDOCUMENT into CSP. ( (mikewest著, )) https://github.com/w3c/webappsec-csp/commit/0cd4bf42b5e78168cd85efe798a9a5e719677b8e

[90] Add allow-orientation-lock to sandbox flags ( (mounirlamouri著, )) https://github.com/whatwg/html/commit/8f0f73c1b061a8ccee57c6878d8474b43c73aaeb

[91] Add allow-presentation to sandbox flags ( (mounirlamouri著, )) https://github.com/whatwg/html/commit/0678e3de01a3ef83c5f6f0c017e7464ede1d8ec1

[92] ( ()) http://www.integrity.or.jp/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fwww.integrity.or.jp%2F

<iframe sandbox="allow-scripts" security="restricted" src="http://www.integrity.or.jp/embed/" width="600" height="338" title="&#8220;東京都港区の税理士法人インテグリティです&#8221; &#8212; 税理士なら港区の税理士法人インテグリティ" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>

[93] Use fullscreen logic for initial about:blank documents too ( (annevk著, )) https://github.com/whatwg/html/commit/c2a8d605e0115c80d1ccb4b15371ecaa56a33e30

[94] Integrate allowusermedia (domenic著, ) https://github.com/whatwg/html/commit/688df431630fe7d9a0518e402c1f1543d0f493a0

[101] Make allowfullscreen and allowusermedia match implementations (annevk著, ) https://github.com/whatwg/html/commit/9f6b91cb14a0f497ee5b3e7118ee65e687eaea78

[98] Be more precise about nested and discarded browsing contexts (domenic著, ) https://github.com/whatwg/html/commit/39118df640ad4a3f03f164fb5ffe0a56316297be

[46] Tweak [CEReactions] definition and usage (domenic著, ) https://github.com/whatwg/html/commit/c422734d44ae9897c1700daf08bd415e0dc5f9e1

[47] Add allow-top-navigation-by-user-activation sandbox token (domenic著, ) https://github.com/whatwg/html/commit/8abd73ec3a56541e3f6486d3a593a8bcfd67295d

[100] Remove <applet> (zcorpan著, ) https://github.com/whatwg/html/commit/b9b9d60f9451c05f8e8d542e4094f987ae1a5fb8

[102] 28563 – As in most cases the http-equiv meta tags are equivalent to their corresponding HTTP header, would i [...] () https://www.w3.org/Bugs/Public/show_bug.cgi?id=28563

[103] Define the HTTP Refresh header by annevk · Pull Request #2892 · whatwg/html () https://github.com/whatwg/html/pull/2892

[104] <meta http-equiv=Set-Cookie> should do nothing if document is cookie averse · Issue #1950 · whatwg/html () https://github.com/whatwg/html/issues/1950

[105] What is the "sandboxed storage area URLs flag"? · Issue #3862 · whatwg/html () https://github.com/whatwg/html/issues/3862

[106] Editorial: remove sandboxed storage area URLs flag (annevk著, ) https://github.com/whatwg/html/commit/42a1e493fea61129e4b7c8a3bd80856feb85b8c4

[107] What is the "sandboxed storage area URLs flag"? · Issue #3862 · whatwg/html () https://github.com/whatwg/html/issues/3862

[108] Remove "filesystem" URL scheme · Issue #846 · whatwg/fetch () https://github.com/whatwg/fetch/issues/846

[109] Editorial: remove sandboxed storage area URLs flag by annevk · Pull Request #4388 · whatwg/html () https://github.com/whatwg/html/pull/4388

[110] Refactor the navigation algorithm (dtapuska, , ) https://github.com/whatwg/html/commit/061e782437c6cff600f18bc96c1a11489e09c3ab

[112] Refactor navigation algorithm. by dtapuska · Pull Request #4664 · whatwg/html () https://github.com/whatwg/html/pull/4664

[117] Snapshot sandbox at the start of navigation (clelland, , ) https://github.com/whatwg/html/commit/eb13fece2cadc45863dc61079358b72478756f8b

[121] Possible race in feature policy in multiprocess implementations · Issue #256 · w3c/webappsec-permissions-policy () https://github.com/w3c/webappsec-permissions-policy/issues/256

[122] Snapshot sandbox at start of navigation. by clelland · Pull Request #5098 · whatwg/html () https://github.com/whatwg/html/pull/5098

[123] Editorial: nested browsing context is a member, not a type (annevk, , ) https://github.com/whatwg/html/commit/6b737bbc428facf34ec3728c0912cf9e172d0ea4

[124] Revamp the user activation model (mustaqahmed, , ) https://github.com/whatwg/html/commit/8f8c1f50158736b3cf16188377a0974a20367c8b