CSP ハッシュジェネレーターとは
A CSP hash is a base64-encoded SHA-256, SHA-384, or SHA-512 digest of an inline script or style block's exact content. When you add the hash to your CSP header as script-src 'sha256-...' or style-src 'sha256-...', the browser allows that specific inline code to run while blocking all other inline scripts or styles. This is the most secure alternative to 'unsafe-inline'.
クイックアンサー
Use a CSP hash to allow a specific inline script or style without enabling all inline code with unsafe-inline. The hash is a cryptographic digest of the exact code content — SHA-256 is the standard. Add the hash to your CSP as script-src 'sha256-...' or style-src 'sha256-...'.
制限事項
- The hash is only valid for the exact content hashed. Any whitespace, formatting, or content change produces a completely different hash and breaks the CSP allowlist.
- Some build tools and HTML minifiers may modify inline whitespace in production, invalidating hashes generated from development code. Verify against production output.
- CSP hashes do not work with inline event handlers (onclick, onerror) without enabling unsafe-hashes, which weakens security significantly.
使い方
- Copy the exact inline script or style content from your HTML — every space, newline, and indent must match.
- Paste it into the text area and select the hash algorithm.
- Copy the hash value and add it to your CSP header or meta tag as part of script-src or style-src.
主な用途
- Allow a specific inline script for a critical-path loader or analytics snippet without enabling all inline scripts.
- Allow a small inline style block for above-the-fold critical CSS while a stylesheet loads.
- Upgrade an existing CSP that uses unsafe-inline to hash-based allowlisting for stronger security.