Skip to content

Commit d994959

Browse files
committed
Ruby: add tests for rb/weak-sensitive-data-hashing
1 parent 81ec686 commit d994959

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
edges
2+
| weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:6:1:6:1 | x | provenance | |
3+
| weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:10:23:10:30 | password | provenance | |
4+
| weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:11:32:11:39 | password | provenance | |
5+
| weak_hashing.rb:4:1:4:8 | username | weak_hashing.rb:12:23:12:30 | username | provenance | |
6+
| weak_hashing.rb:6:1:6:1 | x | weak_hashing.rb:13:23:13:23 | x | provenance | |
7+
| weak_hashing.rb:30:25:30:38 | password_param | weak_hashing.rb:32:25:32:38 | password_param | provenance | |
8+
nodes
9+
| weak_hashing.rb:3:1:3:8 | password | semmle.label | password |
10+
| weak_hashing.rb:4:1:4:8 | username | semmle.label | username |
11+
| weak_hashing.rb:6:1:6:1 | x | semmle.label | x |
12+
| weak_hashing.rb:10:23:10:30 | password | semmle.label | password |
13+
| weak_hashing.rb:11:32:11:39 | password | semmle.label | password |
14+
| weak_hashing.rb:12:23:12:30 | username | semmle.label | username |
15+
| weak_hashing.rb:13:23:13:23 | x | semmle.label | x |
16+
| weak_hashing.rb:24:23:24:36 | call to get_password | semmle.label | call to get_password |
17+
| weak_hashing.rb:28:23:28:42 | ...[...] | semmle.label | ...[...] |
18+
| weak_hashing.rb:30:25:30:38 | password_param | semmle.label | password_param |
19+
| weak_hashing.rb:32:25:32:38 | password_param | semmle.label | password_param |
20+
subpaths
21+
#select
22+
| weak_hashing.rb:10:23:10:30 | password | weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:10:23:10:30 | password | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:3:1:3:8 | password | Sensitive data (password) |
23+
| weak_hashing.rb:11:32:11:39 | password | weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:11:32:11:39 | password | $@ is used in a hashing algorithm (SHA1) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:3:1:3:8 | password | Sensitive data (password) |
24+
| weak_hashing.rb:12:23:12:30 | username | weak_hashing.rb:4:1:4:8 | username | weak_hashing.rb:12:23:12:30 | username | $@ is used in a hashing algorithm (MD5) that is insecure. | weak_hashing.rb:4:1:4:8 | username | Sensitive data (id) |
25+
| weak_hashing.rb:13:23:13:23 | x | weak_hashing.rb:3:1:3:8 | password | weak_hashing.rb:13:23:13:23 | x | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:3:1:3:8 | password | Sensitive data (password) |
26+
| weak_hashing.rb:24:23:24:36 | call to get_password | weak_hashing.rb:24:23:24:36 | call to get_password | weak_hashing.rb:24:23:24:36 | call to get_password | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:24:23:24:36 | call to get_password | Sensitive data (password) |
27+
| weak_hashing.rb:28:23:28:42 | ...[...] | weak_hashing.rb:28:23:28:42 | ...[...] | weak_hashing.rb:28:23:28:42 | ...[...] | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:28:23:28:42 | ...[...] | Sensitive data (password) |
28+
| weak_hashing.rb:32:25:32:38 | password_param | weak_hashing.rb:30:25:30:38 | password_param | weak_hashing.rb:32:25:32:38 | password_param | $@ is used in a hashing algorithm (MD5) that is insecure for password hashing, since it is not a computationally expensive hash function. | weak_hashing.rb:30:25:30:38 | password_param | Sensitive data (password) |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/security/cwe-327/WeakSensitiveDataHashing.ql
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'openssl'
2+
3+
password = "abcde"
4+
username = "some_user"
5+
some_data = "foo"
6+
x = password
7+
8+
Digest::MD5.hexdigest(some_data) # OK: input is not sensitive
9+
Digest::SHA256.hexdigest(password) # OK: strong hash algorithm
10+
Digest::MD5.hexdigest(password) # BAD: weak hash function used for sensitive data
11+
OpenSSL::Digest.digest('SHA1', password) # BAD: weak hash function used for sensitive data
12+
Digest::MD5.hexdigest(username) # BAD: weak hash function used for sensitive data
13+
Digest::MD5.hexdigest(x) # BAD: weak hash function used for sensitive data
14+
15+
def get_safe_data()
16+
return "hello"
17+
end
18+
def get_password()
19+
return "changeme"
20+
end
21+
22+
# FIXME
23+
Digest::MD5.hexdigest(get_safe_data()) # OK: input is not sensitive
24+
Digest::MD5.hexdigest(get_password()) # BAD: weak hash function used for sensitive data
25+
26+
some_hash = {password: "changeme", foo: "bar"}
27+
Digest::MD5.hexdigest(some_hash[:foo]) # OK: input is not sensitive
28+
Digest::MD5.hexdigest(some_hash[:password]) # BAD: weak hash function used for sensitive data
29+
30+
def a_method(safe_data, password_param)
31+
Digest::MD5.hexdigest(safe_data) # OK: input is not sensitive
32+
Digest::MD5.hexdigest(password_param) # BAD: weak hash function used for sensitive data
33+
end

0 commit comments

Comments
 (0)