Skip to content

Commit 4140942

Browse files
committed
Update tests
1 parent fd306ed commit 4140942

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
edges
22
| IncompleteHostnameRegexp.go:11:8:11:36 | "^((www\|beta).)?example.com/" | IncompleteHostnameRegexp.go:12:38:12:39 | re | provenance | |
3+
| main.go:49:21:49:45 | `https://www.example.com` | main.go:62:15:62:25 | sourceConst | provenance | |
4+
| main.go:62:15:62:25 | sourceConst | main.go:65:15:65:23 | localVar3 | provenance | |
35
nodes
46
| IncompleteHostnameRegexp.go:11:8:11:36 | "^((www\|beta).)?example.com/" | semmle.label | "^((www\|beta).)?example.com/" |
57
| IncompleteHostnameRegexp.go:12:38:12:39 | re | semmle.label | re |
6-
| main.go:39:60:39:79 | "^test2.github.com$" | semmle.label | "^test2.github.com$" |
7-
| main.go:44:15:44:39 | `https://www.example.com` | semmle.label | `https://www.example.com` |
8+
| main.go:40:60:40:79 | "^test2.github.com$" | semmle.label | "^test2.github.com$" |
9+
| main.go:45:15:45:39 | `https://www.example.com` | semmle.label | `https://www.example.com` |
10+
| main.go:49:21:49:45 | `https://www.example.com` | semmle.label | `https://www.example.com` |
11+
| main.go:56:15:56:34 | ...+... | semmle.label | ...+... |
12+
| main.go:58:15:58:42 | ...+... | semmle.label | ...+... |
13+
| main.go:62:15:62:25 | sourceConst | semmle.label | sourceConst |
14+
| main.go:65:15:65:23 | localVar3 | semmle.label | localVar3 |
815
subpaths
916
#select
1017
| IncompleteHostnameRegexp.go:11:8:11:36 | "^((www\|beta).)?example.com/" | IncompleteHostnameRegexp.go:11:8:11:36 | "^((www\|beta).)?example.com/" | IncompleteHostnameRegexp.go:12:38:12:39 | re | This regular expression has an unescaped dot before ')?example.com', so it might match more hosts than expected when $@. | IncompleteHostnameRegexp.go:12:38:12:39 | re | the regular expression is used |
11-
| main.go:39:60:39:79 | "^test2.github.com$" | main.go:39:60:39:79 | "^test2.github.com$" | main.go:39:60:39:79 | "^test2.github.com$" | This regular expression has an unescaped dot before 'github.com', so it might match more hosts than expected when $@. | main.go:39:60:39:79 | "^test2.github.com$" | the regular expression is used |
12-
| main.go:44:15:44:39 | `https://www.example.com` | main.go:44:15:44:39 | `https://www.example.com` | main.go:44:15:44:39 | `https://www.example.com` | This regular expression has an unescaped dot before 'example.com', so it might match more hosts than expected when $@. | main.go:44:15:44:39 | `https://www.example.com` | the regular expression is used |
18+
| main.go:40:60:40:79 | "^test2.github.com$" | main.go:40:60:40:79 | "^test2.github.com$" | main.go:40:60:40:79 | "^test2.github.com$" | This regular expression has an unescaped dot before 'github.com', so it might match more hosts than expected when $@. | main.go:40:60:40:79 | "^test2.github.com$" | the regular expression is used |
19+
| main.go:45:15:45:39 | `https://www.example.com` | main.go:45:15:45:39 | `https://www.example.com` | main.go:45:15:45:39 | `https://www.example.com` | This regular expression has an unescaped dot before 'example.com', so it might match more hosts than expected when $@. | main.go:45:15:45:39 | `https://www.example.com` | the regular expression is used |
20+
| main.go:49:21:49:45 | `https://www.example.com` | main.go:49:21:49:45 | `https://www.example.com` | main.go:65:15:65:23 | localVar3 | This regular expression has an unescaped dot before 'example.com', so it might match more hosts than expected when $@. | main.go:65:15:65:23 | localVar3 | the regular expression is used |
21+
| main.go:56:15:56:34 | ...+... | main.go:56:15:56:34 | ...+... | main.go:56:15:56:34 | ...+... | This regular expression has an unescaped dot before 'example.com', so it might match more hosts than expected when $@. | main.go:56:15:56:34 | ...+... | the regular expression is used |
22+
| main.go:58:15:58:42 | ...+... | main.go:58:15:58:42 | ...+... | main.go:58:15:58:42 | ...+... | This regular expression has an unescaped dot before 'example.com', so it might match more hosts than expected when $@. | main.go:58:15:58:42 | ...+... | the regular expression is used |

go/ql/test/query-tests/Security/CWE-020/IncompleteHostnameRegexp/main.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
package main
44

55
import (
6-
"github.com/elazarl/goproxy"
76
"net/http"
87
"regexp"
98
"time"
9+
10+
"github.com/elazarl/goproxy"
1011
)
1112

1213
func Match(notARegex string) bool {
@@ -44,3 +45,22 @@ func main() {
4445
regexp.Match(`https://www.example.com`, []byte("")) // NOT OK
4546
regexp.Match(`https://www\.example\.com`, []byte("")) // OK
4647
}
48+
49+
const sourceConst = `https://www.example.com`
50+
const firstHalfConst = `https://www.example.`
51+
52+
func concatenateStrings() {
53+
firstHalf := `https://www.example.`
54+
regexp.Match(firstHalf+`com`, []byte("")) // MISSING: NOT OK
55+
56+
regexp.Match(firstHalfConst+`com`, []byte("")) // NOT OK
57+
58+
regexp.Match(`https://www.example.`+`com`, []byte("")) // NOT OK
59+
}
60+
61+
func avoidDuplicateResults() {
62+
localVar1 := sourceConst
63+
localVar2 := localVar1
64+
localVar3 := localVar2
65+
regexp.Match(localVar3, []byte("")) // NOT OK
66+
}

0 commit comments

Comments
 (0)