FAQ-001581 - SOQL Security and User Mode Implementation / WITH SECURITY_ENFORCED Sufficiency

Current Status:SUGGESTS_CASEErrorUnable to AnswerSuggests Case

Current FAQ

Question
Is using WITH SECURITY_ENFORCED in SOQL queries sufficient for security compliance?
Answer
`WITH SECURITY_ENFORCED` in SOQL queries is not a complete solution for security compliance. Here's what you need to know: **What WITH SECURITY_ENFORCED covers:** - Enforces CRUD (Create, Read, Update, Delete) and FLS (Field-Level Security) checks for fields in the `SELECT` and `FROM` clauses - Provides a step towards security compliance for query-level operations **What WITH SECURITY_ENFORCED does NOT cover:** - Fields in the `WHERE` or `ORDER BY` clauses are not protected - These unprotected fields can still potentially leak sensitive information **Additional requirements for full compliance:** - Manual checks using methods like `isAccessible()` are required for fields in WHERE and ORDER BY clauses - You must perform these additional checks to ensure all sensitive data is protected - Full security compliance requires a combination of `WITH SECURITY_ENFORCED` and manual field accessibility validation **Recommendation:** While `WITH SECURITY_ENFORCED` helps with security compliance, additional manual checks are required to ensure comprehensive protection. For definitive guidance on AppExchange Security Review compliance, consider opening a case with Salesforce. In summary, `WITH SECURITY_ENFORCED` is beneficial but not sufficient on its own for complete security compliance.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexCRUDViolation
Question
Is using WITH SECURITY_ENFORCED in SOQL queries sufficient for security compliance?
Recommended Answer Update
`WITH SECURITY_ENFORCED` in SOQL queries is not a complete solution for security compliance. Here's what you need to know: **What WITH SECURITY_ENFORCED covers:** - Enforces CRUD (Create, Read, Update, Delete) and FLS (Field-Level Security) checks for fields in the `SELECT` and `FROM` clauses - Provides a step towards security compliance for query-level operations **What WITH SECURITY_ENFORCED does NOT cover:** - Fields in the `WHERE` or `ORDER BY` clauses are not protected - These unprotected fields can still potentially leak sensitive information **Modern approach for full compliance:** - Use `WITH USER_MODE` for comprehensive CRUD and FLS enforcement across all query clauses - For legacy compatibility, manual checks using methods like `isAccessible()` remain required for fields in WHERE and ORDER BY clauses when using `WITH SECURITY_ENFORCED` - Full security compliance requires either `WITH USER_MODE` or a combination of `WITH SECURITY_ENFORCED` and manual field accessibility validation **Recommendation:** While `WITH SECURITY_ENFORCED` helps with security compliance, consider `WITH USER_MODE` for comprehensive protection or add manual checks for complete coverage. For definitive guidance on AppExchange Security Review compliance, consider opening a case with Salesforce. In summary, `WITH SECURITY_ENFORCED` is beneficial but not sufficient on its own for complete security compliance.
Reasoning
The FAQ content is accurate but can be improved by incorporating modern security approaches. The content mentions the limitations of `WITH SECURITY_ENFORCED` and recommends manual checks, which is correct but doesn't mention the modern `WITH USER_MODE` approach that automatically handles all query clauses. Per the security approaches guidelines, we should 'prioritize modern features' while not implying legacy approaches are unacceptable. The update adds a brief mention of `WITH USER_MODE` as the modern approach while preserving all existing information about manual checks. I selected the ApexCRUDViolation rule because this FAQ directly addresses CRUD and FLS enforcement in SOQL queries, which is exactly what this rule detects violations for. The FAQ is teaching developers about proper security enforcement in SOQL queries, and the ApexCRUDViolation rule flags code that lacks proper CRUD/FLS checks - making it directly relevant to the security concepts being explained.
Reasoning References
Recommended Related Articles