Skip to content

Commit b078430

Browse files
authored
add Zip::File.new query to tests
1 parent e317392 commit b078430

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

ruby/ql/test/query-tests/security/cwe-022/ArchiveApiPathTraversal.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def unpload_zip
1010
unzip params[:file]
1111
end
1212

13+
# this is vulnerable
14+
def create_new_zip
15+
zip params[:filename], files
16+
end
17+
1318
# these are not vulnerable because of the string compare sanitizer
1419
def safe_upload_string_compare
1520
filename = params[:filename]
@@ -66,4 +71,12 @@ def unzip(file)
6671
end
6772
end
6873
end
74+
75+
def zip(filename, files = [])
76+
Zip::File.new(filename) do |zf|
77+
files.each do |f|
78+
zf.add f
79+
end
80+
end
81+
end
6982
end

ruby/ql/test/query-tests/security/cwe-022/PathInjection.expected

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
edges
22
| ArchiveApiPathTraversal.rb:5:26:5:31 | call to params : | ArchiveApiPathTraversal.rb:5:26:5:42 | ...[...] : |
3-
| ArchiveApiPathTraversal.rb:5:26:5:42 | ...[...] : | ArchiveApiPathTraversal.rb:44:17:44:27 | destination : |
3+
| ArchiveApiPathTraversal.rb:5:26:5:42 | ...[...] : | ArchiveApiPathTraversal.rb:49:17:49:27 | destination : |
44
| ArchiveApiPathTraversal.rb:10:11:10:16 | call to params : | ArchiveApiPathTraversal.rb:10:11:10:23 | ...[...] : |
5-
| ArchiveApiPathTraversal.rb:10:11:10:23 | ...[...] : | ArchiveApiPathTraversal.rb:62:13:62:16 | file : |
6-
| ArchiveApiPathTraversal.rb:44:17:44:27 | destination : | ArchiveApiPathTraversal.rb:47:38:47:48 | destination : |
7-
| ArchiveApiPathTraversal.rb:47:28:47:67 | call to join : | ArchiveApiPathTraversal.rb:54:21:54:36 | destination_file |
8-
| ArchiveApiPathTraversal.rb:47:38:47:48 | destination : | ArchiveApiPathTraversal.rb:47:28:47:67 | call to join : |
9-
| ArchiveApiPathTraversal.rb:62:13:62:16 | file : | ArchiveApiPathTraversal.rb:63:20:63:23 | file |
5+
| ArchiveApiPathTraversal.rb:10:11:10:23 | ...[...] : | ArchiveApiPathTraversal.rb:67:13:67:16 | file : |
6+
| ArchiveApiPathTraversal.rb:15:9:15:14 | call to params : | ArchiveApiPathTraversal.rb:15:9:15:25 | ...[...] : |
7+
| ArchiveApiPathTraversal.rb:15:9:15:25 | ...[...] : | ArchiveApiPathTraversal.rb:75:11:75:18 | filename : |
8+
| ArchiveApiPathTraversal.rb:49:17:49:27 | destination : | ArchiveApiPathTraversal.rb:52:38:52:48 | destination : |
9+
| ArchiveApiPathTraversal.rb:52:28:52:67 | call to join : | ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file |
10+
| ArchiveApiPathTraversal.rb:52:38:52:48 | destination : | ArchiveApiPathTraversal.rb:52:28:52:67 | call to join : |
11+
| ArchiveApiPathTraversal.rb:67:13:67:16 | file : | ArchiveApiPathTraversal.rb:68:20:68:23 | file |
12+
| ArchiveApiPathTraversal.rb:75:11:75:18 | filename : | ArchiveApiPathTraversal.rb:76:19:76:26 | filename |
1013
| tainted_path.rb:4:12:4:17 | call to params : | tainted_path.rb:4:12:4:24 | ...[...] : |
1114
| tainted_path.rb:4:12:4:24 | ...[...] : | tainted_path.rb:5:26:5:29 | path |
1215
| tainted_path.rb:10:12:10:43 | call to absolute_path : | tainted_path.rb:11:26:11:29 | path |
@@ -38,12 +41,16 @@ nodes
3841
| ArchiveApiPathTraversal.rb:5:26:5:42 | ...[...] : | semmle.label | ...[...] : |
3942
| ArchiveApiPathTraversal.rb:10:11:10:16 | call to params : | semmle.label | call to params : |
4043
| ArchiveApiPathTraversal.rb:10:11:10:23 | ...[...] : | semmle.label | ...[...] : |
41-
| ArchiveApiPathTraversal.rb:44:17:44:27 | destination : | semmle.label | destination : |
42-
| ArchiveApiPathTraversal.rb:47:28:47:67 | call to join : | semmle.label | call to join : |
43-
| ArchiveApiPathTraversal.rb:47:38:47:48 | destination : | semmle.label | destination : |
44-
| ArchiveApiPathTraversal.rb:54:21:54:36 | destination_file | semmle.label | destination_file |
45-
| ArchiveApiPathTraversal.rb:62:13:62:16 | file : | semmle.label | file : |
46-
| ArchiveApiPathTraversal.rb:63:20:63:23 | file | semmle.label | file |
44+
| ArchiveApiPathTraversal.rb:15:9:15:14 | call to params : | semmle.label | call to params : |
45+
| ArchiveApiPathTraversal.rb:15:9:15:25 | ...[...] : | semmle.label | ...[...] : |
46+
| ArchiveApiPathTraversal.rb:49:17:49:27 | destination : | semmle.label | destination : |
47+
| ArchiveApiPathTraversal.rb:52:28:52:67 | call to join : | semmle.label | call to join : |
48+
| ArchiveApiPathTraversal.rb:52:38:52:48 | destination : | semmle.label | destination : |
49+
| ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file | semmle.label | destination_file |
50+
| ArchiveApiPathTraversal.rb:67:13:67:16 | file : | semmle.label | file : |
51+
| ArchiveApiPathTraversal.rb:68:20:68:23 | file | semmle.label | file |
52+
| ArchiveApiPathTraversal.rb:75:11:75:18 | filename : | semmle.label | filename : |
53+
| ArchiveApiPathTraversal.rb:76:19:76:26 | filename | semmle.label | filename |
4754
| tainted_path.rb:4:12:4:17 | call to params : | semmle.label | call to params : |
4855
| tainted_path.rb:4:12:4:24 | ...[...] : | semmle.label | ...[...] : |
4956
| tainted_path.rb:5:26:5:29 | path | semmle.label | path |
@@ -81,8 +88,9 @@ nodes
8188
| tainted_path.rb:60:26:60:29 | path | semmle.label | path |
8289
subpaths
8390
#select
84-
| ArchiveApiPathTraversal.rb:54:21:54:36 | destination_file | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params : | ArchiveApiPathTraversal.rb:54:21:54:36 | destination_file | This path depends on $@. | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params | a user-provided value |
85-
| ArchiveApiPathTraversal.rb:63:20:63:23 | file | ArchiveApiPathTraversal.rb:10:11:10:16 | call to params : | ArchiveApiPathTraversal.rb:63:20:63:23 | file | This path depends on $@. | ArchiveApiPathTraversal.rb:10:11:10:16 | call to params | a user-provided value |
91+
| ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params : | ArchiveApiPathTraversal.rb:59:21:59:36 | destination_file | This path depends on $@. | ArchiveApiPathTraversal.rb:5:26:5:31 | call to params | a user-provided value |
92+
| ArchiveApiPathTraversal.rb:68:20:68:23 | file | ArchiveApiPathTraversal.rb:10:11:10:16 | call to params : | ArchiveApiPathTraversal.rb:68:20:68:23 | file | This path depends on $@. | ArchiveApiPathTraversal.rb:10:11:10:16 | call to params | a user-provided value |
93+
| ArchiveApiPathTraversal.rb:76:19:76:26 | filename | ArchiveApiPathTraversal.rb:15:9:15:14 | call to params : | ArchiveApiPathTraversal.rb:76:19:76:26 | filename | This path depends on $@. | ArchiveApiPathTraversal.rb:15:9:15:14 | call to params | a user-provided value |
8694
| tainted_path.rb:5:26:5:29 | path | tainted_path.rb:4:12:4:17 | call to params : | tainted_path.rb:5:26:5:29 | path | This path depends on $@. | tainted_path.rb:4:12:4:17 | call to params | a user-provided value |
8795
| tainted_path.rb:11:26:11:29 | path | tainted_path.rb:10:31:10:36 | call to params : | tainted_path.rb:11:26:11:29 | path | This path depends on $@. | tainted_path.rb:10:31:10:36 | call to params | a user-provided value |
8896
| tainted_path.rb:17:26:17:29 | path | tainted_path.rb:16:28:16:33 | call to params : | tainted_path.rb:17:26:17:29 | path | This path depends on $@. | tainted_path.rb:16:28:16:33 | call to params | a user-provided value |

0 commit comments

Comments
 (0)