Last active
August 29, 2015 14:10
-
-
Save yukisov/489f4d5916862f67dca1 to your computer and use it in GitHub Desktop.
HTTP response headers for security by PHP
This file contains 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 characters
<?php | |
// セッションクッキーに httponly 属性を設定 | |
ini_set('session.cookie_httponly', 1); | |
// セッションクッキーに secure 属性を設定 | |
ini_set('session.cookie_secure', 1); | |
session_start(); | |
// JavaScriptの実行を許可する対象を 同一オリジンと code.jquery.com と maxcdn.bootstrapcdn.com に制限する | |
header("Content-Security-Policy: default-src 'self'"); // デフォルト設定 | |
header("Content-Security-Policy: script-src 'self' code.jquery.com maxcdn.bootstrapcdn.com"); | |
// XSS攻撃を検知させる(検知したら実行させない)。 | |
header("X-XSS-Protection: 1; mode=block"); | |
// IEにコンテンツの内容を解析させない(ファイルの内容からファイルの種類を決定させない)。 | |
header("X-Content-Type-Options: nosniff"); | |
// IEでダウンロードしたファイルを直接開かせない。 | |
header("X-Download-Options: noopen"); | |
// このページを iframe に埋め込ませない | |
header("X-Frame-Options: DENY"); | |
if ($_SERVER['HTTPS'] != '') { // HTTPSアクセスの場合 | |
// このサイトへのアクセスを HTTPS に制限する | |
header("Strict-Transport-Security: max-age=31536000; includeSubDomains"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment