Skip to content

Commit 07d9591

Browse files
committed
Ruby: Add more RequestWithoutValidation.ql tests
Added: - one where the value is not directly used when disabling certificate validation. - one with argument passing, Faraday, where it is only the passing of `OpenSSL::SSL::VERIFY_NONE` that is recognized.
1 parent 47c9c5b commit 07d9591

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

ruby/ql/test/query-tests/security/cwe-295/Faraday.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,22 @@
2626
# GOOD
2727
connection = Faraday.new("http://example.com", ssl: { verify_mode: OpenSSL::SSL::VERIFY_PEER })
2828
response = connection.get("/")
29+
30+
# -- example of passing verify as argument --
31+
32+
def verify_as_arg(host, path, arg)
33+
# BAD, due to the call below
34+
connection = Faraday.new(host, ssl: { verify: arg })
35+
response = connection.get(path)
36+
end
37+
38+
verify_as_arg("http://example.com", "/", false)
39+
40+
41+
def verify_mode_as_arg(host, path, arg)
42+
# BAD, due to the call below
43+
connection = Faraday.new(host, ssl: { verify_mode: arg })
44+
response = connection.get(path)
45+
end
46+
47+
verify_mode_as_arg("http://example.com", "/", OpenSSL::SSL::VERIFY_NONE)

ruby/ql/test/query-tests/security/cwe-295/RequestWithoutValidation.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| Excon.rb:30:3:30:62 | call to get | This request may run without certificate validation because it is $@. | Excon.rb:30:36:30:57 | Pair | disabled here | Excon.rb:30:36:30:57 | Pair | here |
66
| Faraday.rb:5:12:5:30 | call to get | This request may run without certificate validation because it is $@. | Faraday.rb:4:48:4:69 | Pair | disabled here | Faraday.rb:4:48:4:69 | Pair | here |
77
| Faraday.rb:9:12:9:30 | call to get | This request may run without certificate validation because it is $@. | Faraday.rb:8:48:8:94 | Pair | disabled here | Faraday.rb:8:48:8:94 | Pair | here |
8+
| Faraday.rb:44:16:44:35 | call to get | This request may run without certificate validation because it is $@. | Faraday.rb:43:36:43:60 | Pair | disabled here | Faraday.rb:43:36:43:60 | Pair | here |
89
| HttpClient.rb:6:1:6:33 | call to get | This request may run without certificate validation because it is $@. | HttpClient.rb:5:1:5:29 | call to verify_mode= | disabled here | HttpClient.rb:5:1:5:29 | call to verify_mode= | here |
910
| Httparty.rb:4:1:4:50 | call to get | This request may run without certificate validation because it is $@. | Httparty.rb:4:37:4:49 | Pair | disabled here | Httparty.rb:4:37:4:49 | Pair | here |
1011
| Httparty.rb:7:1:7:55 | call to get | This request may run without certificate validation because it is $@. | Httparty.rb:7:37:7:54 | Pair | disabled here | Httparty.rb:7:37:7:54 | Pair | here |
@@ -21,5 +22,6 @@
2122
| RestClient.rb:5:12:5:23 | call to get | This request may run without certificate validation because it is $@. | RestClient.rb:4:60:4:96 | Pair | disabled here | RestClient.rb:4:60:4:96 | Pair | here |
2223
| RestClient.rb:9:12:9:23 | call to get | This request may run without certificate validation because it is $@. | RestClient.rb:8:62:8:98 | Pair | disabled here | RestClient.rb:8:62:8:98 | Pair | here |
2324
| RestClient.rb:14:12:14:23 | call to get | This request may run without certificate validation because it is $@. | RestClient.rb:12:13:12:49 | Pair | disabled here | RestClient.rb:12:13:12:49 | Pair | here |
25+
| RestClient.rb:19:12:19:23 | call to get | This request may run without certificate validation because it is $@. | RestClient.rb:18:60:18:76 | Pair | disabled here | RestClient.rb:18:60:18:76 | Pair | here |
2426
| Typhoeus.rb:4:1:4:62 | call to get | This request may run without certificate validation because it is $@. | Typhoeus.rb:4:41:4:61 | Pair | disabled here | Typhoeus.rb:4:41:4:61 | Pair | here |
2527
| Typhoeus.rb:8:1:8:54 | call to post | This request may run without certificate validation because it is $@. | Typhoeus.rb:7:37:7:57 | Pair | disabled here | Typhoeus.rb:7:37:7:57 | Pair | here |

ruby/ql/test/query-tests/security/cwe-295/RestClient.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
resource = RestClient::Resource.new("https://example.com", options)
1414
response = resource.get
1515

16+
# BAD
17+
value = OpenSSL::SSL::VERIFY_NONE
18+
resource = RestClient::Resource.new("https://example.com", verify_ssl: value)
19+
response = resource.get
20+
1621
# GOOD
1722
RestClient.get("https://example.com")
1823

0 commit comments

Comments
 (0)