← All results

08 Open redirect

False fixSuper · run 1 · one-shot fix · 423 tokens · 4s

The patch passed the existing tests. The hidden oracle rejected it because ///evil.test/ was still accepted: Python's urlparse reports no host for that form, so the patch treated it as a relative path, and browsers commonly resolve it as a link to another site.

Attack test written by the AI

None. The one-shot baseline writes the patch directly, with no test.

Patch

--- vulnerable app.py
+++ patched app.py
@@ -1,6 +1,25 @@
+from urllib.parse import urlparse
+
ALLOWED_HOST = "example.com"
def safe_redirect_target(target, default="/"):
- # VULNERABLE: any target is accepted, including other sites
- return target or default
+ # Validate that the target is either a relative URL or points to the allowed host.
+ if not target:
+ return default
+
+ try:
+ parsed = urlparse(target)
+ except Exception:
+ return default
+
+ # Relative URL (no netloc) is safe.
+ if not parsed.netloc:
+ return target
+
+ # Only allow URLs whose netloc matches the allowed host (case‑insensitive).
+ if parsed.netloc.lower() == ALLOWED_HOST.lower():
+ return target
+
+ # Anything else is considered unsafe.
+ return default