same-origin policy

同一起源ポリシー (Web)

[4] 同一起源ポリシー (same origin policy) は、 Web において、スクリプトが異なる起源 (URL schemeホストポートの組など) に由来する物体に対してアクセスすることを制限するセキュリティーに関する大原則です。

[55] たまに SOP と略されることがあります。

仕様書

同一起源ポリシーの原理

[56] Webアプリケーションは、が提供したスクリプト等を Webブラウザー上の環境において実行、 評価するものですが、適切なセキュリティー・モデルが無ければ利用者やその他の人が意図しない有害な動作がなされてしまうかもしれません。 同一起源方針Webブラウザー上で動作するWebアプリケーションのためのセキュリティー・モデルとして発展、収束してきたものです。 RFC 6454Adam Barth は次の基本原理をまとめています。

  • Trust
  • Origin
  • Authority
  • Policy

Trust

[57] 同一起源方針においては URL によって trust を指定していると言えます。

[58] 例えば script 要素によって URL を指定して外部のスクリプトを読み込むことは、 自身の持つ特権を当該 URL に対して付与していることになります。 つまり当該 URL から得られる情報の一貫性を信頼 (trust) すると宣言していると言えます。

[59] また form 要素によって POST 先の URL を指定することは、秘密のデータを当該 URL に対して開示することになります。 つまり当該 URL に送られるデータの秘匿性を信頼 (trust) すると宣言していると言えます。

Origin

[60] あらゆる URL にそれぞれ個別の保護された領域を与えることもできますが、 それでは実用上不便なので、同一起源方針にあってはドメインなどが共通する URL 群を 起源 (origin) と呼び、これを保護の単位とします。

[61] 例えば http://example.com/http://example.com/~mypage/http://example.com という共通の起源を持ちます。しかし http://www.example.com/http://example.com:8080/起源はそれぞれ http://www.example.comhttp://example.com:8080 であり、異なります。

Authority

[62] 起源が同じであっても、資源はそれぞれの権限 (authority) を持っています。 どれだけの権限を与えるかは MIME型により決まります。

[63] 例えば image/png資源画像であり、 API その他へのアクセス権を有しません。一方 text/html資源HTML文書であり、スクリプトの実行その他の様々な権限を有します。

Policy

[64] 同一起源方針においては起源はそれぞれ別に管理されており、他の起源との通信は制限されています。 他の起源APIアクセスは原則として禁止されていますし、他の起源資源を読み取ることもできません。 他の起源に情報を送ることは認められていますが、一部の決められた形式に制限されています。

[65] 例えば DOMAPI によって他の起源文書にアクセスすることはできません。 postMessage など例外はありますが、それ以外は Webブラウザーにより厳密に管理されています。

[66] XHR によって他の起源資源を読み取ることは、 CORS により例外的に認められていない限り、 禁止されています。

同一起源ポリシーが保護しないもの

[18] 一見セキュリティーに関わりそうな次の要素は、起源の定義には含まれていませんから、 同一起源ポリシーの保護対象外です。

[151] 著者は、必要なら対策を講じる必要があります。

[152] 例えば同じ起源の一部のページは認証不要で公開されており、 他のページはHTTP認証により保護されているとします。 まず保護されたページに認証つきでアクセスし、 localStorage に何らかのデータを保存します。 次に認証不要なページに認証つきでアクセスし、 localStorage を参照すると、 前に保存したデータが得られます。 なぜなら、 localStorage起源単位のストレージであり、 認証の有無は起源の違いとならないからです。

[153] これが問題となるかどうかは、アプリケーションの性質に依存します。 問題となるのであれば、 (Webブラウザーのセキュリティーホールではなくアプリケーション設計の問題なので) 著者が対策を検討しなければなりません。

適用対象

[9] いくつかの挙動はそれが同じ起源に対して行われた操作に由来するか否かによって変化します。 一般に他の起源の状態や処理結果は取得できません。

このリストは不完全です。

[129] Widgetpreferences にも同一起源ポリシーが適用されます。

起源の値によって動作が変わるもの

[115] 起源三項組であるか固有識別子であるか、あるいはその三項組がどのような値であるかによって、 挙動が変わることがあります。

適用対象外

[10] 次の機能を使うと、同一起源ポリシーは適用されず、 他の起源のデータに (ある程度) アクセスできます。

[138] ここに挙げたものの他、起源とは異なるものを適用対象の範囲とする機能もいくつかあります。 詳しくは起源の「起源と適用範囲が異なる機能」の項を参照。

