@@ -16,21 +16,53 @@ controlled by the attacker.</p>
1616<p >To guard against untrusted URL redirection, it is advisable to avoid putting user input
1717directly into a redirect URL. Instead, maintain a list of authorized
1818redirects on the server; then choose from that list based on the user input provided.</p >
19-
19+ <p >
20+ If this is not possible, then the user input should be validated in some other way,
21+ for example, by verifying that the target URL is on the same host as the current page.
22+ </p >
2023</recommendation >
24+
25+
2126<example >
27+ <p >
28+ The following example shows an HTTP request parameter being used directly in a URL redirect
29+ without validating the input, which facilitates phishing attacks:
30+ </p >
31+
32+ <sample src =" examples/UrlRedirect.java" />
2233
23- <p >The following example shows an HTTP request parameter being used directly in a URL redirect
24- without validating the input, which facilitates phishing attacks.
25- It also shows how to remedy the problem by validating the user input against a known fixed string.
34+ <p >
35+ One way to remedy the problem is to validate the user input against a known fixed string
36+ before doing the redirection:
2637</p >
2738
28- <sample src =" UrlRedirect.java" />
39+ <sample src =" examples/UrlRedirectGood.java" />
40+
41+ <p >
42+ Alternatively, we can check that the target URL does not redirect to a different host
43+ by checking that the URL is either relative or on a known good host:
44+ </p >
45+
46+ <sample src =" examples/UrlRedirectGoodDomain.java" />
47+
48+ <p >
49+ Note that as written, the above code will allow redirects to URLs on <code >example.com</code >,
50+ which is harmless but perhaps not intended. You can substitute your own domain (if known) for
51+ <code >example.com</code > to prevent this.
52+ </p >
2953
3054</example >
31- <references >
3255
56+ <references >
3357
58+ <li >
59+ OWASP:
60+ <a href =" https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html" >XSS
61+ Unvalidated Redirects and Forwards Cheat Sheet</a >.
62+ </li >
63+ <li >
64+ Microsoft Docs: <a href =" https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/preventing-open-redirection-attacks" >Preventing Open Redirection Attacks (C#)</a >.
65+ </li >
3466
3567</references >
3668</qhelp >
0 commit comments