FAQ-000163 - CSRF and DML Security Issues / CSRF Token Implementation and Validation

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
Should I implement confirmation dialogs to mitigate CSRF security risks?
Answer
Yes, implementing confirmation dialogs is a good practice to mitigate CSRF security risks in Salesforce. Here's how: 1. **Visualforce Pages**: Enable the `confirmationTokenRequired` metadata field to ensure GET requests require a CSRF token in the URL, preventing unauthorized state changes or DML operations during page initialization. 2. **User Interaction**: Require explicit user actions, like button clicks, to trigger state changes or DML operations in Apex controllers for Lightning or LWC components. By requiring user interaction, like clicking a button or confirming an action, you reduce the risk of automated or unauthorized state changes. These measures effectively reduce the risk of CSRF attacks.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexCSRFVfCsrf
Question
Should I implement confirmation dialogs to mitigate CSRF security risks?
Recommended Answer Update
Yes, implementing confirmation dialogs is a good practice to mitigate CSRF security risks in Salesforce. Here's how: 1. **Visualforce Pages**: Enable the `confirmationTokenRequired` metadata field to ensure GET requests require a CSRF token in the URL, preventing unauthorized state changes or DML operations during page initialization. 2. **User Interaction**: Require explicit user actions, like button clicks, to trigger state changes or DML operations in Apex controllers for Lightning or LWC components. By requiring user interaction, like clicking a button or confirming an action, you reduce the risk of automated or unauthorized state changes. These measures effectively reduce the risk of CSRF attacks.
Reasoning
The FAQ content is accurate and well-structured, focusing on proper CSRF mitigation techniques. No significant changes are needed as the information aligns with current security best practices and doesn't conflict with any security rules or guidelines. Regarding related security rules: - **ApexCSRF**: This rule directly relates to the FAQ's core topic of CSRF protection in Apex. The FAQ discusses implementing confirmation dialogs and requiring explicit user actions in Apex controllers, which is exactly what this rule helps detect and prevent - CSRF vulnerabilities in Apex code. - **VfCsrf**: This rule is highly relevant because the FAQ specifically mentions Visualforce pages and the `confirmationTokenRequired` metadata field. The FAQ's recommendation to "enable the confirmationTokenRequired metadata field to ensure GET requests require a CSRF token" directly corresponds to what this Visualforce CSRF rule validates.
Reasoning References
Recommended Related Articles