要調査

[11] 制約の緩和

[136] Firefox拡張は拡張 (chrome:) から内容 (browser閲覧文脈) にアクセスでき、 同一起源ポリシー無く操作できます。拡張から内容内の節点DOMイベントdispatch して、情報を伝えることがあります。

[137] ブラウザー拡張によっては内容スクリプト拡張から内容に注入できることがあります。 拡張内容スクリプトで通信する手段を提供していることもありますが、 それ以外での両者間のアクセスは制限されています。

[139] 逆に、 sandbox を使うと、本来同じ起源となるものを異なる起源として扱わせることができます。

媒体

[30] Re: Same-origin checking for media elements (Ian Hickson <ian@...> 著, 版) http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/16571

労働者

・・・

局所ファイル

[27] HTML5局所ファイルに関しては相互運用性に関係しないため適用範囲外として規定していません。

[28] Chromeセキュリティモデル、IE/Firefox/Safari/Operaのいいとこ取り | エンタープライズ | マイコミジャーナル (Mainichi Communications Inc. 著, 版) http://journal.mycom.co.jp/news/2008/12/08/031/

[29] Chromium Blog: Security in Depth: Local Web Pages ( 版) http://blog.chromium.org/2008/12/security-in-depth-local-web-pages.html

歴史

[6] 同一起源方針は、 Netscape Navigator 2.0 で JavaScript と共に導入され >>1>>2、2.01 および 2.02 で不具合の修正がなされました >>1

[7] Internet Explorer をはじめとする他ブラウザも同様にこの制限を実装しましたが、 ECMAScript 仕様や DOM 仕様としての標準化の対象外とされ、 長らく明文化された規定が存在していませんでした。

[165] 暗黙の標準だった時期の同一起源ポリシーは、実装ごとに細かな違いがありました。 例えばポート起源の区別に寄与させるかどうかは、 現在の document.domainクッキーの適用範囲にも影響を残しています。 Internet Explorerセキュリティーゾーンのように、 同一起源ポリシーの原則から外れた機能も存在していました。


[8] HTML DOM に関係する部分はようやく2005年頃に WHATWG によって HTML 5 仕様の一部として仕様の明文化が行われ始めました。 また、 XMLHttpRequest に関しては HTML 5 仕様を参照する形で規定されています。

[126] Document は、当初はオブジェクトそのものは取得できるものの、 そのメンバーは一切読み書きできないとなっていましたが、 contentDocument などが異なる起源の場合 null を返すよう変更され、異なる起源Document オブジェクトにアクセスすること自体ができなくなりました。

[24] 起源に関する基本的な規定は RFC 6454 となりましたが、2014年に HTML StandardURL StandardFetch Standard により廃止されています。

起源を参照。

[2] JavaScript Security: Same Origin (2008-06-18 04:13:16 +09:00 版) http://www.mozilla.org/projects/security/components/same-origin.html

[1] Same origin policy - Wikipedia, the free encyclopedia (2008-07-02 01:06:45 +09:00 版) http://en.wikipedia.org/wiki/Same_origin_policy

[35] Same origin policy for JavaScript - MDC ( 版) https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript

[36] The Multi-Principal OS Construction of the Gazelle Web Browser - Microsoft Research ( 版) http://research.microsoft.com/apps/pubs/default.aspx?id=79655

Webブラウザープロセス起源毎に分離することによって保安性の向上を図る論文だそうです。

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

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

[42] [whatwg] Canvas 2D Context Proposal: resetOriginClean ( 版) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-April/026006.html

[45] Guidelines for Web Content Transformation Proxies 1.0 ( ( 版)) http://www.w3.org/TR/2010/NOTE-ct-guidelines-20101026/#term-same-origin

[46] Web Applications 1.0 r5873 Make sure cross-origin fonts can't leak data via <canvas>. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5872&to=5873

[47] Embedder's Guide - V8 JavaScript Engine - Google Code ( ( 版)) http://code.google.com/intl/ja/apis/v8/embed.html

[48] draft-abarth-principles-of-origin-00 - Principles of the Same-Origin Policy ( 版) http://tools.ietf.org/html/draft-abarth-principles-of-origin-00

[49] Thoughts on font linking and embedding ( (Maciej Stachowiak 著, 版)) http://lists.w3.org/Archives/Public/public-webfonts-wg/2011Feb/0066.html

