Salesforce Decode
Salesforcedecode
Back to questions
LWCAdvancedsecuritylockercsp

Architect LWC security with Locker and CSP considerations

Real World Scenario

Third-party chart library fails in LWC due to Locker Service restrictions on eval and DOM APIs.

Expected Answer

• Use Salesforce-approved libraries or LWS-compatible builds • Lightning Out limited for external hosting with strict CSP • Avoid innerHTML with untrusted content—XSS risk even with Locker • Sanitize dynamic HTML via platform components where possible • CSP nonces and strict script-src in Experience Cloud sites • Security review third-party static resources before upload • Prefer platform lightning-chart or CRM Analytics embed over arbitrary JS libs

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Main difference: use case and scale. Use Salesforce-approved libraries or LWS-compatible builds. Lightning Out limited for external hosting with strict CSP. Pick based on your integration pattern and team capability. Locker is feature not bug—architects select libraries at design time for platform compatibility. Optimize for scale and operational observability.

Architect Perspective

Locker is feature not bug—architects select libraries at design time for platform compatibility.