What are the main security risks in custom Apex and LWC, and how do you prevent them?
Your confidence:Not rated
Model answer
- Access control: Apex runs in system mode. Use
with sharing, user-mode SOQL and DML, and verify the caller may access IDs they pass in. - SOQL injection: bind variables,
Database.queryWithBinds, whitelisted field names. - XSS: LWC escapes by default; avoid
innerHTML/lwc:dom="manual"with untrusted data; encode output in Visualforce. - Secrets: Named and External Credentials; nothing in code, custom settings or logs.
- Guest-accessible code: minimal, validated,
with sharing, returning minimal data. - Third-party JavaScript: Lightning Web Security isolation and minimal CSP Trusted Sites.
- Tooling: Code Analyzer (PMD, ESLint, security rules) in CI, review checklists.
โ Key points to hit
โ Red-flag answers
- 'LWC is secure, so nothing to do'
- Concatenated dynamic SOQL
โช Follow-ups
Does `with sharing` enforce FLS?
No. It enforces record sharing only. Use user mode or Security.stripInaccessible for object and field permissions.
How do you review a managed package's security?
Check its AppExchange security review status, the permissions it requires, its guest and API exposure, and any without sharing entry points it exposes in your org.