CSP Hash-Pinned script-src for Static Sites

    1

    This kit is the hasher, the union, the CI check and the deploy order that make the strict policy safe to keep.

    $29

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    CSP Hash-Pinned script-src for Static Sites

    Example session with this skill installed

    Our Next.js static site behind nginx has script-src locked to hashes with no unsafe-inline. After the last deploy the site loaded but nothing worked until we rolled back. Make deploys safe without loosening the policy.

    • Read your context and instructions
    • Compiled the csp hash-pinned script-src

    Summary

    The outage was the hash list: the new build's inline bootstrap scripts had new hashes and the header still listed the old ones. Added the hash union to the deploy, a CI check that refuses to ship without it, and a browser check after the pointer moves.

    Diagnosis

    node scripts/csp-hashes.mjs check out/ --header-file deploy/csp.txt

    FAIL: the header lacks 3 of 3 inline-script hashes for out/; this build would not hydrate behind that header
      'sha256-Qm9vdHN0cmFw...'  <- index.html, docs/index.html, ...
      'sha256-U2VsZi5fX25l...'  <- index.html
      'sha256-cGFnZURhdGE...'  <- search/index.html
    

    HTTP 200 on every page; zero hydration. Exactly the failure the policy hides.

    Fix in the deploy script

    1. node scripts/csp-hashes.mjs union out/ /srv/releases/current > deploy/script-src.txt (new build plus the rollback release: 5 unique hashes).
    2. Write both Content-Security-Policy add_header lines with that list, nginx -t, reload.
    3. node scripts/csp-hashes.mjs check out/ --header-file deploy/csp.txt -> ok: the header carries all 3 inline-script hashes for out/.
    4. Move /srv/releases/current to the new build.
    5. Playwright: type into the search box, expect results. Passed.

    CI

    The check step runs on every build against the header in the repo; a build whose hashes are not in the header fails the pipeline before anyone can deploy it. A header that still contained 'unsafe-inline' would also fail: with it present the hashes do nothing.

    Monitoring

    A synthetic browser check that performs one real interaction every hour; the uptime check that watched HTTP 200 for a month stays, but it is no longer the only signal.

    Tests

    node --test scripts/csp.test.mjs: 2 passed.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    A strict policy (script-src 'self' plus exact SHA-256 hashes, no unsafe-inline) is the right policy for a static site. It also has a failure mode no HTTP check can see: static exports bootstrap hydration through inline scripts whose hashes change with every build, so a release shipped without updating the header returns 200 on every page while React never hydrates and every interactive element is dead. That ran in production for a month before someone used the search box. This kit is the hasher, the union, the CI check and the deploy order that make the strict policy safe to keep.

    csp-hashes.mjs: list walks a build and prints the 'sha256-...' tokens, hashing inline script text byte for byte as browsers do, skipping JSON-LD and template data blocks, including import maps, with --styles for a hash-pinned style-src and --json for tooling; union merges the new build and the rollback release so a rollback needs no header change; check compares a build against the header string or file you are about to deploy, exits 1 naming every missing hash and the files that carry it, and exits 1 when the header still contains 'unsafe-inline' (which makes the hashes theatre).

    The deploy contract (reference/why-hashes-break-hydration.md): header with the union, config test and reload, then the release pointer, then a real interaction in a browser; a synthetic browser check per deploy and per hour, because status codes cannot see this.

    2 offline tests including the CLI. Node 20+, no packages, no network.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.

    Requires Node 20+. No support for inline event handlers (onclick). Post-hash HTML minification will break the hashes.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 19 days ago

    Software
    Node.js 20+Web server CSP configuration
    Web browser
    orbrowser automation

    You need write access to the server's CSP header configuration. The browser runs the final check.

    Permissions

    Terminal / Shell
    Read Files

    Shell to run the node script and tests; read files for the built static tree, the rollback release and the header file. No writes, no network access, no environment variables.

    Listed19 days ago

    What's inside

    Frequently Asked Questions

    It automates the extraction of SHA-256 hashes from your build files and validates them against your headers, preventing 'silent' hydration failures where a site loads but its interactive elements are blocked by the browser.

    Yes, it includes a 'union' strategy that combines hashes from current and previous builds, ensuring that a rollback doesn't trigger security blocks while the headers catch up.

    This skill is framework-agnostic and works with any static site generator (like Astro, Next.js, or Vite) as long as you are running Node.js 20+ in your environment.

    You receive the `csp-hashes.mjs` tool, the automated CI validation scripts, and a guided implementation workflow for integrating hash extraction into your deployment pipeline.

    This tool is designed to work with any CI/CD agent that supports Node.js execution, acting as a specialized security validator during the build and deployment phases.

    Because browsers require byte-for-byte accuracy for CSP hashes, any HTML minification or rewriting must occur before you run the extraction tool to avoid token mismatches.

    New in LLM Ops