Solution:
Root Cause: Security Restrictions Enforcement via DenyAddAndCustomizePages Flag In SharePoint Online, modern sites have the
DenyAddAndCustomizePages (Custom Script) security feature enabled by default. This flag strips permission to execute script-based modifications, upload web parts, edit master pages, or access specific legacy system catalogs (
_catalogs/wp or
_catalogs/solutions). Even a Site Collection Administrator receives Access Denied when attempting these actions if Custom Scripting is blocked.
Diagnostic Verification: 1 Connect via SharePoint Online Management Shell.
2 Query the custom script status on the site:
Copy
powershell
Get-SPOSite -Identity "[https://yourtenant.sharepoint.com/sites/targetsite](https://yourtenant.sharepoint.com/sites/targetsite)" | Select-Object DenyAddAndCustomizePages
3 If DenyAddAndCustomizePages returns Enabled, custom scripting features are blocked.
Step-by-Step Fix: 1 Temporarily Allow Custom Scripting on the Site Collection:
Copy
powershell
Set-SPOSite -Identity "[https://yourtenant.sharepoint.com/sites/targetsite](https://yourtenant.sharepoint.com/sites/targetsite)" -DenyAddAndCustomizePages $false
*(Note: Changes made via PowerShell take effect immediately, whereas GUI setting changes in M365 Admin Center can take up to 24 hours to propagate).*
2 Perform Required Administrative Task:
Complete uploading the web part, updating master pages, or configuring solution settings. 3 Re-enable Custom Scripting Security (Recommended Practice):
Copy
powershell
Set-SPOSite -Identity "[https://yourtenant.sharepoint.com/sites/targetsite](https://yourtenant.sharepoint.com/sites/targetsite)" -DenyAddAndCustomizePages $true
Prevention & Long-Term Monitoring: Utilize modern SharePoint Framework (SPFx) extensions instead of legacy custom script modifications to avoid requiring custom script permissions.