SSブログ

ツイッターでブックマークレットが使えなくなった件 [メール投稿]



 ツイッターのstatusページでリロードのためのブックマークレットや引用ツイートのためのブックマークレットや、さらにはメールでブログに記事をアップロードするためのブックマークレットや、その他いろいろとブックマークレットを使っていたのだけど、Firefox 40.0にアップデートしてから使えなくなった。
 以前にブログ【Firefoxのブックマークレットが使えないサイトがある】で書いたように、Content Security Policy (CSP) が原因らしいが、それならばと、例えば上のツイートのHTTPヘッダを見てみたら、CSPの所は次のように書いてあった。
Content-Security-Policy: default-src 'self'; connect-src 'self' https://upload.twitter.com https://analytics.twitter.com https://pay.twitter.com https://graph.facebook.com; font-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com https://fonts.gstatic.com https://maxcdn.bootstrapcdn.com https://netdna.bootstrapcdn.com data:; frame-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com twitter: https://www.youtube.com https://vine.co https://upload.twitter.com https://platform.twitter.com https://syndication.twitter.com https://s-static.ak.facebook.com https://www.facebook.com https://pay.twitter.com; img-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com blob: https://syndication.twitter.com https://www.google.com https://www.google-analytics.com https://stats.g.doubleclick.net https://www.facebook.com https://graph.facebook.com https://fbcdn-profile-a.akamaihd.net https://*.fbcdn.net data:; media-sr c 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com blob:; object-src https://twitter.com https://pbs.twimg.com; script-src 'unsafe-inline' 'unsafe-eval' 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com https://platform.twitter.com https://syndication.twitter.com https://analytics.twitter.com https://www.google-analytics.com https://ssl.google-analytics.com https://connect.facebook.net https://cm.g.doubleclick.net https://api.twitter.com https://graph.facebook.com https://www.google.com; style-src 'unsafe-inline' 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com https://fonts.googleapis.com https://maxcdn.bootstrapcdn.com https://netdna.bootstrapcdn.com https://translate.googleapis.com https://platform.twitter.com; report-uri https://twitter.com/i/csp_report?a=NVQWGYLXFVZXO2LGOQ%3D%3D%3D%3D%3D%3D&ro=false;

 重要な所は強調文字にしておいたが、「script-src」の所に「unsafe-inline」がある。これが含まれていれば、ブックマークレットが使えるんじゃないかと思っていたのだが、私の勘違いかもしれない。
 最新の【Content Security Policy Level 2】で関係ありそうなところを引用する。
7. Directives

This section describes the content security policy directives introduced in this specification. Directive names are case insensitive.

In order to protect against Cross-Site Scripting (XSS), web application authors SHOULD include:

both the script-src and object-src directives, or
include a default-src directive, which covers both scripts and plugins.

In either case, authors SHOULD NOT include either 'unsafe-inline' or data: as valid sources in their policies. Both enable XSS attacks by allowing code to be included directly in the document itself; they are best avoided completely.

 英語は苦手なのでよく分からないが「unsafe-inline」を含めるべきじゃないと書いてあるような気がする。
7.15. script-src

The script-src
directive restricts which scripts the protected resource can execute. The directive also controls other resources, such as XSLT style sheets [XSLT], which can cause the user agent to execute script. The syntax for the name and value of the directive are described by the following ABNF grammar:

directive-name = "script-src"
directive-value = source-list

The term allowed script sources
refers to the result of parsing the script-src directive’s value as a source list if the policy contains an explicit script-src, or otherwise to the default sources.

If 'unsafe-inline' is not in the list of allowed script sources, or if at least one nonce-source or hash-source is present in the list of allowed script sources:

Whenever the user agent would execute an inline <script> from a script element that lacks a valid nonce and lacks a valid hash for the allowed script sources, instead the user agent MUST NOT execute script, and MUST report a violation.
Whenever the user agent would execute an inline script from an inline event handler, instead the user agent MUST NOT execute script, and MUST report a violation.
Whenever the user agent would execute script contained in a javascript URL, instead the user agent MUST NOT execute the script, and MUST report a violation.

 よく分からない。
 それで、ページ内をbookmarkletで検索したら次のように書いてあった。
Note: User agents may allow users to modify or bypass policy enforcement through user preferences, bookmarklets, third-party additions to the user agent, and other such mechanisms.

 Google翻訳では次のようになる。
注:ユーザーエージェントは、ユーザーがユーザーの好み、ブックマークレット、ユーザエージェントに、サードパーティ製の追加、および他のそのような機構を介して変更またはバイパスポリシーの適用を可能にすることができます。

 ブックマークレットを使っている場合はCSPを無視させてもいいよ、と読めるのだけど、「may allow」であって、無視させることを推奨してないみたいだから、Firefoxとしては、無視しないことにしたのだろう。
 それで、ツイッターのHTTPヘッダの「script-src」に「unsafe-inline」があるけれど、これを無視することにしたのだろう。
 あっ、そもそも「unsafe-inline」の意味が分かってない。

 結論。よく分からない。とにかく、これはツイッターのHTTPヘッダのCSPの所に何が書いてあったかメモしたかっただけ。
nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:moblog

nice! 0

コメント 0

コメントを書く

お名前:[必須]
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。