LoginSignup
9
5

More than 5 years have passed since last update.

Nuxt.jsでCSPを有効にする

Posted at

CSPとは

Content Security Policyの略
ブラウザ側でポリシーに従って読み込みリソースや実行するスクリプトを制限することができる機能です。

nuxtでもCSPのサポートがされているけど、nuxtのドキュメントに載ってなかったのでとりあえずメモ

nuxt.config.jsの設定

nuxt.config.js
const isDev = process.env.NODE_ENV !== 'production'

module.exports = {
    render: {
        csp: {
            enabled: !isDev,
            policies: {
                'default-src': ['self'],
                'script-src': [
                    'https://www.google-analytics.com',
                ],
                'child-src': [
                    'https://www.youtube.com',
                ],
                'report-to': ['/report']
            }
        }
    }
}

ポリシーについてはMozillaのドキュメントを見てみてください

9
5
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
9
5