To implement CSRF protection across different Salesforce contexts, follow these methods:
1. **Visualforce Pages**: Enable the `confirmationTokenRequired` boolean metadata field in the Visualforce page settings. When set to `true`, GET requests to the page require a CSRF token in the URL, ensuring the page is inaccessible without the token. Configure this in the Visualforce page settings in the org setup.
2. **Lightning Web Components (LWC) and Aura**: Avoid performing state change or DML operations in an Apex controller during instantiation. Instead, trigger state changes through user actions, like button clicks.
3. **General Practices**: Ensure all form requests and state change operations are triggered by user actions. Avoid executing DML operations on page initialization, as this bypasses the platform's default CSRF protection.
These steps will help effectively mitigate CSRF vulnerabilities in Salesforce environments.