{"success":true,"name":"only-redirect-users-to-destinations-you-control","description":"Building redirects that use a URL from a parameter or user input.","category":"ai-brimind","path":"ai-brimind/only-redirect-users-to-destinations-you-control/SKILL.md","file":"SKILL.md","content":"---\nname: only-redirect-users-to-destinations-you-control\ndescription: \"Building redirects that use a URL from a parameter or user input.\"\n---\n\n# Only Redirect Users to Destinations You Control\n\n## When to use\nThe app redirects after login or actions using a 'next', 'returnTo', or similar URL parameter, and the target isn't validated.\n\n## Example request\nLogin redirects to whatever ?next= says → phishing email links to YOUR real login with next=evil-site, and the victim lands on a fake page after truly logging in; that trust transfer is the open redirect attack. Validating that the URL 'contains' your domain → evil.com/yourdomain.com passes the check; parse the URL properly instead of string matching. Blocking http:// but forgetting protocol-relative //evil.com → the browser happily follows it; whitelist safe shapes, don't blacklist bad ones. Redirect target also used in emails → the same trick rides your email reputation; the rule covers every place a destination is built from input.\n\n## Instructions\nYou are a redirect gatekeeper who knows your domain's reputation is the product being stolen: an open redirect lets attackers wrap their trap in your trusted URL. Wherever a redirect destination comes from a parameter, form field, or stored value: 1) Prefer the safest design: redirect to internal ROUTES, not URLs — accept only a path like /dashboard, reject anything containing a scheme or host, and prepend your own origin server-side. 2) If external destinations are genuinely needed, keep an explicit whitelist of allowed hosts and compare the properly PARSED hostname against it — never use 'contains' or 'starts with' string checks, which attackers bypass with lookalike paths and subdomains. 3) Know the trick shapes and test them: //evil.com, backslash variants, javascript: URLs, and encoded characters — your validation must reject all of them. 4) Use the framework's or auth library's built-in safe-redirect helper if one exists before writing your own. 5) Apply the same rule everywhere destinations are built from input: post-login flows, logout, email links, share links. Verify by attempting each trick shape against your own endpoint and confirming every one lands on your default page instead. Explain the fix by naming the flaw — open redirect — and describing the phishing chain it just broke.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #466\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}