github.com のサイトで delicious bookmarklet を動かしても、モーダルが開いてくれない。これはなんでかなと思っていたら、どうやら Content Security Policy と関連するらしいです。詳しくは Content Security Policyに書かれています。Shortcomings の部分。W3C の仕様的には、Content Security Policy (CSP) が bookmarklet の挙動を阻害するものではないはずだけど、実際には bookmarklet の動作に影響を及ぼしていると。
それで、ついでに Github でどんな CSP の設定がされているのかを見てみました。それがこんな感じ(x-content-security-policy の header)。
- default-src *;
- script-src ‘self’ https://github.global.ssl.fastly.net https://jobs.github.com https://ssl.google-analytics.com https://collector.githubapp.com https://analytics.githubapp.com;
- style-src ‘self’ ‘unsafe-inline’ https://github.global.ssl.fastly.net;
- object-src ‘self’ https://github.global.ssl.fastly.net
policy の内容についてはCSP policy directives - Security | MDNに詳しく書かれています。W3C にもExamplesが書かれています。
default-src の設定は、src の設定がされていない場合に使われます。アスタリスク(*)はMatchingに仕様が書かれてありますが、*のみで設定されている場合はすべての URL が許可の対象となります。
script-src は、Javascript を対象にしていて、‘self’の expression は、Same Origin な URL が許可の対象になります(the set of URIs which are in the same origin as the protected resource)。‘unsafe-inline’や’unsafe-eval’が指定されていないので、インラインスクリプトの挿入や eval の実行ができなくなる。
style-src は、スタイルシートを対象にしていて、‘unsafe-inline’を指定しているので style 要素や style 属性での CSS の指定が可能になっている。style 属性でのスタイルの操作は jQuery でも普通に行われるので、意識的に使わないようにしていないと、unsafe-inline は必要になってくるかなと思われます。
object-src は object、embeded、applet 要素が対象になる。
というメモ。