Skip to content

Commit d3e0a90

Browse files
author
Max Schaefer
committed
Go: Mention raw string iterals in QHelp for go/incomplete-hostname-regexp.
1 parent 693c28a commit d3e0a90

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

go/ql/src/Security/CWE-020/IncompleteHostnameRegexp.qhelp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ domain such as <code>wwwXexample.com</code>.
4141
Address this vulnerability by escaping <code>.</code> appropriately:
4242
</p>
4343
<sample src="IncompleteHostnameRegexpGood.go"/>
44+
<p>
45+
You may also want to consider using raw string literals to avoid having to escape backslashes:
46+
</p>
47+
<sample src="IncompleteHostnameRegexpGood2.go"/>
4448
</example>
4549

4650
<references>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
"regexp"
7+
)
8+
9+
func checkRedirectGood(req *http.Request, via []*http.Request) error {
10+
// GOOD: the host of `req.URL` must be `example.com`, `www.example.com` or `beta.example.com`
11+
re := `^((www|beta)\.)?example\.com/`
12+
if matched, _ := regexp.MatchString(re, req.URL.Host); matched {
13+
return nil
14+
}
15+
return errors.New("Invalid redirect")
16+
}

0 commit comments

Comments
 (0)