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

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
What are the common causes of Cross-Site Request Forgery (CSRF) vulnerabilities in Visualforce pages?
Answer
Common causes of Cross-Site Request Forgery (CSRF) vulnerabilities in Visualforce pages include: 1. **State Changes on Initialization**: Performing state changes or DML operations during page initialization, such as in class constructors or methods called from the `action` parameter of a Visualforce page. This bypasses the platform's default CSRF protection. 2. **CSRF Token Not Required**: Not enabling the `confirmationTokenRequired` boolean metadata field in the Visualforce page settings. Without this, GET requests to the page do not require a CSRF token, leaving it vulnerable. 3. **JavaScript Actions**: Actions submitted via JavaScript, as Visualforce's built-in CSRF protection does not cover these actions. To mitigate these vulnerabilities, enable the `confirmationTokenRequired` field, avoid state changes or DML operations during initialization, and ensure actions are triggered by user interactions.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexCSRFVfCsrf
Question
What are the common causes of Cross-Site Request Forgery (CSRF) vulnerabilities in Visualforce pages?
Recommended Answer Update
Common causes of Cross-Site Request Forgery (CSRF) vulnerabilities in Visualforce pages include: 1. **State Changes on Initialization**: Performing state changes or DML operations during page initialization, such as in class constructors or methods called from the `action` parameter of a Visualforce page. This bypasses the platform's default CSRF protection. 2. **CSRF Token Not Required**: Not enabling the `confirmationTokenRequired` boolean metadata field in the Visualforce page settings. Without this, GET requests to the page don't require a CSRF token, leaving it vulnerable. 3. **JavaScript Actions**: Actions submitted via JavaScript, as Visualforce's built-in CSRF protection doesn't cover these actions. To mitigate these vulnerabilities, enable the `confirmationTokenRequired` field, avoid state changes or DML operations during initialization, and ensure actions are triggered by user interactions.
Reasoning
The existing FAQ content is accurate and comprehensive. I made minor improvements to make the language more conversational by changing 'do not require' to 'don't require' and 'does not cover' to 'doesn't cover', following the brand guidelines to use contractions and be more conversational. These small changes maintain the technical accuracy while making the content more accessible. For security rules selection: - ApexCSRF: This rule directly relates to CSRF vulnerabilities in Apex controllers, which is exactly what the FAQ discusses. The FAQ content about performing state changes during initialization, not requiring CSRF tokens, and JavaScript actions all align with what this rule detects. - VfCsrf: This rule specifically targets CSRF vulnerabilities in Visualforce pages, which is the exact focus of this FAQ. The FAQ's discussion of the confirmationTokenRequired field and Visualforce-specific CSRF protection mechanisms directly corresponds to what this rule addresses.
Reasoning References