3.4.3.2 CSP違反のタイプ

CSP違反のタイプについて学習します。

'unsafe-inline'のCSP違反のタイプは次のとおりです:

  1. インライン・スクリプト・タグ: インライン<script>タグに有効なnonceがない場合に発生します。

    <script>
        console.log('This script will be blocked by CSP because it lacks the correct nonce.');
    </script>
  2. 1.インライン・スタイル属性: style属性がHTML要素で直接使用される場合に発生します。

    <!-- This inline style will be blocked by CSP -->
    <span style="color: blue;">Text</span>
  3. インライン・スタイル・タグ: スクリプト違反と似ていますが、<style>タグまたはインライン・スタイルに関連します。

    <!-- Blocked if no valid nonce is provided -->
    <style>
      body { background-color: red; }
    </style>
  4. インラインJavaScript属性: onclickonmouseoverなどのHTML属性でインラインJavaScriptが使用されている場合にトリガーされます。

    <!-- This will be blocked by CSP -->
    <button onclick="alert('Clicked!')">Click Me</button>
  5. 外部リソース違反: リソース(スクリプト、スタイルなど)が、CSPヘッダーで許可されていないソースからロードされるとブロックされます。

    <!-- Blocked if cdn.example.com is not in the script-src directive -->
    <script src="https://cdn.example.com/library.js"></script>