An open redirect occurs when a site accepts a redirect destination from a query parameter, form, cookie, or another external source without checking where that address actually leads. An attacker can create a link to your domain that sends users to a fake login, payment, or file-download page after they click it.
The issue is not limited to WordPress itself. Unsafe logic can appear in custom code, a plugin, a form, an Elementor integration, or a server-side handler. Below is a practical approach to finding, fixing, and testing these scenarios.
Why Open Redirects Are Dangerous
Users see a familiar domain in the initial link and may not notice that they have been redirected to another site. This increases the effectiveness of phishing campaigns, especially when links are sent in the name of a support team or administrator.
An open redirect does not always mean that the site has been fully compromised, but it creates a tool for social engineering. In addition, these URLs can appear in logs, advertising campaigns, emails, and messages, making the damage to the brand's reputation more visible.
Pay particular attention to redirect scenarios after login, logout, password reset, form submission, and returns from payment or other external services.
- redirecting users to a phishing domain through a link on your site;
- concealing malicious destinations in emails and messages;
- targeting administrators with fake authentication pages;
- damaging trust in the domain and brand.
Where to Look for Unsafe Parameters
Start by searching the code of the theme, child theme, custom plugins, and custom integrations. The parameters most commonly used for redirects are redirect_to, return_url, next, redirect, and continue. There is no universal naming standard: a specific plugin may use its own parameter.
Review GET and POST handlers, functions that call wp_redirect(), wp_safe_redirect(), or header('Location: ...'), as well as JavaScript logic using window.location. Also inspect URLs passed through hidden form fields.
In Elementor, the risk may arise in forms, custom post-submission actions, CRM integrations, authentication services, and custom widgets. Check not only the builder page but also the server-side code that processes the submitted data.
- search for the parameters redirect_to, return_url, and next;
- check values from $_GET, $_POST, $_REQUEST, cookies, and Referer;
- find every call to wp_redirect() and every header containing Location;
- review forms used for login, logout, and data submission;
- check integrations in which an external service supplies a return URL.
Why sanitize_text_field() Does Not Solve the Problem
sanitize_text_field() is designed to clean text by removing unwanted characters, tags, and some control constructs. It does not determine whether a URL is internal, belongs to an allowed domain, or is safe to use as a redirect destination.
For example, the seemingly well-formed value https://attacker.example/login may pass text sanitization while remaining dangerous for a redirect. An address should not be considered safe merely because it came from a Referer header or a cookie: these sources are not automatically trusted.
URLs require destination validation. The safest approach is to allow only internal addresses or a limited set of domains and paths. If a function needs only a destination page, do not pass it an arbitrary address supplied by the browser.
- cleaning a string is not the same as validating URL safety;
- encoded characters and unusual URL formats can bypass naive checks;
- the scheme, host, path, and, where necessary, query parameters must be validated;
- external destinations should preferably be constructed explicitly rather than accepted from the user.
How to Validate URLs Correctly in WordPress
Use wp_safe_redirect() for redirects within the site. Unlike the general-purpose wp_redirect(), this function is intended for safer URL handling and takes WordPress's allowed hosts into account. After calling the redirect function, terminate script execution with exit or wp_die() so that subsequent code cannot continue modifying the response.
wp_validate_redirect() helps validate an address and return a fallback if the URL fails validation. However, this may not be sufficient for sensitive scenarios: add your own allowlist of permitted paths or domains, especially when the business logic allows only a few destinations.
The example below permits only internal addresses and restricts redirects to the specified paths. In a real project, adapt the list to the site's logic.
- use wp_safe_redirect() for internal redirects;
- before that, apply wp_validate_redirect() with a safe fallback URL;
- compare the host with the site's domain when accepting absolute URLs;
- create a separate, explicit allowlist for external domains;
- always terminate execution after redirecting.
function webhva_safe_redirect( $target ) {
$fallback = home_url( '/' );
if ( ! is_string( $target ) || $target === '' ) {
wp_safe_redirect( $fallback );
exit;
}
$target = wp_validate_redirect( $target, $fallback );
$parts = wp_parse_url( $target );
$home = wp_parse_url( home_url( '/' ) );
if ( empty( $parts['host'] ) || empty( $home['host'] ) ||
strtolower( $parts['host'] ) !== strtolower( $home['host'] ) ) {
wp_safe_redirect( $fallback );
exit;
}
$allowed_paths = array( '/', '/account/', '/dashboard/' );
$path = isset( $parts['path'] ) ? trailingslashit( $parts['path'] ) : '/';
if ( ! in_array( $path, $allowed_paths, true ) ) {
wp_safe_redirect( $fallback );
exit;
}
wp_safe_redirect( $target );
exit;
}
How to Protect Elementor Forms and Integrations
Do not pass a user-supplied value directly to a post-submission redirect action. If visitors need to be returned to a specific page, it is better to store a short scenario identifier or a predefined path rather than an arbitrary URL.
If an integration genuinely needs to accept a URL, validate it on the server after receiving it. JavaScript-only validation does not protect the site: a request can be sent directly while bypassing browser-side code.
Forms also require standard security measures: verify a nonce where the WordPress logic calls for it, enforce access controls, and sanitize other fields correctly. However, a nonce protects against forged requests; it does not replace destination validation.
- do not treat a hidden form field containing a URL as trusted;
- validate redirects on the server, not only in Elementor or JavaScript;
- keep the page allowlist in code or configuration rather than accepting it from the client;
- use a safe fallback route for post-authentication returns.
Testing After the Fix
Test more than one obvious URL. Check every point where the site may receive a destination address. Perform testing on a copy or in a controlled environment so that real authentication and integration flows are not interrupted.
For each parameter, try an internal address, an absolute address on another domain, an empty value, a URL with a changed host case, encoded characters, and an address with an additional port. The system should either keep the user on an allowed page or send them to a safe fallback.
After making changes, review web-server and application logs. Unusual requests to login, logout, and form pages may indicate that another handler or an alternative parameter remains.
- test the post-login flow;
- test logging out of the user profile and administrative panel;
- test password reset and the return flow after form submission;
- test Elementor and external-service integrations;
- confirm that a prohibited domain does not open, even in encoded form;
- repeat the checks after plugin updates or theme changes.
Frequently asked questions
Is replacing wp_redirect() with wp_safe_redirect() enough?
Not always. It is a better baseline step for internal redirects, but you must also define permitted paths, validate the URL source, and provide a safe fallback. If the logic allows external domains, restrict them explicitly.
Can the redirect_to parameter be trusted after authentication?
No. The redirect_to value comes from the client and must be validated on the server. Allow only internal addresses or a specific list of routes, and use a default page when validation fails.
Does an Elementor form nonce protect against open redirects?
A nonce helps confirm that a request is legitimate, but it does not determine where the user may be redirected. URL validation must be performed separately on the server.
What should I do if a redirect to an external service is required?
Use an allowlist of specific domains and, where necessary, paths. Do not allow an arbitrary host from a GET parameter. For particularly sensitive destinations, consider showing an intermediate warning that names the external domain.
Conclusion
Protection against open redirects begins with cataloging every parameter that affects redirection. Pay particular attention to redirect_to, return_url, and next in WordPress, forms, and Elementor integrations.
Text sanitization does not replace URL validation. Use wp_validate_redirect(), wp_safe_redirect(), an allowlist of permitted routes, and a safe fallback, then test login, logout, form, and integration flows with unsafe destination variants.