# Preventing UI and data access vulnerabilities

*Platform Developer Study Guide · User Interface · Last updated October 26, 2026 · https://www.certifyforce.com/study-guide/platform-developer/user-interface/preventing-ui-and-data-access-vulnerabilities*

How to make Apex behind Lightning components and Visualforce respect object, field and record access (user mode, stripInaccessible, sharing keywords), and how to stop SOQL injection, cross-site scripting and CSRF in the UI.

- Certification: Salesforce Platform Developer
- Exam section: User Interface
- Study guide: https://www.certifyforce.com/study-guide/platform-developer

**Official exam objective:**

> Given a scenario, prevent user interface and data access security vulnerabilities.

## What the exam expects

- For Apex behind a Lightning component, flow or Visualforce page, pick what enforces record access (sharing keywords), object and field access (user mode, `WITH SECURITY_ENFORCED`, `stripInaccessible`, describe checks), or both, and whether it throws or silently drops fields.
- Predict an entry-point class's sharing mode with an explicit, inherited or omitted declaration.
- Fix SOQL injection with bind variables or `String.escapeSingleQuotes()`, and cross-site scripting with default escaping, `JSENCODE`/`HTMLENCODE` or sanitizing base components.
- Recognize built-in protection: standard controllers, Lightning Data Service, anti-CSRF tokens, Lightning Web Security.

**Key terms.** *System mode*: Apex's default before API 67.0, ignoring the running user's object and field permissions. *User mode*: a database operation that applies the running user's object permissions, field-level security (FLS) and sharing. *CRUD/FLS*: object and field permissions. *SOQL injection*: user input that changes a dynamic query's logic. *XSS*: attacker-supplied script executed in another user's browser.

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Apex default | System mode before API 67.0 (running user's object permissions and FLS ignored); user mode at API 67.0 and later | [Enforce Object and Field Permissions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm), [Release note](https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&language=en_US&release=262&type=5) |
| Sharing keywords scope | Record access only; object access and FLS are never enforced by the sharing mode | [Sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm) |
| Omitted declaration, LWC `@AuraEnabled` entry | Defaults to with sharing; Visualforce controller, REST and async default to without sharing | [Sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm) |
| `WITH USER_MODE` | Enforces object permissions, FLS and sharing; finds all FLS errors, not just the first | [Enforce User Mode](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm) |
| `WITH SECURITY_ENFORCED` | Checks SELECT and FROM fields only, throws `System.QueryException`, Apex only; removed as of API 67.0 | [WITH SECURITY_ENFORCED](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_enforced.htm), [Release note](https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&language=en_US&release=262&type=5) |
| `stripInaccessible` | Removes inaccessible fields without an exception; never strips Id; no AggregateResult | [stripInaccessible](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_stripInaccessible.htm) |
| User-mode DML | `insert as user` or `Database.insert(recs, AccessLevel.USER_MODE)` throws on missing FLS | [Enforce User Mode](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm) |
| Custom Visualforce controller | Runs entirely in system mode at API 66.0 and earlier; standard controller logic runs in user mode | [Custom Controllers and Extensions](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-controller-def.html), [Release note](https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&language=en_US&release=262&type=5) |
| LDS base components and `lightning/ui*Api` | UI API responses respect CRUD, FLS and sharing | [Lightning Data Service](https://developer.salesforce.com/docs/platform/lwc/guide/data-ui-api.html) |
| Dynamic SOQL that can't use binds | `String.escapeSingleQuotes()` on the user input | [SOQL Injection](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-security-tips-soql-injection.html) |

## Check yourself

- Why doesn't `with sharing` stop a component from showing a field hidden by FLS?
- When should you choose `Security.stripInaccessible` over `WITH USER_MODE`?
- When is the Visualforce anti-CSRF token bypassed?
- Which encoding function protects a merge field written into a Visualforce JavaScript string?

## Sources

- [Enforce User Mode for Database Operations](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm)
- [Use the with sharing, without sharing, and inherited sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm)
- [Database Operations Run in User Mode by Default, Not System Mode](https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&language=en_US&release=262&type=5)
- [Enforce Object and Field Permissions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm)
- [Enforce Security with the stripInaccessible Method](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_stripInaccessible.htm)
- [Filter SOQL Queries Using WITH SECURITY_ENFORCED](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_enforced.htm)
- [SOQL Injection](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-security-tips-soql-injection.html)
- [Cross Site Scripting (XSS)](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-security-tips-xss.html)
- [Unescaped Output and Formulas in Visualforce Pages](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-security-tips-scontrols.html)
- [Cross-Site Request Forgery (CSRF)](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-security-tips-csrf.html)
- [What are Custom Controllers and Controller Extensions?](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-controller-def.html)
- [Lightning Data Service](https://developer.salesforce.com/docs/platform/lwc/guide/data-ui-api.html)
- [lightning-formatted-rich-text](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-formatted-rich-text.html?type=Develop)
- [Lightning Web Security](https://developer.salesforce.com/docs/platform/lightning-components-security/guide/lws-intro.html)
- [Using the runAs Method](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
