LoginSignup
3
1

More than 3 years have passed since last update.

Amplifyでセキュリティヘッダ(Strict-Transport-Security, X-Frame-Options, X-XSS-Protection, X-Content-Type-Options, Content-Security-Policy)を追加する

Posted at

Amplifyでセキュリティ対策(カスタムヘッダを追加)した際のメモです。
CloudFrontよりお手軽に設定できます。

方法

以下2点のいずれかの方法で設定しましょう。

  1. 設定ファイル追加(customHttp.yml)
  2. Amplify Console

1. 設定ファイル追加(customHttp.yml)

レポジトリのルートディレクトリにcustomHttp.ymlファイルを追加し、commit & push します。
Amplify Consoleでのデプロイアクションの後、指定したヘッダが追加されているのが確認できるでしょう。

./customHttp.yml
customHeaders:
  - pattern: '**/*'
    headers:
      - key: 'Strict-Transport-Security'
        value: 'max-age=31536000; includeSubDomains'
      - key: 'X-Frame-Options'
        value: 'SAMEORIGIN'
      - key: 'X-XSS-Protection'
        value: '1; mode=block'
      - key: 'X-Content-Type-Options'
        value: 'nosniff'
      - key: 'Content-Security-Policy'
        value: 'default-src self'

2. Amplify Console

Amplify Console -> Custom headersに移動します。

スクリーンショット 2021-02-15 13.46.35.jpg

上記、yamlと同等の内容を追加して、保存します。

スクリーンショット 2021-02-15 13.47.38.png

スクリーンショット 2021-02-15 13.53.57.png

(参考) CloudFrontの場合

Lambda@Edgeで対応できますが、Amplifyより手間がかかります。

[CloudFront] Lambda@EdgeでHTTPセキュリティヘッダーを追加する方法

参考サイト

3
1
0

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
3
1