# URL Redirection to Untrusted Site ('Open Redirect') (CWE-601) A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect. **Stack:** Python - Prevalence: 中 覆盖 3 种语言 - Impact: 中 建议审查 - Prevention: 已记录 4 个修复示例 **OWASP:** Broken Access Control (A01:2021-Broken Access Control) - #1 ## Description An open redirect vulnerability occurs when an application takes user input and uses it to redirect the user to a different URL. Attackers can exploit this to redirect users to malicious sites. ## Prevention 基于 1 条 Shoulder 检测规则的 Open Redirect 预防策略。 ### Python Validate redirect URLs against a domain allowlist or use relative paths ## Warning Signs - [MEDIUM] unvalidated redirects using user input ## Consequences - 获取权限 - 绕过保护机制 ## Mitigations - 根据可信域名的允许列表对 URL 进行验证 - 使用映射系统而不是直接使用 URL 参数 - 在重定向到外部站点之前显示警告页面 ## Detection - Total rules: 4 - Languages: go, javascript, typescript, python ## Rules by Language ### Python (1 rules) - **Open Redirect** [MEDIUM]: Detects unvalidated redirects using user input. - Remediation: Validate redirect URLs against an allowlist of permitted domains. ```python from urllib.parse import urlparse ALLOWED_DOMAINS = {"myapp.com"} if urlparse(url).netloc not in ALLOWED_DOMAINS: url = "/" ``` Learn more: https://shoulder.dev/learn/python/cwe-601/open-redirect