---
title: "Redirect only to your own pages · Agent Wranglers"
url: https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/block-open-redirects
updated: 2026-10-20
licence: "All rights reserved"
---

# Redirect only to your own pages

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Requests and files](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files)
- Rule: A redirect that takes its target from the address must only go to your own pages or an allow-list.
- How: Accept only paths that start with a single `/`, or IDs that map to known targets. Reject full addresses, `//host`, backslashes and control characters. Attackers use open redirects to make phishing links look trusted.
- Check: The agent sets the return address to an outside site in several forms. Every one lands on the home page or an error.

Example:

```text
/login?next=https://evil.example.net
/login?next=//evil.example.net
/login?next=/\evil.example.net
/login?next=/%09/evil.example.net
```

```js
const isSafeNext = next => typeof next === 'string' && /^\/(?!\/)/.test(next) && !/[\\\x00-\x1f]/.test(next);
res.redirect(isSafeNext(req.query.next) ? req.query.next : '/');
```

```python
def is_safe_next(target: str) -> bool:
    return (target.startswith("/") and not target.startswith("//")
            and not any(ch == "\\" or ord(ch) < 32 for ch in target))

return redirect(target if is_safe_next(target) else "/")
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers security testing playbook: https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/block-open-redirects`.

- Previous: [Keep file paths inside their folder](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/block-path-traversal)
- Next: [Share data across sites on purpose](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/strict-cors)
- [Requests and files](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files)
