Skip to content

Commit 1a7989d

Browse files
committed
CSP FAQ
1 parent ba3311c commit 1a7989d

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

docs/spfx/content-securty-policy-trusted-script-sources.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Support for Content Security Policy (CSP) in SharePoint Online
33
description: Learn how SharePoint Online implements Content Security Policy to protect against various attack vectors, and how you can ensure your SharePoint Framework components are valid.
4-
ms.date: 11/17/2025
4+
ms.date: 12/16/2025
55
author: andrewconnell-msft2
66
ms.author: bjansen
77
---
@@ -24,9 +24,6 @@ If the enforcement on March 1, 2026, is too soon because you need more time to r
2424
Set-SPOTenant -DelayContentSecurityPolicyEnforcement $true
2525
```
2626

27-
> [!NOTE]
28-
> This option will be available in the SPO Management Shell version that will be released by the end of November 2025.
29-
3027
## How Content Security Policy Works in SharePoint Online
3128

3229
When a browser requests a script, if CSP is enabled on the site, the browser checks the script location against the CSP rules. If the CSP restrictions allow the location of the script to be loaded by the browser, the browser proceeds with the request. However, if CSP rules to not allow the location, the browser doesn't load the script and logs the error in the browser's Console.
@@ -244,3 +241,76 @@ Selecting a search result opens the side panel with the audit details. Take note
244241
## Testing with CSP Enforced
245242
246243
The enforcement of Content Security Policy (CSP) for SharePoint Online will start from March 1, 2026, but you can already now verify your application's behavior by adding the `csp=enforce` URL parameter to the page containing the SPFx solution you want to test. To enforce CSP in reporting mode, use `csp=report`.
244+
245+
## Frequently Asked Questions
246+
247+
### I need to load the script https://code.jquery.com/jquery-3.6.0.min.js, in what ways can I define this as trusted source?
248+
249+
- The most secure way is qualifying the exact script you want load as then only the specific version of the script can be loaded: `https://code.jquery.com/jquery-3.6.0.min.js`
250+
- If you want to allow all scripts in a specific domain (code.jquery.com) then use `https://code.jquery.com`. Note that `https://code.jquery.com/*` is not working.
251+
- If you want to allow all script sources in specific domain + folder (root folder of code.jquery.com) then use `https://code.jquery.com/`. Note that `https://code.jquery.com/*` is not working.
252+
- If you want to allow all subdomains inside a domain use `*.jquery.com`, this will allow loading anything under `jquery.com`
253+
254+
### I'm hitting the 300 max sources limit, what should I do?
255+
256+
When you hit this limit then the recommendation is to consolidate sources using the model described in the FAQ question above. Note that when the 300 limit is reached uploading new solutions to your app catalog can be impacted. If you're using an automated deployment system with unique script sources per build then the 300 limit can be reached soon, recommended workarounds are:
257+
- Adding script sources in way that cover all versions (see above)
258+
- Automatically removing the auto added scripts sources using the model described below
259+
260+
Currently the logic to auto add script sources will always add the source, even though there's already a source listed that qualifies. This is somthing we're evaluating for fixing.
261+
262+
### Can I update the trusted script sources list using script or code?
263+
264+
Yes, you can update the trusted script sources using SPO Management shell:
265+
266+
```PowerShell
267+
# List current sources
268+
Get-SPOContentSecurityPolicy
269+
270+
# Remove a source
271+
Remove-SPOContentSecurityPolicy -Source "https://cdn.host.com/source/"
272+
273+
# Add a source
274+
Add-SPOContentSecurityPolicy -Source "https://cdn.host.com/source/"
275+
```
276+
277+
Same is also possible using CSOM:
278+
279+
```C#
280+
// cc is the CSOM ClientContext instance you've created for your tenant admin url
281+
Tenant tenant = new Tenant(cc);
282+
283+
// Get trusted sources
284+
var cspTrustedSources = tenant.GetContentSecurityPolicy();
285+
cc.Load(cspTrustedSources);
286+
cc.ExecuteQuery();
287+
288+
// Add trusted source
289+
cspTrustedSources.Add("https://cdn.host.com/source/");
290+
cc.ExecuteQuery();
291+
292+
// Remove trusted source
293+
cspTrustedSources.Remove("https://cdn.host.com/source/");
294+
cc.ExecuteQuery();
295+
```
296+
297+
### Can I still use eval()?
298+
299+
Yes, using `eval()` will stay possible because the 'unsafe-eval' directive is part of the standard CSP header
300+
301+
### Can I get the nonce value to 'allow' my inline script snippets?
302+
303+
No, the nonce value is avaiable for use. Recommendation is to move inline script to script files.
304+
305+
### Does CSP apply to SPFx components hosted on 'classic' pages?
306+
307+
No, when an SPFx web part is hosted on a classic page CSP will not be enforced
308+
309+
### Does CSP apply to the retired SharePoint Add-Ins?
310+
311+
No, CSP does not apply to Add-Ins. Add-Ins will stop working from April 2, 2026.
312+
313+
### Auto populating trusted script sources is not working when an solution is uploaded to a site collection app catalog?
314+
315+
Correct, auto populating of trusted script sources will only apply to solutions uploaded in the tenant app catalog. Currently this only applies to uploading via the modern app catalog (https://contoso-admin.sharepoint.com/_layouts/15/tenantAppCatalog.aspx), we're evaluating bringing this option to the classic app catalog.
316+

0 commit comments

Comments
 (0)