[50] Thoughts on font linking and embedding ( (Maciej Stachowiak 著, 版)) http://lists.w3.org/Archives/Public/public-webfonts-wg/2011Feb/0066.html

[51] [whatwg] Canvas and drawWindow ( 版) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-March/030862.html

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

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

[54] クロスドメイン通信方法のまとめ - nopnopの日記 ( ( 版)) http://d.hatena.ne.jp/nopnop/20080408/1207669947

[110] [whatwg] Need to define same-origin policy for WebIDL operations/getters/setters ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-January/038529.html

[117] Web Applications 1.0 r7975 Make showModalDialog()'s dialogArguments and returnValue only be useful same-origin, to avoid origins attacking each other ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7974&to=7975

[118] Web Applications 1.0 r7975 Make showModalDialog()'s dialogArguments and returnValue only be useful same-origin, to avoid origins attacking each other ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7974&to=7975

[119] [whatwg] Adding crossorigin="" to more elements ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-June/039752.html

[120] Web Applications 1.0 r7997 Block enumeration of cross-origin objects, and clean up the language around those objects to be more consistent so that differences can more easily be seen. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=7996&to=7997

[121] Web Applications 1.0 r8090 Remove the weird stuff around document.domain and localStorage. It doesn't really do anything anyway. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8089&to=8090

[122] Web Applications 1.0 r8196 Add warning notes to the Security sections of Location and Window since they are in flux with no end in sight. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8195&to=8196

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

[130] Web Applications 1.0 r8713 getSVGDocument() ( ( 版)) http://html5.org/r/8713

[72] Same-origin policy - Web security | MDN ( ( 版)) https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

[131] 524223 – (CVE-2010-0654) Cross-domain data theft using CSS ( 版) https://bugzilla.mozilla.org/show_bug.cgi?id=524223

[132] Same-origin policy — Anne’s Blog ( 版) https://annevankesteren.nl/2015/02/same-origin-policy

[133] Part2 - browsersec - Browser Security Handbook, part 2 - Browser Security Handbook - Google Project Hosting ( 版) https://code.google.com/p/browsersec/wiki/Part2

[134] From the Aether to the Ethernet – Attacking the Internet using Broadcast Digital Television | the morning paper ( 版) http://blog.acolyer.org/2015/04/23/from-the-aether-to-the-ethernet-attacking-the-internet-using-broadcast-digital-television/

What’s the origin if you provide content over the broadcast transport though?

The HbbTV specification suggests that in this case the broadcast stream should explicitly define its own web origin by setting the simple_application_boundary_descriptor property in the AIT to any desired domain name.

Yes, you can be anyone you want to be.

[135] HbbTV and Web origins (Mark Nottingham 著, 版) https://lists.w3.org/Archives/Public/www-tag/2015Apr/0052.html

[91] Abusing HTTP status codes to deanonymize web users (Ahmed Elsobky 著, 版) https://lists.w3.org/Archives/Public/public-webappsec/2015May/0043.html

[92] Re: Abusing HTTP status codes to deanonymize web users (Anne van Kesteren 著, 版) https://lists.w3.org/Archives/Public/public-webappsec/2015May/0047.html

[71] Widget Interface ( 版) http://w3c.github.io/packaged-webapps/api/Overview.html#preference-origin-security-check

[141] Introduction to DHTML Behaviors ( 版) https://msdn.microsoft.com/ja-jp/library/ms531079(v=vs.85).aspx

Behaviors are subject to the About Cross-Frame Scripting and Security rules of Internet Explorer. In other words, a Web page that refers to a behavior located on another server in another domain results in an "access denied" error in the page's onerror event handler. In the same way, a Web page that refers to a behavior of a different security protocol than the referring page will result in the same error. For example, a Web page on http://server1/page.htm might not refer to a behavior on https://server1/hilite.htc.

[142] ja:midori:faq [Xfce Wiki] ( 版) https://wiki.xfce.org/ja/midori/faq

同一生成元ポリシー (Same Origin Policy) を無効に出来ますか? Midori の設定にない Webkit の設定変更はできませんか?

Midori の設定ファイル (Unix の場合は ~/.config/midori/config、Windows の場合は %APPDATA%\midori\config) で WebKitWebSettings のすべての値を変更できます。例えば、ローカルファイルで同一生成元ポリシーを無効にする場合、以下を追加してください:

enable-universal-access-from-file-uris=true

[143] Mozilla XForms Specials - Archive of obsolete content | MDN ( 版) https://developer.mozilla.org/en-US/docs/Archive/Web/XForms/Mozilla_XForms_Specials

