LoginSignup
10

More than 5 years have passed since last update.

メモ:セキュリティ関係のヘッダ

Last updated at Posted at 2017-04-16

今後のためのメモ。

Twitterウィジェット、GoogleAnalytics、Googleタグマネージャ、Googleフォントを使っている状態の設定。

これをベース設定します。

// XSS攻撃を検知させる(検知したら実行させない)。
header("X-XSS-Protection: 1; mode=block");
// IEにコンテンツの内容を解析させない(ファイルの内容からファイルの種類を決定させない)。
header( "X-Content-Type-Options: nosniff" );
// JavaScriptの実行を許可する対象を 同一オリジンと一部ドメインに制限する
header("Content-Security-Policy: default-src 'self'; ".
       "connect-src 'self'; ".
       "style-src 'self' 'unsafe-inline' *.googleapis.com *.twitter.com *.twimg.com; ".
       "script-src 'self' *.twitter.com *.twimg.com *.googleapis.com *.googletagmanager.com *.google-analytics.com; ".
       "img-src 'self' 'unsafe-inline' data: *.twitter.com *.twimg.com *.google-analytics.com;".
       "font-src 'self' fonts.gstatic.com; ".
       "frame-src 'self' *.twitter.com;"
);

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10