FAQ-000264 - CSRF and DML Security Issues / Visualforce CSRF Protection

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
How should CSRF protection be implemented across different invocation methods (inline VF, Lightning, detail buttons)?
Answer
To implement CSRF protection for Visualforce pages invoked via inline VF, Lightning, and detail buttons, follow these steps: 1. **Enable `confirmationTokenRequired`**: Set the `confirmationTokenRequired` boolean metadata field to `true` in the Visualforce page settings. This ensures GET requests to the page require a CSRF token in the URL, making the page inaccessible without it. 2. **Avoid DML on Initialization**: Do not perform state changes or DML operations during the instantiation of Apex controllers for Visualforce pages or components. Trigger these operations through explicit user actions, like button clicks. 3. **Secure Coding Practices**: Ensure methods called from the `action` parameter of a Visualforce page do not execute DML operations on page load. This prevents vulnerabilities from malicious URLs. 4. **Reference Secure Development Resources**: Use resources like the Secure Server-Side Development module on Trailhead and the Metadata API Developer Guide for additional guidance. These practices will help mitigate CSRF vulnerabilities effectively across different invocation methods.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexCSRFVfCsrf
Question
How should CSRF protection be implemented across different invocation methods (inline VF, Lightning, detail buttons)?
Recommended Answer Update
To implement CSRF protection for Visualforce pages invoked via inline VF, Lightning, and detail buttons, follow these steps: 1. **Enable `confirmationTokenRequired`**: Set the `confirmationTokenRequired` boolean metadata field to `true` in the Visualforce page settings. This ensures GET requests to the page require a CSRF token in the URL, making the page inaccessible without it. 2. **Avoid DML on Initialization**: Don't perform state changes or DML operations during the instantiation of Apex controllers for Visualforce pages or components. Trigger these operations through explicit user actions, like button clicks. 3. **Secure Coding Practices**: Ensure methods called from the `action` parameter of a Visualforce page don't execute DML operations on page load. This prevents vulnerabilities from malicious URLs. 4. **Reference Secure Development Resources**: Use resources like the Secure Server-Side Development module on Trailhead and the Metadata API Developer Guide for additional guidance. These practices will help mitigate CSRF vulnerabilities effectively across different invocation methods.
Reasoning
The FAQ content is technically accurate and well-structured. I made minor wording improvements to make it more conversational and direct while preserving all existing points and information. Changes include: 1. Replaced "Do not" with "Don't" to be more conversational 2. Replaced "do not" with "don't" in step 3 for consistency Regarding the selected security rules: - **ApexCSRF**: This rule directly relates to the FAQ's core topic of CSRF protection implementation. The FAQ discusses avoiding DML operations during controller instantiation and on page load, which is exactly what this rule detects - CSRF vulnerabilities in Apex controllers used by Visualforce pages. - **VfCsrf**: This rule specifically targets CSRF issues in Visualforce pages, which is the primary focus of this FAQ. The FAQ's recommendation to enable `confirmationTokenRequired` and avoid DML operations in action parameters directly corresponds to what this rule validates.
Reasoning References