Skip to content

Commit 7ec6416

Browse files
authored
Convert Ruby qlref tests to inline expectations
1 parent de281fc commit 7ec6416

143 files changed

Lines changed: 1034 additions & 977 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/CWE-522-DecompressionBombs/DecompressionBombs.ql
1+
query: experimental/CWE-522-DecompressionBombs/DecompressionBombs.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
require 'zlib'
22

33
class TestController < ActionController::Base
4-
gzip_path = params[:path]
4+
gzip_path = params[:path] # $ Source
55

6-
Zlib::GzipReader.open(gzip_path).read
6+
Zlib::GzipReader.open(gzip_path).read # $ Alert
77
Zlib::GzipReader.open(gzip_path) do |uncompressedfile|
88
puts uncompressedfile.read
9-
end
9+
end # $ Alert
1010
Zlib::GzipReader.open(gzip_path) do |uncompressedfile|
1111
uncompressedfile.each do |entry|
1212
puts entry
1313
end
14-
end
15-
uncompressedfile = Zlib::GzipReader.open(gzip_path)
14+
end # $ Alert
15+
uncompressedfile = Zlib::GzipReader.open(gzip_path) # $ Alert
1616
uncompressedfile.each do |entry|
1717
puts entry
1818
end
1919

20-
Zlib::GzipReader.new(File.open(gzip_path, 'rb')).read
21-
Zlib::GzipReader.new(File.open(gzip_path, 'rb')).each do |entry|
20+
Zlib::GzipReader.new(File.open(gzip_path, 'rb')).read # $ Alert
21+
Zlib::GzipReader.new(File.open(gzip_path, 'rb')).each do |entry| # $ Alert
2222
puts entry
2323
end
2424

25-
Zlib::GzipReader.zcat(open(gzip_path))
25+
Zlib::GzipReader.zcat(open(gzip_path)) # $ Alert
2626
end
2727

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
require 'zip'
22

33
class TestController < ActionController::Base
4-
zipfile_path = params[:path]
4+
zipfile_path = params[:path] # $ Source
55

66
Zip::InputStream.open(zipfile_path) do |input|
77
while (entry = input.get_next_entry)
88
puts :file_name, entry.name
99
input
1010
end
11-
end
11+
end # $ Alert
1212
Zip::InputStream.open(zipfile_path) do |input|
1313
input.read
14-
end
15-
input = Zip::InputStream.open(zipfile_path)
14+
end # $ Alert
15+
input = Zip::InputStream.open(zipfile_path) # $ Alert
1616

17-
Zip::File.open(zipfile_path).read "10GB"
18-
Zip::File.open(zipfile_path).extract "10GB", "./"
17+
Zip::File.open(zipfile_path).read "10GB" # $ Alert
18+
Zip::File.open(zipfile_path).extract "10GB", "./" # $ Alert
1919

2020
Zip::File.open(zipfile_path) do |zip_file|
2121
# Handle entries one by one
@@ -25,33 +25,33 @@ class TestController < ActionController::Base
2525
# Extract to file or directory based on name in the archive
2626
entry.extract
2727
# Read into memory
28-
entry.get_input_stream.read
28+
entry.get_input_stream.read # $ Alert
2929
end
3030
end
3131

3232
zip_file = Zip::File.open(zipfile_path)
3333
zip_file.each do |entry|
34-
entry.extract
35-
entry.get_input_stream.read
34+
entry.extract # $ Alert
35+
entry.get_input_stream.read # $ Alert
3636
end
3737

3838
# Find specific entry
3939
Zip::File.open(zipfile_path) do |zip_file|
4040
zip_file.glob('*.xml').each do |entry|
41-
zip_file.read(entry.name)
42-
entry.extract
41+
zip_file.read(entry.name) # $ Alert
42+
entry.extract # $ Alert
4343
end
4444
entry = zip_file.glob('*.csv').first
4545
raise 'File too large when extracted' if entry.size > MAX_SIZE
46-
puts entry.get_input_stream.read
46+
puts entry.get_input_stream.read # $ Alert
4747
end
4848

4949
zip_file = Zip::File.open(zipfile_path)
5050
entry = zip_file.glob('*.csv')
51-
puts entry.get_input_stream.read
51+
puts entry.get_input_stream.read # $ Alert
5252

5353
zip_file = Zip::File.open(zipfile_path)
5454
zip_file.glob('*') do |entry|
55-
entry.get_input_stream.read
55+
entry.get_input_stream.read # $ Alert
5656
end
5757
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/ldap-improper-auth/ImproperLdapAuth.ql
1+
query: experimental/ldap-improper-auth/ImproperLdapAuth.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

ruby/ql/test/query-tests/experimental/ImproperLdapAuth/ImproperLdapAuth.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class FooController < ActionController::Base
22
def some_request_handler
33
# A string tainted by user input is used directly as password
44
# (i.e a remote flow source)
5-
pass = params[:pass]
5+
pass = params[:pass] # $ Source
66

