7.3.4 (L1) Ensure custom script execution is restricted on site collections

Information

This setting controls custom script execution on a particular site (previously called "site collection").

Custom scripts can allow users to change the look, feel and behavior of sites and pages. Every script that runs in a SharePoint page (whether it's an HTML page in a document library or a JavaScript in a Script Editor Web Part) always runs in the context of the user visiting the page and the SharePoint application. This means:

- Scripts have access to everything the user has access to.
- Scripts can access content across several Microsoft 365 services and even beyond with Microsoft Graph integration.

The recommended state is DenyAddAndCustomizePages set to $true

Custom scripts could contain malicious instructions unknown to the user or administrator. When users are allowed to run custom script, the organization can no longer enforce governance, scope the capabilities of inserted code, block specific parts of code, or block all custom code that has been deployed. If scripting is allowed the following things can't be audited:

- What code has been inserted
- Where the code has been inserted
- Who inserted the code

Note: Microsoft recommends using the

SharePoint Framework

instead of custom scripts.

Solution

To remediate using PowerShell:

- Connect to SharePoint Online using Connect-SPOService
- Edit the below and run for each site as needed:

Set-SPOSite -Identity <SiteUrl> -DenyAddAndCustomizePages $true

Note: The property DenyAddAndCustomizePages cannot be set on the MySite host, which is displayed with a URL like https:// tenant id -my.sharepoint.com/

Impact:

None - this is the default behavior.

See Also

https://workbench.cisecurity.org/benchmarks/17682

Item Details

Category: CONFIGURATION MANAGEMENT, SYSTEM AND INFORMATION INTEGRITY

References: 800-53|CM-7, 800-53|CM-7(1), 800-53|SI-7, 800-53|SI-7(1)

Plugin: microsoft_azure

Control ID: fabeac24a07ff9ac3de89bef03329a1f37941571ae2b68122f7b6157bd1a2f6b