← Back to Blog

SharePoint Online CSP Enforcement: SPFx Developer Guide

Fix SPFx web parts broken by Content Security Policy enforcement: resolve inline scripts, eval calls, and style violations with practical solutions.

SharePoint Online CSP Enforcement: SPFx Developer Guide

Your SPFx Web Part Just Stopped Working

You deploy a SharePoint Framework solution that has been running fine for months. Suddenly, users report a blank web part or broken functionality. You open the browser console and see this:

Refused to execute inline script because it violates the following
Content Security Policy directive: "script-src 'nonce-...'"

This is the result of Microsoft enforcing Content Security Policy headers on SharePoint Online pages. If you have SPFx solutions in production, you need to audit them now.

What Is CSP and Why Microsoft Is Enforcing It

Content Security Policy is an HTTP response header that tells the browser which sources of content are trusted. It prevents cross-site scripting (XSS) attacks by blocking unauthorized inline scripts, eval calls, and resources loaded from untrusted origins.

SharePoint Online has historically been lenient with CSP. That changed as Microsoft moved to harden the platform against supply-chain attacks targeting custom solutions. CSP enforcement gives Microsoft a server-side control to limit what client-side code can do, even in tenant-deployed SPFx packages.

Enforcement Rollout Timeline

DateChangeImpact
June 2025CSP headers added in report-only modeNo breakage; violations logged
October 2025script-src enforcement begins (targeted release tenants)Inline scripts blocked
January 2026script-src and style-src enforcement reaches GA tenantsInline scripts and styles blocked
March 2026Full CSP enforcement including connect-src restrictionsUnauthorized API calls blocked
June 2026 (planned)Strict nonce-based policy for all tenantsOnly nonce-tagged scripts execute

If your tenant is on targeted release, you are already under full enforcement. GA tenants have been catching up since Q1 2026.

What Breaks: Common SPFx Patterns That Violate CSP

Inline Scripts via innerHTML

Setting innerHTML with