Created
July 25, 2012 15:15
Revisions
-
syoichi revised this gist
Aug 3, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ }()); ``` 取得したコードは、CSPにより、Data URIによる読み込み、Inline JavaScript、javascriptスキーム、eval、Function、setTimeout、setIntervalによる実行はできないはず([参考](https://docs.google.com/presentation/d/1FCSnSw_6CIc9fng9nqUGB_9bGJq3hliJw7O-l4d0mmA/edit?pli=1#slide=id.g1506577f_12_18))。[blobスキーム](http://dev.w3.org/2006/webapi/FileAPI/#url)、[filesystemスキーム](http://www.html5rocks.com/ja/tutorials/file/filesystem/#toc-filesystemurls)についてはわからない。<br> なお、web_accessible_resourcesに登録するとWeb上から取得も実行もできてしまうので注意が必要。 ## 実行する -
syoichi revised this gist
Jul 27, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ (function executeGetOtherExtensionJSByXHR() { 'use strict'; var OTHER_EXTENSION_JS, xhr, log; OTHER_EXTENSION_JS = 'chrome-extension://<EXTENSION_ID>/check.js'; @@ -68,7 +68,7 @@ (function executeLoadOtherExtensionJS(doc) { 'use strict'; var OTHER_EXTENSION_JS; OTHER_EXTENSION_JS = 'chrome-extension://<EXTENSION_ID>/check.js'; -
syoichi created this gist
Jul 25, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ 他の拡張のJavaScriptファイルを取得・実行できると、[その拡張がインストールされていて有効になっている事がわかる](http://utatane.tumblr.com/post/387377735/taberareloo-1-1-3)。[Extension Messaging APIによる拡張間通信](http://code.google.com/chrome/extensions/messaging.html#external)(受信側にEvent Listenerが設定されている場合)や、[Management API](http://code.google.com/chrome/extensions/management.html)によっても知る事は可能。 検証環境はWindows 7 Home Premium SP1 64bit上のChrome 20.0.1132.57、Chromium 22.0.1217.0 (148295)。 ## XHRで取得する 取得するファイルを持つ拡張で、Manifestの[web_accessible_resources](http://code.google.com/chrome/extensions/manifest.html#web_accessible_resources)にファイルを登録しておく。 ``` "web_accessible_resources": [ "check.js" ], ``` これでXHRで取得可能になる。 ``` js /*jslint browser: true, devel: true, maxlen: 80*/ // Edition 2012-07-23 (function executeGetOtherExtensionJSByXHR() { 'use strict'; var OTHER_EXTENSION_JS, xhr, log; OTHER_EXTENSION_JS = 'chrome-extension://<EXTENSION_ID>/check.js'; xhr = new XMLHttpRequest(); log = function log(evt) { var xhr; xhr = evt.target; if (/^(?:200|304)$/.test(xhr.status)) { console.log(xhr.responseText); return; } console.error('loading error'); }; xhr.addEventListener('load', log); xhr.addEventListener('error', log); xhr.open('GET', OTHER_EXTENSION_JS); xhr.responseType = 'text'; xhr.send(null); }()); ``` 取得したコードは、CSPにより、Data URIによる読み込み、Inline JavaScript、javascriptスキーム、eval、Function、setTimeout、setIntervalによる実行はできないはず([参考](https://docs.google.com/presentation/d/1FCSnSw_6CIc9fng9nqUGB_9bGJq3hliJw7O-l4d0mmA/edit?pli=1#slide=id.g1506577f_12_18))。[filesystemスキーム](http://www.html5rocks.com/ja/tutorials/file/filesystem/#toc-filesystemurls)についてはわからない。<br> なお、web_accessible_resourcesに登録するとWeb上から取得も実行もできてしまうので注意が必要。 ## 実行する 実行したい拡張で、Manifestの[content_security_policy](http://code.google.com/chrome/extensions/contentSecurityPolicy.html)に実行するファイルを持つ拡張のOriginを登録しておく。[アプリではcontent_security_policyを変更できない](https://docs.google.com/presentation/d/1FCSnSw_6CIc9fng9nqUGB_9bGJq3hliJw7O-l4d0mmA/edit?pli=1#slide=id.g1506577f_12_18)らしい。 ``` "content_security_policy": "script-src 'self' chrome-extension://<EXTENSION_ID>; object-src 'self'", ``` 後はBackground Pageで読みこめば実行できる。 ``` js /*jslint browser: true, maxlen: 80*/ // Edition 2012-07-23 (function executeLoadOtherExtensionJS(doc) { 'use strict'; var OTHER_EXTENSION_JS; OTHER_EXTENSION_JS = 'chrome-extension://<EXTENSION_ID>/check.js'; doc.head.appendChild(doc.createElement('script')).src = OTHER_EXTENSION_JS; }(document)); ``` 何故これが可能なのかは不明。[Relaxing the default policy](http://code.google.com/chrome/extensions/contentSecurityPolicy.html#H2-3)では特に言及されてない。不具合かもしれないので、そのうちできなくなるかもしれない。 ちなみに、Manifest Version 1の拡張のJavaScriptファイルは、何も設定しなくても他の拡張から実行する事ができてしまう。