Skip to content

Commit 361b703

Browse files
author
Porcupiney Hairs
committed
Include suggested changes from review.
1 parent 1ef42a1 commit 361b703

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

go/ql/test/experimental/CWE-321/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ func lejwt2() (interface{}, error) {
113113
return le.New(sharedKeyglobal) // BAD
114114
}
115115

116-
func BarrierGuardTest() (interface{}, error) {
117-
sharedKey := ""
118-
if sharedKey != "" {
119-
return le.New([]byte(sharedKey)) // GOOD
120-
}
121-
return "", nil
122-
}
123-
124116
func main() {
125117
return
126118
}

go/ql/test/experimental/CWE-321/sanitizer.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
cristal "github.com/cristalhq/jwt/v3"
1414
)
1515

16-
func cristalhq() (interface{}, error) {
16+
func check_ok() (interface{}, error) {
1717
key := []byte(`key`)
1818
return cristal.NewSignerHS(cristal.HS256, key) // BAD
1919
}
@@ -40,6 +40,7 @@ func GenerateCryptoString2(n int) (string, error) {
4040
}
4141
return string(ret), nil
4242
}
43+
4344
func GenerateRandomString3(size int) string {
4445
const characters = `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
4546
var bytes = make([]byte, size)
@@ -72,45 +73,44 @@ func RandString(length int64) string {
7273

7374
return string(result)
7475
}
75-
func genKey(size int) (string, error) {
76-
err := errors.New("size too small")
77-
return "", err
78-
}
79-
func test1() {
76+
77+
func randIntSanitizerModulo_test() (interface{}, error) {
8078
key := GenerateRandomString(32)
81-
return cristal.NewSignerHS(cristal.HS256, key) // GOOD
79+
return cristal.NewSignerHS(cristal.HS256, []byte(key)) // GOOD
8280
}
8381

84-
func test2() {
82+
func randIntSanitizer_test() (interface{}, error) {
8583
key2, _ := GenerateCryptoString2(32)
86-
return cristal.NewSignerHS(cristal.HS256, key2) // GOOD
84+
return cristal.NewSignerHS(cristal.HS256, []byte(key2)) // GOOD
8785
}
8886

89-
func test3() {
87+
func formattingSanitizer_test() (interface{}, error) {
9088
key3 := RandAuthToken()
91-
return cristal.NewSignerHS(cristal.HS256, key3) // GOOD
89+
return cristal.NewSignerHS(cristal.HS256, []byte(key3)) // GOOD
9290
}
9391

94-
func test4() (interface{}, error) {
95-
key4, err := genKey(21)
96-
if err != nil {
97-
return nil, err
98-
}
92+
func genKey() (string, error) {
93+
k := "asd"
94+
e := errors.New("no key")
95+
return k, e
96+
}
9997

100-
return cristal.NewSignerHS(cristal.HS256, key4) // BAD
98+
func emptyErrorSanitizer_test() (interface{}, error) {
99+
key4, _ := genKey()
100+
return cristal.NewSignerHS(cristal.HS256, []byte(key4)) // GOOD
101101
}
102102

103-
func test5() (interface{}, error) {
104-
temp := "test"
105-
if temp != "test" {
106-
return cristal.NewSignerHS(cristal.HS256, []byte(temp)), nil // GOOD
107-
} else {
108-
return nil, nil
103+
func compareSanitizerTest() (interface{}, error) {
104+
key5 := ""
105+
if key5 != "" {
106+
return cristal.NewSignerHS(cristal.HS256, []byte(key5)) // GOOD
109107
}
108+
return "", nil
110109
}
111-
func test6() {
112-
key := GenerateRandomString3(32)
113-
return cristal.NewSignerHS(cristal.HS256, key) // GOOD
110+
111+
func randReadSanitizer_test() (interface{}, error) {
112+
key6 := GenerateRandomString3(32)
113+
return cristal.NewSignerHS(cristal.HS256, []byte(key6)) // GOOD
114114
}
115115

116116
func main() {

0 commit comments

Comments
 (0)