Newer Version Available

This content describes an older version of this product. View Latest

CspTrustedSite

Represents a trusted URL. For each CspTrustedSite component, you can specify Content Security Policy (CSP) directives and permissions policy directives. Each CSP directive allows Lightning components, third-party APIs, and WebSocket connections to access a resource type from the trusted URL. If the Permissions-Policy HTTP header is enabled, each permissions policy directive grants the trusted URL access to a browser feature. In API version 58.0 and earlier, CspTrustedSite components included only CSP directives and were referred to as CSP Trusted Sites.

This type extends the Metadata metadata type and inherits its fullName field.

Declarative Metadata File Suffix and Directory Location

CspTrustedSite components are stored in the cspTrustedSites directory of the corresponding package directory. The file name matches the unique name of the trusted site, and the extension is .cspTrustedSite.

Version

CspTrustedSite components are available in API version 39.0 and later.

Fields

Field Field Type Description
canAccessCamera boolean Indicates whether this CspTrustedSite can access the user’s camera (true) or not (false). The default value is false.

This field takes effect only when the enablePermissionsPolicy field equals true and the grantCameraAccess field equals TrustedUrls in the SecuritySettings metadata API type.

This field is available in API version 59.0 and later.

canAccessMicrophone boolean Indicates whether this CspTrustedSite can access the user’s microphone (true) or not (false). The default value is false.

This field takes effect only when the enablePermissionsPolicy field equals true and the grantMicrophoneAccess field equals TrustedUrls in the SecuritySettings metadata API type.

This field is available in API version 59.0 and later.

context CspTrustedSiteContext (enumeration of type string) Declares the scope of the CSP directives for this trusted URL.
  • All—Apply the CSP directives to all supported context types.
  • Communities—Apply the CSP directives to Experience Builder sites only.
  • FieldServiceMobileExtension—Apply the CSP directives to the Field Service Mobile Extensions only. This value is available in API version 47.0 and later.
  • LEX—Apply the CSP directives to Lightning Experience pages only.
  • VisualForce—Apply the CSP directives to custom Visualforce pages only. This value is available in API version 55.0 and later.

For custom Visualforce pages, content is restricted to trusted URLs only if the page’s cspHeader attribute is set to true.

This field is available in API version 44.0 and later.

description string The description of this trusted URL.
endpointUrl string Required. The URL for this CspTrustedSite.

This field must include a domain name and can include a port. For example, https://example.com or https://example.com:8080.

To reduce repetition, you can use the wildcard character * (asterisk). For example, *.example.com. For a third-party API, the URL must begin with https://. For example, https://example.com. For a WebSocket connection, the URL must begin with wss://. For example, wss://example.com.

isActive boolean Required. Indicates whether this CspTrustedSite is active (true) or not (false). The default value is true.
isApplicableToConnectSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load URLs using script interfaces from this trusted URL (true) or not (false). This field has a default value of false.

This field is available in API version 48.0 and later.

isApplicableToFontSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load fonts from this trusted URL (true) or not (false). This field has a default value of false.

This field is available in API version 48.0 and later.

isApplicableToFrameSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load resources contained in <iframe> elements from this trusted URL (true) or not (false). This field has a default value of false.This field is available in API version 48.0 and later.
isApplicableToImgSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load images from this trusted URL (true) or not (false). This field has a default value of false. This field is available in API version 48.0 and later.
isApplicableToMediaSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load audio and video from this trusted URL (true) or not (false). This field has a default value of false.

In API version 59.0 and later, for each trusted URL, at least one CSPTrustedSite starting with isApplicable or canAccess must be set to true.

In API version 50.0 to 58.0, if all isApplicable fields are false, the isApplicableToImgSrc field is set to true. In API version 49.0 and earlier, if all isApplicable fields are false, these fields all default to true.

This field is available in API version 48.0 and later.
isApplicableToStyleSrc boolean Indicates whether Lightning components, third-party APIs, and WebSocket connections can load style sheets from this trusted URL (true) or not (false). This field has a default value of false. This field is available in API version 48.0 and later.
mobileExtension string Reserved for future use.

Declarative Metadata Sample Definition

A sample XML definition of a trusted site is shown below.

1<?xml version="1.0" encoding="UTF-8"?>
2<CspTrustedSite xmlns="http://soap.sforce.com/2006/04/metadata">
3    <canAccessCamera>false</canAccessCamera>
4    <canAccessMicrophone>true</canAccessMicrophone>
5    <description>Used for Lightning component callout to mapping web service</description>
6    <context>LEX</context>
7    <endpointUrl>https://www.maptestsite.net/</endpointUrl>
8    <isActive>true</isActive>
9    <isApplicableToConnectSrc>true</isApplicableToConnectSrc>
10    <isApplicableToFontSrc>true</isApplicableToFontSrc>
11    <isApplicableToFrameSrc>false</isApplicableToFrameSrc>
12    <isApplicableToImgSrc>true</isApplicableToImgSrc>
13    <isApplicableToMediaSrc>false</isApplicableToMediaSrc>
14    <isApplicableToStyleSrc>true</isApplicableToStyleSrc>
15</CspTrustedSite>

Usage

For each CSPTrustedSite component, at least one field starting with grantAccess or isApplicableTo must be set to true.

In API versions 50.0 to 58.0, if all isApplicable fields are false, the isApplicableToImgSrc field is set to true. In API version 49.0 and earlier, if all isApplicable fields are false, those fields all default to true.

To ensure smooth integration across Salesforce products, Salesforce includes URLs in each of the CSP directives that correspond to the isApplicable fields, even though those URLs aren’t defined as CspTrustedSite components. Salesforce regularly updates those URLs based on the latest requirements.

Wildcard Support in the Manifest File

This metadata type supports the wildcard character * (asterisk) in the package.xml manifest file. For information about using the manifest file, see Deploying and Retrieving Metadata with the Zip File.