FAQ-000201 - CSRF and DML Security Issues / General CSRF Prevention and Best Practices

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
What design patterns can maintain good user experience while meeting CSRF protection requirements?
Answer
To maintain a good user experience while meeting CSRF protection requirements, consider these design patterns: 1. **Enable CSRF Token Protection**: For Visualforce pages, set the `confirmationTokenRequired` attribute to `true` to ensure GET requests require a CSRF token in the URL. 2. **Trigger State Changes with User Actions**: Avoid automatic state changes or DML operations during initialization. Use explicit user actions, like button clicks, to trigger these operations. 3. **Session-Based CSRF Tokens**: Use a single CSRF token per session to reduce risk, as attackers would need to guess the token within the session window. 4. **Validate Token Entropy**: Ensure CSRF tokens have sufficient entropy to be effective. 5. **Secure Custom Components**: Follow secure coding guidelines for Lightning components to ensure they are safe and enforce proper contracts. 6. **Educate Users**: Provide clear instructions and feedback about actions requiring CSRF tokens to help users understand the security measures without compromising usability. These practices help balance security and user experience effectively.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexCSRFVfCsrf
Question
What design patterns can maintain good user experience while meeting CSRF protection requirements?
Recommended Answer Update
To maintain a good user experience while meeting CSRF protection requirements, consider these design patterns: 1. **Enable CSRF Token Protection**: For Visualforce pages, set the `confirmationTokenRequired` attribute to `true` to ensure GET requests require a CSRF token in the URL. 2. **Trigger State Changes with User Actions**: Avoid automatic state changes or DML operations during initialization. Use explicit user actions, like button clicks, to trigger these operations. 3. **Session-Based CSRF Tokens**: Use a single CSRF token per session to reduce risk, as attackers would need to guess the token within the session window. 4. **Validate Token Entropy**: Ensure CSRF tokens have sufficient entropy to be effective. 5. **Secure Custom Components**: Follow secure coding guidelines for Lightning components to ensure they're safe and enforce proper contracts. 6. **Educate Users**: Provide clear instructions and feedback about actions requiring CSRF tokens to help users understand the security measures without compromising usability. These practices help balance security and user experience effectively.
Reasoning
The FAQ content is accurate and well-structured. The only improvement needed is a minor language refinement in point 5, changing "they are safe" to "they're safe" to follow the brand guidelines for conversational tone using contractions. This makes the content more natural and user-friendly while maintaining all technical accuracy. Regarding security rules: I selected ApexCSRF because this FAQ directly discusses CSRF protection requirements and design patterns, which is exactly what the ApexCSRF rule detects and prevents. The FAQ content about enabling CSRF token protection, triggering state changes with user actions, and session-based CSRF tokens all relate to preventing the Cross-Site Request Forgery vulnerabilities that this rule identifies. I selected VfCsrf because the FAQ specifically mentions Visualforce pages and the `confirmationTokenRequired` attribute, which is directly related to Visualforce CSRF protection that the VfCsrf rule addresses.
Reasoning References