An open redirect is when your site agrees to send a visitor to any external address. It usually lives in login parameters such as ?next=, ?return_url= or ?redirect=, which return the user to a page after sign-in. If the site never checks that the target belongs to its own domain, anyone can craft a link that starts with example.uz and ends somewhere else. Nothing breaks on the server, which is why the bug looks harmless, yet the trusted domain name is exactly what makes it valuable to scammers.
Why a simple redirect is dangerous
People are taught to check a link's domain. An open redirect defeats that habit: the link really begins with example.uz, the user clicks, and the site instantly forwards them to a pixel-perfect copy asking them to "log in again". Mail filters and messengers also tend to trust links from reputable domains. The bigger risk is in OAuth and "Sign in with Google" flows: if an allowed return URL contains an open redirect, an authorization code or token can travel along the chain to the attacker, turning phishing into direct account takeover.
What vulnerable code looks like
The problem often fits in one line, where the parameter goes straight into the Location header:
<?php
// login.php : VULNERABLE
if (login_ok($_POST['user'], $_POST['pass'])) {
header('Location: ' . $_GET['next']);
exit;
}
Naive checks, such as requiring the string example.uz somewhere in the URL, do not help. Every address below passes such checks and still lands on a foreign site:
https://example.uz/login?next=https://hujumchi.example
https://example.uz/login?next=//hujumchi.example
https://example.uz/login?next=/\hujumchi.example
https://example.uz/login?next=https://example.uz@hujumchi.example
https://example.uz/login?next=https://example.uz.hujumchi.example
A URL starting with // is protocol-relative and opens another host. Browsers treat the backslash as a normal slash. Everything before @ is a username, so the real host follows it, and the last line is simply another domain that contains your name.
The fix: allow only local paths
The safest approach is to accept no external URLs at all. A login page only needs to return users to pages on your own site, so a path beginning with / is enough. This function enforces that and falls back to the home page otherwise:
<?php
function safe_redirect_target(string $url, string $fallback = '/'): string
{
// Only local paths such as /cabinet/orders?id=5 are allowed
if ($url === '' || $url[0] !== '/') {
return $fallback;
}
// "//host" and "/\host" are treated by browsers as another site
if (isset($url[1]) && ($url[1] === '/' || $url[1] === '\\')) {
return $fallback;
}
// Tabs and newlines are stripped by browsers and enable bypasses
if (preg_match('/[\x00-\x1F\x7F]/', $url)) {
return $fallback;
}
return $url;
}
header('Location: ' . safe_redirect_target($_GET['next'] ?? ''));
exit;
If you genuinely need external redirects, for example to a partner shop, pass an identifier such as ?go=partner1 and look it up in a fixed server-side list. Anything not in the list is rejected.
Example: an online course platform in Tashkent
A coding school emails links like example.uz/login?next=/dars/45. One day a Telegram group shares a "free certificate" link that starts with the real domain, so nobody hesitates. The next parameter, however, holds a // address, and the login page forwards students to a fake copy; within days dozens of passwords are stolen. The fix is a few lines: the function above, applied to every redirect, plus password resets and two-factor authentication.
Testing your own site
Search the code for redirects: header('Location: in PHP, redirect( in Laravel, window.location or location.href in JavaScript, and check whether the value comes from the user. Then test it; a protected site should answer every trick with / and keep the normal internal path unchanged:
for t in "https://hujumchi.example" "//hujumchi.example" "/%5Chujumchi.example" "/cabinet"; do
echo "== $t"
curl -s -o /dev/null -D - "https://example.uz/login.php?next=$t" | grep -i '^location'
done
Client-side redirects count too. If JavaScript copies a URL parameter into location.href, that is an open redirect and possibly XSS, since a javascript: value can execute. The same rule applies: accept only paths starting with / but not //. If your site runs on sayt.uz hosting and someone else wrote the code, ask its developer to review it, and keep CMS core and plugins updated.