-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBadRedirectCheck.qhelp
More file actions
40 lines (35 loc) · 1.47 KB
/
BadRedirectCheck.qhelp
File metadata and controls
40 lines (35 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
<qhelp>
<overview>
<p>
Redirect URLs should be checked to ensure that user input cannot cause a site to redirect
to arbitrary domains. This is often done with a check that the redirect URL begins with a slash,
which most of the time is an absolute redirect on the same host. However, browsers interpret URLs
beginning with <code>//</code> or <code>/\</code> as absolute URLs. For example, a redirect to
<code>//example.com</code> will redirect to <code>https://example.com</code>. Thus, redirect checks must
also check the second character of redirect URLs.
</p>
</overview>
<recommendation>
<p>
Also disallow redirect URLs starting with <code>//</code> or <code>/\</code>.
</p>
</recommendation>
<example>
<p>
The following function validates a (presumably untrusted) redirect URL <code>redir</code>. If it
does not begin with <code>/</code>, the harmless placeholder redirect URL <code>/</code> is
returned to prevent an open redirect; otherwise <code>redir</code> itself is returned.
</p>
<sample src="BadRedirectCheck.go"/>
<p>
While this check provides partial protection, it should be extended to cover <code>//</code> and
<code>/\</code> as well:
</p>
<sample src="BadRedirectCheckGood.go"/>
</example>
<references>
<li>OWASP: <a href="https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html#validating-urls">
XSS Unvalidated Redirects and Forwards Cheat Sheet</a>.</li>
</references>
</qhelp>