@@ -16,21 +16,53 @@ controlled by the attacker.</p>
16
16
<p >To guard against untrusted URL redirection, it is advisable to avoid putting user input
17
17
directly into a redirect URL. Instead, maintain a list of authorized
18
18
redirects 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 >
20
23
</recommendation >
24
+
25
+
21
26
<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" />
22
33
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:
26
37
</p >
27
38
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 >
29
53
30
54
</example >
31
- <references >
32
55
56
+ <references >
33
57
58
+ <li >
59
+ OWASP:
60
+ <a href =" https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html" >
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 >
34
66
35
67
</references >
36
68
</qhelp >
0 commit comments