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
|------|--------|--------|
| June 2025 | CSP headers added in report-only mode | No breakage; violations logged |
|---|
| October 2025 | script-src enforcement begins (targeted release tenants) | Inline scripts blocked |
|---|
| January 2026 | script-src and style-src enforcement reaches GA tenants | Inline scripts and styles blocked |
|---|
| March 2026 | Full CSP enforcement including connect-src restrictions | Unauthorized API calls blocked |
|---|
| June 2026 (planned) | Strict nonce-based policy for all tenants | Only 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
;
`
eval() and new Function()
Both eval()
and new Function()
are blocked by script-src
policies that do not include 'unsafe-eval'
. Some template libraries and older utility packages use these internally.
`
typescript
// BREAKS under CSP
const result = eval('2 + 2');
const dynamicFn = new Function('a', 'b', 'return a + b');
`
Inline Styles via element.style
Setting styles directly through JavaScript properties or setAttribute('style', ...)
violates style-src
when 'unsafe-inline'
is not allowed.
`
typescript
// BREAKS under CSP
element.style.backgroundColor = '#0078d4';
element.setAttribute('style', 'color: red; font-size: 14px;');
`
Dynamic Script Loading
Creating