Skip to content

Commit c308978

Browse files
committed
Make insecure randomness test more realistic
1 parent 7f5e973 commit c308978

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

go/ql/test/query-tests/Security/CWE-338/InsecureRandomness/InsecureRandomness.expected

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#select
22
| InsecureRandomness.go:12:18:12:40 | call to Intn | InsecureRandomness.go:12:18:12:40 | call to Intn | InsecureRandomness.go:12:18:12:40 | call to Intn | A password-related function depends on a $@ generated with a cryptographically weak RNG. | InsecureRandomness.go:12:18:12:40 | call to Intn | random number |
33
| sample.go:26:25:26:30 | call to Guid | sample.go:15:49:15:61 | call to Uint32 | sample.go:26:25:26:30 | call to Guid | This cryptographic algorithm depends on a $@ generated with a cryptographically weak RNG. | sample.go:15:49:15:61 | call to Uint32 | random number |
4-
| sample.go:37:25:37:29 | nonce | sample.go:34:12:34:40 | call to New | sample.go:37:25:37:29 | nonce | This cryptographic algorithm depends on a $@ generated with a cryptographically weak RNG. | sample.go:34:12:34:40 | call to New | random number |
5-
| sample.go:37:32:37:36 | nonce | sample.go:34:12:34:40 | call to New | sample.go:37:32:37:36 | nonce | This cryptographic algorithm depends on a $@ generated with a cryptographically weak RNG. | sample.go:34:12:34:40 | call to New | random number |
4+
| sample.go:37:35:37:39 | nonce | sample.go:34:12:34:40 | call to New | sample.go:37:35:37:39 | nonce | This cryptographic algorithm depends on a $@ generated with a cryptographically weak RNG. | sample.go:34:12:34:40 | call to New | random number |
65
| sample.go:43:17:43:39 | call to Intn | sample.go:43:17:43:39 | call to Intn | sample.go:43:17:43:39 | call to Intn | A password-related function depends on a $@ generated with a cryptographically weak RNG. | sample.go:43:17:43:39 | call to Intn | random number |
76
| sample.go:58:32:58:43 | type conversion | sample.go:55:17:55:42 | call to Intn | sample.go:58:32:58:43 | type conversion | This cryptographic algorithm depends on a $@ generated with a cryptographically weak RNG. | sample.go:55:17:55:42 | call to Intn | random number |
87
edges
@@ -13,8 +12,7 @@ edges
1312
| sample.go:15:49:15:61 | call to Uint32 | sample.go:15:31:15:62 | []type{args} [array] | provenance | |
1413
| sample.go:15:49:15:61 | call to Uint32 | sample.go:15:31:15:62 | call to Sprintf | provenance | FunctionModel |
1514
| sample.go:16:9:16:15 | slice expression | sample.go:26:25:26:30 | call to Guid | provenance | |
16-
| sample.go:33:2:33:6 | definition of nonce | sample.go:37:25:37:29 | nonce | provenance | |
17-
| sample.go:33:2:33:6 | definition of nonce | sample.go:37:32:37:36 | nonce | provenance | |
15+
| sample.go:33:2:33:6 | definition of nonce | sample.go:37:35:37:39 | nonce | provenance | |
1816
| sample.go:34:12:34:40 | call to New | sample.go:35:14:35:19 | random | provenance | |
1917
| sample.go:35:14:35:19 | random | sample.go:33:2:33:6 | definition of nonce | provenance | MaD:2 |
2018
| sample.go:55:17:55:42 | call to Intn | sample.go:56:29:56:38 | randNumber | provenance | |
@@ -36,8 +34,7 @@ nodes
3634
| sample.go:33:2:33:6 | definition of nonce | semmle.label | definition of nonce |
3735
| sample.go:34:12:34:40 | call to New | semmle.label | call to New |
3836
| sample.go:35:14:35:19 | random | semmle.label | random |
39-
| sample.go:37:25:37:29 | nonce | semmle.label | nonce |
40-
| sample.go:37:32:37:36 | nonce | semmle.label | nonce |
37+
| sample.go:37:35:37:39 | nonce | semmle.label | nonce |
4138
| sample.go:43:17:43:39 | call to Intn | semmle.label | call to Intn |
4239
| sample.go:44:17:44:39 | call to Intn | semmle.label | call to Intn |
4340
| sample.go:45:17:45:39 | call to Intn | semmle.label | call to Intn |

go/ql/test/query-tests/Security/CWE-338/InsecureRandomness/sample.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func encrypt(data []byte, password string) []byte {
3434
random := rand.New(rand.NewSource(999))
3535
io.ReadFull(random, nonce)
3636

37-
ciphertext := gcm.Seal(nonce, nonce, data, nil) // BAD: use of an insecure rng to generate a nonce
37+
ciphertext := gcm.Seal(data[:0], nonce, data, nil) // BAD: use of an insecure rng to generate a nonce
3838
return ciphertext
3939
}
4040

0 commit comments

Comments
 (0)