PatchPingsAI-Powered
HomeFeaturesMonitoringPricingHow it worksFAQ
Download free
PatchPings

Secure. Monitor. Fix.

AI-powered website monitoring & audits

Product

  • Features
  • Monitoring
  • Scans
  • DMARC checker
  • SSL checker
  • Pricing
  • FAQ

Company

  • About
  • Knowledge Base
  • Contact

Install

  • Lens
  • WordPress
GET IT ONGoogle Play
PrivacyExtension privacyCookiesTermsAcceptable useDelete account

© 2026 PatchPings by CodenVibe IT LLC. All rights reserved.

PatchPings

Secure. Monitor. Fix.

AI-powered website monitoring & audits

Install

  • Lens
  • WordPress
GET IT ONGoogle Play

Product

  • Features
  • Monitoring
  • Scans
  • DMARC checker
  • SSL checker
  • Pricing
  • FAQ

Company

  • About
  • Knowledge Base
  • Contact

© 2026 PatchPings by CodenVibe IT LLC. All rights reserved.

PrivacyExtension privacyCookiesTermsAcceptable useDelete account
PatchPings

Secure. Monitor. Fix.

AI-powered website monitoring & audits

Product

  • Features
  • Monitoring
  • Scans
  • DMARC checker
  • SSL checker
  • Pricing
  • FAQ

Company

  • About
  • Knowledge Base
  • Contact

Install

  • Lens
  • WordPress
  • GET IT ONGoogle Play

© 2026 PatchPings by CodenVibe IT LLC. All rights reserved.

PrivacyExtension privacyCookiesTermsAcceptable useDelete account
  1. Home
  2. /
  3. Knowledge Base
  4. /
  5. CSP Nonces Explained
Dev guides 4 min readOct 19, 2026

CSP Nonces Explained: Safer Inline Scripts

Content-Security-Policy nonces let you allow specific inline scripts without opening unsafe-inline. Learn how nonces work, how they differ from hashes, and rollout tips.

The PatchPings Team
Source code editor scene representing CSP nonce-based inline script allow-listing

A CSP nonce is a random, unguessable value your server generates per response and places on both the Content-Security-Policy header and the inline <script> tags you intentionally trust. Browsers run only those inline scripts that carry the matching nonce, which removes the need for a blanket 'unsafe-inline'.

Nonces are one of the cleanest ways to tighten CSP on apps that still need a small amount of inline bootstrapping. For broader CSP setup, see the Content-Security-Policy setup guide.

How a nonce flows through a request

  1. 1Server generates a cryptographically strong random string for this response only.
  2. 2Server sends Content-Security-Policy including script-src 'nonce-…'.
  3. 3Server renders trusted inline scripts as <script nonce="…">.
  4. 4Browser executes matching nonced scripts and blocks others.
Header and matching scriptcode
Content-Security-Policy: default-src 'self'; script-src 'nonce-rAnd0m123' 'strict-dynamic'
<script nonce="rAnd0m123">window.__BOOT=true</script>

Nonces vs hashes

  • Nonces change every response; ideal when inline content varies or is templated.
  • Hashes ('sha256-…') allow a fixed inline block by content fingerprint; ideal for rare static snippets.
  • `'strict-dynamic'` lets nonced or hashed scripts load additional scripts, which simplifies modern bundles when used carefully.
Never reuse a nonce across users

A nonce must be unique per response (or at least unpredictable). Reusing one static nonce in a config file is equivalent to allowing anyone who learns it to inline scripts.

Framework notes

Many modern frameworks can emit nonces into both the CSP middleware and the HTML template. Wire the same request-scoped value through; do not hardcode an example string from documentation into production.

Roll out without breaking the UI

  1. 1Start with Content-Security-Policy-Report-Only and collect violations.
  2. 2Add nonces to first-party inline scripts you still need.
  3. 3Remove 'unsafe-inline' once reports are clean.
  4. 4Enforce the policy and monitor with CSP error fixes as a troubleshooting map.

Verify on the live site

View source on a authenticated page and confirm the nonce in the header matches the script attributes. Then run a PatchPings scan to grade CSP presence. Scanners will not invent a nonce for you, but they will show whether CSP is missing, report-only, or overly permissive.

Nonces turn CSP from a blunt 'unsafe-inline' switch into a precise allow-list. Generate them per response, keep them out of static config, and pair them with the rest of your XSS defences from clickjacking, XSS and CSRF explained.

#CSP#Nonce#XSS#Headers

Keep reading

Developer monitor showing configuration work for a Content-Security-Policy rollout
Dev guides

Content Security Policy Setup: Staged Rollout Without Breaking Your Site

2 min read
Code editor context for diagnosing Content-Security-Policy console errors
Dev guides

How to Fix Content-Security-Policy Errors

2 min read
Dark abstract threat surface representing common browser-based web attacks
Security

What Is Clickjacking? XSS and CSRF Explained

2 min read
PatchPings

Start scanning. It’s free.

Download PatchPings and run your first full security scan in under a minute. No credit card, no catch.

GET IT ONGoogle Play

Free for all signed-in users · Guest mode available · v1.0.0