SafariのCSPのPath matchingがなんか不思議
CSP Lv.2のPath matching
こないだ使ったLTの資料とCSP Lv.2の最終草案を見てください。
CSP Lv.2の話 from Yu Yagihashi
Content Security Policy Level 2 W3C Last Call Working Draft
Path matchingの概要
Content-Security-Policy: script-src http://xss.moe/js/
で http://xss.moe オリジンの /js 以下のスクリプトのみ許可される。
ソースリストはこういう書き方もできる。
Content-Security-Policy: script-src http://*.xss.moe Content-Security-Policy: script-src *.xss.moe Content-Security-Policy: script-src *.xss.moe/js/
Safariの不思議
HTTP/1.1 200 OK Date: Wed, 29 Oct 2014 05:52:10 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Content-Security-Policy: script-src *.xss.moe Content-Length: 51 Content-Type: text/html; charset=UTF-8 <script src="//test.xss.moe/js/alert.js"></script>
これは通る。
HTTP/1.1 200 OK Date: Wed, 29 Oct 2014 05:53:20 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Content-Security-Policy: script-src http://*.xss.moe/js/ Content-Length: 51 Content-Type: text/html; charset=UTF-8 <script src="//test.xss.moe/js/alert.js"></script>
これも通る。
HTTP/1.1 200 OK Date: Wed, 29 Oct 2014 05:53:28 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Content-Security-Policy: script-src *.xss.moe/js/ Content-Length: 51 Content-Type: text/html; charset=UTF-8 <script src="//test.xss.moe/js/alert.js"></script>
これは通らない…(´・ω・`)
ちなみにChromeとFirefoxだと3つ全て通るので、Safariだけ不思議な感じ。 想定されるポリシーより緩くなっているわけではなく、想定されるポリシーよりむしろ安全な方に倒れているのでCSPとしての役割はきちんと果たしてる。 ただまぁ開発とかでハマると厄介そうなので一応書き残しておく。