mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
Merge pull request #15933 from github/max-schaefer/go-incomplete-hostname-regex
Go: Mention raw string iterals in QHelp for `go/incomplete-hostname-regexp`.
This commit is contained in:
@@ -41,6 +41,10 @@ domain such as <code>wwwXexample.com</code>.
|
||||
Address this vulnerability by escaping <code>.</code> appropriately:
|
||||
</p>
|
||||
<sample src="IncompleteHostnameRegexpGood.go"/>
|
||||
<p>
|
||||
You may also want to consider using raw string literals to avoid having to escape backslashes:
|
||||
</p>
|
||||
<sample src="IncompleteHostnameRegexpGood2.go"/>
|
||||
</example>
|
||||
|
||||
<references>
|
||||
|
||||
16
go/ql/src/Security/CWE-020/IncompleteHostnameRegexpGood2.go
Normal file
16
go/ql/src/Security/CWE-020/IncompleteHostnameRegexpGood2.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func checkRedirectGood(req *http.Request, via []*http.Request) error {
|
||||
// GOOD: the host of `req.URL` must be `example.com`, `www.example.com` or `beta.example.com`
|
||||
re := `^((www|beta)\.)?example\.com/`
|
||||
if matched, _ := regexp.MatchString(re, req.URL.Host); matched {
|
||||
return nil
|
||||
}
|
||||
return errors.New("Invalid redirect")
|
||||
}
|
||||
Reference in New Issue
Block a user