[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79QJSN6YSB0Z7WG94Z8QEVX":3,"skill-same:01M79QJSN6YSB0Z7WG94Z8QEVX":43},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":13,"repositoryHtmlUrl":25,"repositoryHomepageUrl":6,"ownerHtmlUrl":26,"ownerBlogUrl":6,"ownerDescription":27,"updatedAt":28,"install":29,"resources":42},"01M79QJSN6YSB0Z7WG94Z8QEVX","unvalidated-redirects-and-forwards-cheat-sheet",null,"JunMystery\u002FAgent-Guidance","JunMystery","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F161468934?v=4","01M79MTMV8F0BY8NK1A92RA8A0","Jun","01M79MTMWCFBKPHN5B25E6V20B",0,"MIT","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Funvalidated-redirects-and-forwards-cheat-sheet\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"# Unvalidated Redirects and Forwards Cheat Sheet\n\n## Introduction\n\nUnvalidated redirects and forwards are possible when a web application accepts untrusted input that could cause the web application to redirect the request to a URL contained within untrusted input. By modifying untrusted URL input to a malicious site, an attacker may successfully launch a phishing scam and steal user credentials.\n\nBecause the server name in the modified link is identical to the original site, phishing attempts may have a more trustworthy appearance. Unvalidated redirect and forward attacks can also be used to maliciously craft a URL that would pass the application's access control check and then forward the attacker to privileged functions that they would normally not be able to access.\n\n## Safe URL Redirects\n\nWhen we want to redirect a user automatically to another page (without an action of the visitor such as clicking on a hyperlink) you might implement a code such as the following:\n\nJava\n\n```java\nresponse.sendRedirect(\"http:\u002F\u002Fwww.mysite.com\");\n```\n\nPHP\n\n```php\n\u003C?php\n\u002F* Redirect browser *\u002F\nheader(\"Location: http:\u002F\u002Fwww.mysite.com\");\n\u002F* Exit to prevent the rest of the code from executing *\u002F\nexit;\n?>\n```\n\nASP .NET\n\n```csharp\nResponse.Redirect(\"~\u002Ffolder\u002FLogin.aspx\")\n```\n\nRails\n\n```ruby\nredirect_to login_path\n```\n\nRust actix web\n\n```rust\n  Ok(HttpResponse::Found()\n        .insert_header((header::LOCATION, \"https:\u002F\u002Fmysite.com\u002F\"))\n        .finish())\n```\n\nIn the examples above, the URL is being explicitly declared in the code and cannot be manipulated by an attacker.\n\n## Dangerous URL Redirects\n\nThe following examples demonstrate unsafe redirect and forward code.\n\n### Dangerous URL Redirect Example 1\n\nThe following Java code receives the URL from the parameter named `url` ([GET or POST](https:\u002F\u002Fdocs.oracle.com\u002Fjavaee\u002F7\u002Fapi\u002Fjavax\u002Fservlet\u002FServletRequest.html#getParameter-java.lang.String-)) and redirects to that URL:\n\n```java\nresponse.sendRedirect(request.getParameter(\"url\"));\n```\n\nThe following PHP code obtains a URL from the query string (via the parameter named `url`) and then redirects the user to that URL. Additionally, the PHP code after this `header()` function will continue to execute, so if the user configures their browser to ignore the redirect, they may be able to access the rest of the page.\n\n```php\n$redirect_url = $_GET['url'];\nheader(\"Location: \" . $redirect_url);\n```\n\nA similar example of C\\# .NET Vulnerable Code:\n\n```csharp\nstring url = request.QueryString[\"url\"];\nResponse.Redirect(url);\n```\n\nAnd in Rails:\n\n```ruby\nredirect_to params[:url]\n```\n\nRust actix web\n\n```rust\n  Ok(HttpResponse::Found()\n        .insert_header((header::LOCATION, query_string.path.as_str()))\n        .finish())\n```\n\nThe above code is vulnerable to an attack if no validation or extra method controls are applied to verify the certainty of the URL. This vulnerability could be used as part of a phishing scam by redirecting users to a malicious site.\n\nIf no validation is applied, a malicious user could create a hyperlink to redirect your users to an unvalidated malicious website, for example:\n\n```text\n http:\u002F\u002Fexample.com\u002Fexample.php?url=http:\u002F\u002Fmalicious.example.com\n```\n\nThe user sees the link directing to the original trusted site (`example.com`) and does not realize the redirection that could take place\n\n### Dangerous URL Redirect Example 2\n\n[ASP .NET MVC 1 & 2 websites](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Faspnet\u002Fmvc\u002Foverview\u002Fsecurity\u002Fpreventing-open-redirection-attacks) are particularly vulnerable to open redirection attacks. In order to avoid this vulnerability, you need to apply MVC 3.\n\nThe code for the LogOn action in an ASP.NET MVC 2 application is shown below. After a successful login, the controller returns a redirect to the returnUrl. You can see that no validation is being performed against the returnUrl parameter.\n\nASP.NET MVC 2 LogOn action in `AccountController.cs` (see Microsoft Docs link provided above for the context):\n\n```csharp\n[HttpPost]\n public ActionResult LogOn(LogOnModel model, string returnUrl)\n {\n   if (ModelState.IsValid)\n   {\n     if (MembershipService.ValidateUser(model.UserName, model.Password))\n     {\n       FormsService.SignIn(model.UserName, model.RememberMe);\n       if (!String.IsNullOrEmpty(returnUrl))\n       {\n         return Redirect(returnUrl);\n       }\n       else\n       {\n         return RedirectToAction(\"Index\", \"Home\");\n       }\n     }\n     else\n     {\n       ModelState.AddModelError(\"\", \"The user name or password provided is incorrect.\");\n     }\n   }\n\n   \u002F\u002F If we got this far, something failed, redisplay form\n   return View(model);\n }\n```\n\n### Dangerous Forward Example\n\nWhen applications allow user input to forward requests between different parts of the site, the application must check that the user is authorized to access the URL, perform the functions it provides, and it is an appropriate URL request.\n\nIf the application fails to perform these checks, an attacker crafted URL may pass the application's access control check and then forward the attacker to an administrative function that is not normally permitted.\n\nExample:\n\n```text\nhttp:\u002F\u002Fwww.example.com\u002Ffunction.jsp?fwd=admin.jsp\n```\n\nThe following code is a Java servlet that will receive a `GET` request with a URL parameter named `fwd` in the request to forward to the address specified in the URL parameter. The servlet will retrieve the URL parameter value [from the request](https:\u002F\u002Fdocs.oracle.com\u002Fjavaee\u002F7\u002Fapi\u002Fjavax\u002Fservlet\u002FServletRequest.html#getParameter-java.lang.String-) and complete the server-side forward processing before responding to the browser.\n\n```java\npublic class ForwardServlet extends HttpServlet\n{\n  protected void doGet(HttpServletRequest request, HttpServletResponse response)\n                    throws ServletException, IOException {\n    String query = request.getQueryString();\n    if (query.contains(\"fwd\"))\n    {\n      String fwd = request.getParameter(\"fwd\");\n      try\n      {\n        request.getRequestDispatcher(fwd).forward(request, response);\n      }\n      catch (ServletException e)\n      {\n        e.printStackTrace();\n      }\n    }\n  }\n}\n```\n\n## Preventing Unvalidated Redirects and Forwards\n\nSafe use of redirects and forwards can be done in a number of ways:\n\n- Simply avoid using redirects and forwards.\n- If used, do not allow the URL as user input for the destination.\n- Where possible, have the user provide short name, ID or token which is mapped server-side to a full target URL.\n    - This provides the highest degree of protection against the attack tampering with the URL.\n    - Be careful that this doesn't introduce an enumeration vulnerability where a user could cycle through IDs to find all possible redirect targets\n- If user input can’t be avoided, ensure that the supplied **value** is valid, appropriate for the application, and is **authorized** for the user.\n- For local return URLs, use a framework helper that rejects non-local destinations, such as [ASP.NET Core LocalRedirect or IsLocalUrl](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fsecurity\u002Fpreventing-open-redirects?view=aspnetcore-10.0).\n- If external destinations are required, allow-list explicitly approved destinations using the parsed URL components, as described below.\n- Force all redirects to first go through a page notifying users that they are going off of your site, with the destination clearly displayed, and have them click a link to confirm.\n\n### Validating URLs\n\nUse a maintained URL parser compatible with the redirect API and browser URL interpretation. Compare the parsed scheme, canonical host, and effective port against an explicit allowlist; constrain the path when only specific endpoints are permitted. Reject userinfo and ambiguous input, and redirect using the validated URL rather than transforming it afterward. Do not use raw prefix or suffix matching: [GitLab demonstrates how userinfo and misleading hostnames bypass such checks](https:\u002F\u002Fdocs.gitlab.com\u002Fdevelopment\u002Fsecure_coding_guidelines\u002Fruby\u002F#feature-specific-mitigations). A server-side mapping from an approved destination ID remains preferable to accepting arbitrary URLs.\n\n## References\n\n- [CWE Entry 601 on Open Redirects](https:\u002F\u002Fcwe.mitre.org\u002Fdata\u002Fdefinitions\u002F601.html)\n- [Microsoft: Prevent Open Redirect Attacks in ASP.NET Core](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Faspnet\u002Fcore\u002Fsecurity\u002Fpreventing-open-redirects?view=aspnetcore-10.0)\n",{},"main","5d0a87185c0e172c3901e2a6e5916b6d544b8b94","skills\u002Funvalidated-redirects-and-forwards-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance","https:\u002F\u002Fgithub.com\u002FJunMystery","AI is the typist, I am the architect. Building efficient, secure, and user-centric products through disciplined AI prompt engineering.","2026-11-13 17:41:25",{"source":7,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add JunMystery\u002FAgent-Guidance --skill unvalidated-redirects-and-forwards-cheat-sheet",{"tool":35,"command":36},"bunx","bunx skills add JunMystery\u002FAgent-Guidance --skill unvalidated-redirects-and-forwards-cheat-sheet",{"tool":38,"command":39},"pnpm","pnpm dlx skills add JunMystery\u002FAgent-Guidance --skill unvalidated-redirects-and-forwards-cheat-sheet","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Funvalidated-redirects-and-forwards-cheat-sheet\u002FSKILL.md",true,[],[44,50,56,62,68,74],{"skillNo":45,"name":46,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":47,"categories":48,"keywords":49,"publishedAt":18},"01M79QR1E309VJ6CTQKB32AWWA","zero-trust-architecture-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fzero-trust-architecture-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M79QQV7GHYR02DYGN41S23WN","xss-filter-evasion-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxss-filter-evasion-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M79QQNSN7YB8XB61FFSCS3WH","xs-leaks-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxs-leaks-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M79QQHZZJKFDY9132G5A65C2","xpath-injection-prevention-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxpath-injection-prevention-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M79QQB9ZSD3DJG8658EHQXR1","xml-security-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxml-security-cheat-sheet\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M79QQ60WKV7PFMXWT9CW8PM6","xml-external-entity-prevention-cheat-sheet","https:\u002F\u002Fgithub.com\u002FJunMystery\u002FAgent-Guidance\u002Fblob\u002Fmain\u002Fskills\u002Fxml-external-entity-prevention-cheat-sheet\u002FSKILL.md",[],[]]