77
# BAD: user input is not sanitized
88
ldap = Net::LDAP.new(
@@ -12,7 +12,7 @@ def some_request_handler
1212
auth: {
1313
method: :simple,
1414
username: 'uid=admin,dc=example,dc=com',
15-
password: pass
15+
password: pass # $ Alert
1616
}
1717
)
1818
ldap.bind
@@ -21,14 +21,14 @@ def some_request_handler
2121
def some_request_handler
2222
# A string tainted by user input is used directly as password
2323
# (i.e a remote flow source)
24-
pass = params[:pass]
24+
pass = params[:pass] # $ Source
2525

2626
# BAD: user input is not sanitized
2727
ldap = Net::LDAP.new
2828
ldap.host = your_server_ip_address
2929
ldap.encryption(:method => :simple_tls)
3030
ldap.port = 639
31-
ldap.auth "admin", pass
31+
ldap.auth "admin", pass # $ Alert
3232
ldap.bind
3333
end
3434
end
@@ -56,4 +56,4 @@ def safe_paths
5656
}
5757
)
5858
end
59-
end
59+
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/insecure-randomness/InsecureRandomness.ql
1+
query: experimental/insecure-randomness/InsecureRandomness.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

ruby/ql/test/query-tests/experimental/InsecureRandomness/InsecureRandomness.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def generate_password_1(length)
44
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ['!', '@', '#', '$', '%']
55
# BAD: rand is not cryptographically secure
6-
password = (1..length).collect { chars[rand(chars.size)] }.join
6+
password = (1..length).collect { chars[rand(chars.size)] }.join # $ Alert
77
end
88

99
def generate_password_2(length)
@@ -16,4 +16,4 @@ def generate_password_2(length)
1616
end
1717

1818
password = generate_password_1(10)
19-
password = generate_password_2(10)
19+
password = generate_password_2(10)

ruby/ql/test/query-tests/experimental/LdapInjection/LdapInjection.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ class FooController < ActionController::Base
22
def some_request_handler
33
# A string tainted by user input is used directly as DN
44
# (i.e a remote flow source)
5-
dc = params[:dc]
5+
dc = params[:dc] # $ Source
66

77
# A string tainted by user input is used directly as search filter or attribute
88
# (i.e a remote flow source)
9-
name = params[:user_name]
9+
name = params[:user_name] # $ Source
1010

1111
# LDAP Connection
1212
ldap = Net::LDAP.new(
@@ -22,20 +22,20 @@ def some_request_handler
2222

2323
# BAD: user input is used as DN
2424
# where dc is unsanitized
25-
ldap.search(base: "ou=people,dc=#{dc},dc=com", filter: "cn=George", attributes: [""])
25+
ldap.search(base: "ou=people,dc=#{dc},dc=com", filter: "cn=George", attributes: [""]) # $ Alert
2626

2727
# BAD: user input is used as search filter
2828
# where name is unsanitized
29-
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=#{name}", attributes: [""])
29+
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=#{name}", attributes: [""]) # $ Alert
3030

3131
# BAD: user input is used as attribute
3232
# where name is unsanitized
33-
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=George", attributes: [name])
33+
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=George", attributes: [name]) # $ Alert
3434

3535
# BAD: user input is used as search filter
3636
# where name is unsanitized
3737
filter = Net::LDAP::Filter.eq('cn', name)
38-
ldap.search(base: "ou=people,dc=example,dc=com", filter: filter, attributes: [""])
38+
ldap.search(base: "ou=people,dc=example,dc=com", filter: filter, attributes: [""]) # $ Alert
3939

4040
# GOOD: user input is not used in the LDAP query
4141
result = ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=George", attributes: [""])
@@ -63,4 +63,4 @@ def safe_paths
6363
end
6464
result = ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=#{name}", attributes: [""])
6565
end
66-
end
66+
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/ldap-injection/LdapInjection.ql
1+
query: experimental/ldap-injection/LdapInjection.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

ruby/ql/test/query-tests/experimental/TemplateInjection/ErbInjection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class FooController < ActionController::Base
22
def some_request_handler
33
# A string tainted by user input is inserted into a template
44
# (i.e a remote flow source)
5-
name = params[:name]
5+
name = params[:name] # $ Source
66

77
# Template with the source
88
bad_text = "
@@ -12,11 +12,11 @@ def some_request_handler
1212

1313
# BAD: user input is evaluated
1414
# where name is unsanitized
15-
template = ERB.new(bad_text).result(binding)
15+
template = ERB.new(bad_text).result(binding) # $ Alert
1616

1717
# BAD: user input is evaluated
1818
# where name is unsanitized
19-
render inline: bad_text
19+
render inline: bad_text # $ Alert
2020

2121
# Template with the source
2222
good_text = "

0 commit comments

Comments
 (0)