Protect Your App from Open Redirect Vulnerabilities
Protect against open redirect vulnerabilities by following the security guidelines consistently across Visualforce, Aura, and Lightning Web Components.
Follow Navigation Security Guidelines
Validate every redirected destination before navigation. Use multiple validation and security checks instead of relying on a single check.
Use only trusted destinations instead of trying to block malicious ones.
Use internal relative paths, such as /lightning/..., instead of full external URLs.
Treat values stored in the database as unreliable. Because database fields can be populated via APIs, imports, integrations, or user input, validate them before use.
Validate all inputs used for navigation, including URL parameters, @api properties, wire data, and page state. For example, a component can receive a URL through the Lightning Message Service and use it directly for navigation.
Treat redirectUrl as untrusted input and validate it before navigation to prevent redirects to malicious external websites.
Don’t rely on NavigationMixin for URL safety, as it doesn’t validate destinations automatically, especially with standard__webPage.
Validate all data sources used for navigation or redirection, such as URL query parameters, database fields, @api component properties, user input fields, page state (CurrentPageReference), wire service data, Apex responses, and Lightning Message Service payloads.
Note
Secure Visualforce Pages
Secure your Visualforce pages by validating PageReference targets. Make sure that they point only to intended destinations and are validated. Don’t use query parameters directly in a PageReference as users can control them and these parameters can then be used to redirect to external URLs.
Always validate database fields. If an attacker can influence stored values, the redirect destination becomes attacker controlled.
Note
1// VULNERABLE2public PageReference redirect(){3 Account acc = [4 SELECT Redirect_URL__c5 FROM Account6 WHERE Id = :recordId7];8 return new PageReference(acc.Redirect_URL__c);9}
Restrict navigation to internal relative paths. Verify that the URL starts with a ’/’ character to reject external URLs before the redirect occurs. Here’s a secure PageReference validation.
1public PageReference redirect(){2 String url = ApexPages.currentPage().getParameters().get('redirectUrl');34 // Reject navigation if the URL is blank or not a relative path5 if(String.isBlank(url) || !url.startsWith('/')){6 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Invalid redirect URL.'));7 return null;8}9 return new PageReference(url);10}
Secure Aura Components
Protect your Aura components from unauthorized window.location assignments. Avoid unvalidated attribute assignments because component attributes are influenced by external inputs and aren’t validated before use. These attributes give navigation control to attackers and can redirect users to malicious sites.
Verify that the destination is a relative URL before assignment. Verify that the URL starts with a ’/’ character to reject external URLs before the redirect occurs.
1// Enforce internal relative URLs2if(url && url.startsWith('/')){3 window.location.href = url;4}else{5 // Display an error message or take corrective action6}
Secure Lightning Web Components
Rely on platform-managed routing in LWC to eliminate the risks associated with manual URL handling. Treat data from @api properties or CurrentPageReference.state as untrusted because it originates from external sources. Don’t use this data directly in a standard__webPage navigation type.
1//Vulnerable: Tainted @api Property Used for Navigation23@api redirectUrl;45this[NavigationMixin.Navigate]({6 type: 'standard__webPage',7 attributes:{8 url: this.redirectUrl9}10});
Standard navigation types avoid direct URL handling entirely and rely on Salesforce platform-managed routing and access control. This eliminates the risk of open redirects caused by user-controlled URLs.
Avoid using CurrentPageReference.state values from URL parameters as these values are controlled by users. Direct navigation with these values can cause open redirect vulnerabilities.
Restrict navigation to specific internal paths or modules by using a regex allowlist. For example, allow only /lightning/, /apex/, or /s/ routes.
Eliminate attacker influence over the redirect destination by hard coding targets that don’t depend on user input.
Reduce open redirect risks by using platform-managed routing. Avoid standard__webPage whenever possible. Use standard types, such as standard__recordPage, standard__objectPage, and standard__navItemPage.
Secure your navigation by combining these validation layers:
Null or empty checks: Verify that data exists before processing.
Input type validation: Perform string and format checks.
Relative URL enforcement: Ensure URLs start with /.
Allowlist validation: Use when specific paths are required.
Security logging: Log rejected navigation attempts for review.
Use static analysis tools, such as Salesforce Code Analyzer, as part of your security review process. Perform manual validation to confirm data flow and eliminate false positives.