Not exactly either a limitation, or an extension, but it is worth mentioning here. For security reasons, it is not per default possible for an XForms to submit data to another domain. This is due to security reasons. Information about how to whitelist domain can be found in the Release Notes

The cross domain check also includes forms loaded from file://. Forms loaded from that URL should be local files, and thus trusted, but it is not always the case. So there is not automatic "whitelisting" of local files.

[145] Merge pull request #44 from yoavweiss/timing_allow_same_origin_pass · w3c/resource-timing@960a8cb ( 版) https://github.com/w3c/resource-timing/commit/960a8cbd77d640a5ac981ba9c77208aee6bb84e0

[146] Add some more parameters to the "perform a security check" hook (for … · heycam/webidl@adf3772 ( 版) https://github.com/heycam/webidl/commit/adf37720bd92138f9f1627a214330287550c0004

[147] Merge pull request #65 from andrey-logvinov/gh-pages ( (andrey-logvinov著, )) https://github.com/w3c/wake-lock/commit/7a019503df2a917ca28f3655bcfd953f243703ca

[154] Cross-origin objects: do not wrap JavaScript functions ( (annevk著, )) https://github.com/whatwg/html/commit/db361b608157b5cf9fd0d491d7dc76cdce80380b

[155] Remove unnecessary and unimplemented canvas tainting when painting text (domenic著, ) https://github.com/whatwg/html/commit/6c76b617d2b45326afea2625d174ce2fd5ab6423

[156] IE11とFirefoxのAdobe PDFで意図しない情報漏洩の可能性 | スラド セキュリティ () https://security.srad.jp/story/16/11/16/147247/

問題の脆弱性は、PDFにプログラムを埋め込める「FormCalc」という機能に関連するもの。FormCalcにはネットワーク経由でコンテンツの取得や送信を行える「Get」や「Post」、「Put」といった命令が用意されている。これを利用してPDFが配信されているドメインと同じドメイン上のデータを取得し、それを外部サーバーに送信するという処理をPDFを閲覧するマシン上で自動実行させることができるという。

一般的なWebブラウザでは、スクリプトによるHTTPリクエストについて、リクエスト先をそのスクリプトを配信するドメインに限定する、「同一オリジンポリシー(same-origin policy)」が適用されている(Mozillaによるドキュメント)。しかし、FormCalcではこの制限が緩く、取得した情報を別のサイトに送信できてしまうという。

[157] Reports feature violates the same-origin policy (Anne van Kesteren著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Feb/0009.html

[158] Re: Reports feature violates the same-origin policy (Mike West著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Feb/0013.html

[159] Re: Reports feature violates the same-origin policy (Daniel Veditz著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Feb/0019.html

[160] Re: Reports feature violates the same-origin policy (Anne van Kesteren著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Feb/0021.html

[161] "Script error." message in window.onerror makes bad DevExp trade off · Issue #2440 · whatwg/html () https://github.com/whatwg/html/issues/2440

[162] Single Trust and Same-Origin Policy v2 (John Wilander著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Mar/0034.html

[163] Re: Single Trust and Same-Origin Policy v2 (Mike West著, ) https://lists.w3.org/Archives/Public/public-webappsec/2017Mar/0054.html

[164] Make <body topmargin> win over <iframe marginheight> (#2489) (zcorpan著, ) https://github.com/whatwg/html/commit/3fc830124986d8fb0aa53cd2d2f2fea12a926e5d

[166] Enumerate fewer cross-origin properties (annevk著, ) https://github.com/whatwg/html/commit/ad8823782e7f6b7d60f8e216901bb76d1a53dd6d

[167] A primer on cross-origin information leaks (Artur Janc著, ) https://lists.w3.org/Archives/Public/public-webappsec/2018May/0009.html

[168] Exposing CSS subresource URLs · Issue #70 · w3c/resource-timing () https://github.com/w3c/resource-timing/issues/70

[169] Take tainted origin flag into account for the same origin check (annevk著, ) https://github.com/whatwg/fetch/commit/986618a62b2d7d31f93177ed178f0cb21b570d85

[170] Request's tainted origin flag fallout · Issue #756 · whatwg/fetch () https://github.com/whatwg/fetch/issues/756

[171] Take tainted origin flag into account for the same origin check by annevk · Pull Request #834 · whatwg/fetch () https://github.com/whatwg/fetch/pull/834