Skip to content
Back to skills

Csp And Trusted Urls

ASecurity

Configure Content Security Policy via Trusted URLs and CSP Trusted Sites so Lightning, LWR, and LWC can call third-party scripts, APIs, and frame sources. NOT for clickjack configuration.

  • 15 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 1, 2026
ai-agentsrustgospringapisecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add PranavNagrecha/AwesomeSalesforceSkills --skill csp-and-trusted-urls --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Csp And Trusted Urls?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Csp And Trusted Urls
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/pranavnagrecha-csp-and-trusted-urls/badge)](https://www.skillsdirectory.com/skills/pranavnagrecha-csp-and-trusted-urls)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: csp-and-trusted-urls
description: "Configure Content Security Policy via Trusted URLs and CSP Trusted Sites so Lightning, LWR, and LWC can call third-party scripts, APIs, and frame sources. NOT for clickjack configuration."
category: security
salesforce-version: "Spring '25+"
well-architected-pillars:
  - Security
triggers:
  - "script refused to load salesforce csp"
  - "add trusted url for external api"
  - "lwc fetch third party blocked"
  - "csp trusted sites lightning"
tags:
  - csp
  - trusted-urls
  - lightning
inputs:
  - "External URLs the UI must reach"
  - "context (Lightning vs LWR vs Experience)"
outputs:
  - "Trusted URL records with correct context scopes"
dependencies: []
version: 1.0.0
author: Pranav Nagrecha
updated: 2026-04-28
---

# CSP and Trusted URLs

Salesforce enforces strict CSP for Lightning and LWR. External scripts, connect-src targets, and frame-src must be allow-listed via Trusted URLs (Setup → Security → Trusted URLs). This skill maps each context (Lightning Experience, Experience Cloud LWR, Lightning Communities) to the right directive.

## Recommended Workflow

1. Identify the failing directive: connect-src, script-src, img-src, frame-src, font-src.
2. Setup → Trusted URLs → New. Enter the URL, context (Lightning Experience / Experience Cloud LWR / Communities), and check the relevant directive boxes.
3. Reload the page; verify the console CSP violation is gone.
4. Document the external dependency in your architecture diagram + security review.
5. Remove entries quarterly when features are retired.

## Key Considerations

- Trusted URL is per context — a URL trusted in LEX is not automatically trusted in LWR.
- script-src with inline handlers (onclick=) is not allowed; refactor to LWC event listeners.
- Remote Site Settings govern Apex callouts; Trusted URL governs browser-side fetch.
- Salesforce generates a hash for each CSP-allowed script; use the SFDC-provided cdn when possible to reduce allow-list size.

## Worked Examples (see `references/examples.md`)

- *Add Stripe.js to an LWC checkout* — B2C LWR site.
- *Call internal analytics API from Lightning* — LEX dashboard.

## Common Gotchas (see `references/gotchas.md`)

- **Wildcard subdomains** — https://*.corp.com trusts unintended hosts.
- **LWR vs. LEX confusion** — Same URL added for wrong context silently fails.
- **CDN churn** — Script URL changes version and the allow-list breaks.

## Top LLM Anti-Patterns (full list in `references/llm-anti-patterns.md`)

- Using wildcards 'https://*'
- Disabling CSP ('Relaxed CSP') to ship faster
- Allow-listing a script URL without also allow-listing its connect-src dependencies

## Official Sources Used

- Apex Developer Guide — Sharing — https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_understanding.htm
- Salesforce Security Guide — https://help.salesforce.com/s/articleView?id=sf.security.htm
- Shield Platform Encryption — https://help.salesforce.com/s/articleView?id=sf.security_pe_overview.htm
- Session Security Levels — https://help.salesforce.com/s/articleView?id=sf.security_hap_session.htm
- CSP and Trusted URLs — https://help.salesforce.com/s/articleView?id=sf.security_csp_overview.htm
- API Only User Profile — https://help.salesforce.com/s/articleView?id=sf.users_profiles_api_only.htm
- Privacy Center and DSR — https://help.salesforce.com/s/articleView?id=sf.privacy_center_overview.htm

Files in this skill

  • SKILL.md3.4 KB
  • references/examples.md769 B
  • references/gotchas.md691 B
  • references/llm-anti-patterns.md297 B
  • references/well-architected.md928 B
  • scripts/check_csp_and_trusted_urls.py923 B
  • templates/csp-and-trusted-urls-template.md542 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.