Skip to content

Commit b741453

Browse files
Add test cases
1 parent 507a610 commit b741453

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,9 @@ private module MassAssignmentSinks {
811811
name =
812812
[
813813
"build", "create", "create!", "create_with", "create_or_find_by",
814-
"create_or_find_by!", "find_or_create_by", "find_or_create_by!", "insert", "insert!",
815-
"insert_all", "insert_all!", "instantiate", "new", "update", "update!", "upsert",
816-
"upsert_all"
814+
"create_or_find_by!", "find_or_create_by", "find_or_create_by!",
815+
"find_or_initialize_by", "insert", "insert!", "insert_all", "insert_all!",
816+
"instantiate", "new", "update", "update!", "upsert", "upsert_all"
817817
] and
818818
this = call.getArgument(0)
819819
or
Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,81 @@
11
edges
2-
| test.rb:17:9:17:14 | call to params | test.rb:17:9:17:29 | call to require | provenance | |
3-
| test.rb:17:9:17:29 | call to require | test.rb:17:9:17:37 | call to permit! | provenance | |
4-
| test.rb:17:9:17:37 | call to permit! | test.rb:8:18:8:28 | call to user_params | provenance | |
2+
| test.rb:23:25:23:37 | call to [] [element 0] | test.rb:23:25:23:37 | call to [] | provenance | |
3+
| test.rb:23:26:23:36 | call to user_params | test.rb:23:25:23:37 | call to [] [element 0] | provenance | |
4+
| test.rb:24:26:24:38 | call to [] [element 0] | test.rb:24:26:24:38 | call to [] | provenance | |
5+
| test.rb:24:27:24:37 | call to user_params | test.rb:24:26:24:38 | call to [] [element 0] | provenance | |
6+
| test.rb:30:21:30:33 | call to [] [element 0] | test.rb:30:21:30:33 | call to [] | provenance | |
7+
| test.rb:30:22:30:32 | call to user_params | test.rb:30:21:30:33 | call to [] [element 0] | provenance | |
8+
| test.rb:43:9:43:14 | call to params | test.rb:43:9:43:29 | call to require | provenance | |
9+
| test.rb:43:9:43:29 | call to require | test.rb:43:9:43:37 | call to permit! | provenance | |
10+
| test.rb:43:9:43:37 | call to permit! | test.rb:8:18:8:28 | call to user_params | provenance | |
11+
| test.rb:43:9:43:37 | call to permit! | test.rb:18:20:18:30 | call to user_params | provenance | |
12+
| test.rb:43:9:43:37 | call to permit! | test.rb:19:21:19:31 | call to user_params | provenance | |
13+
| test.rb:43:9:43:37 | call to permit! | test.rb:20:22:20:32 | call to user_params | provenance | |
14+
| test.rb:43:9:43:37 | call to permit! | test.rb:21:21:21:31 | call to user_params | provenance | |
15+
| test.rb:43:9:43:37 | call to permit! | test.rb:22:22:22:32 | call to user_params | provenance | |
16+
| test.rb:43:9:43:37 | call to permit! | test.rb:23:26:23:36 | call to user_params | provenance | |
17+
| test.rb:43:9:43:37 | call to permit! | test.rb:24:27:24:37 | call to user_params | provenance | |
18+
| test.rb:43:9:43:37 | call to permit! | test.rb:25:21:25:31 | call to user_params | provenance | |
19+
| test.rb:43:9:43:37 | call to permit! | test.rb:26:24:26:34 | call to user_params | provenance | |
20+
| test.rb:43:9:43:37 | call to permit! | test.rb:27:22:27:32 | call to user_params | provenance | |
21+
| test.rb:43:9:43:37 | call to permit! | test.rb:28:25:28:35 | call to user_params | provenance | |
22+
| test.rb:43:9:43:37 | call to permit! | test.rb:29:21:29:31 | call to user_params | provenance | |
23+
| test.rb:43:9:43:37 | call to permit! | test.rb:30:22:30:32 | call to user_params | provenance | |
24+
| test.rb:43:9:43:37 | call to permit! | test.rb:31:32:31:42 | call to user_params | provenance | |
25+
| test.rb:43:9:43:37 | call to permit! | test.rb:32:33:32:43 | call to user_params | provenance | |
26+
| test.rb:43:9:43:37 | call to permit! | test.rb:33:36:33:46 | call to user_params | provenance | |
27+
| test.rb:43:9:43:37 | call to permit! | test.rb:34:32:34:42 | call to user_params | provenance | |
28+
| test.rb:43:9:43:37 | call to permit! | test.rb:35:33:35:43 | call to user_params | provenance | |
29+
| test.rb:43:9:43:37 | call to permit! | test.rb:36:26:36:36 | call to user_params | provenance | |
530
nodes
631
| test.rb:8:18:8:28 | call to user_params | semmle.label | call to user_params |
7-
| test.rb:17:9:17:14 | call to params | semmle.label | call to params |
8-
| test.rb:17:9:17:29 | call to require | semmle.label | call to require |
9-
| test.rb:17:9:17:37 | call to permit! | semmle.label | call to permit! |
32+
| test.rb:18:20:18:30 | call to user_params | semmle.label | call to user_params |
33+
| test.rb:19:21:19:31 | call to user_params | semmle.label | call to user_params |
34+
| test.rb:20:22:20:32 | call to user_params | semmle.label | call to user_params |
35+
| test.rb:21:21:21:31 | call to user_params | semmle.label | call to user_params |
36+
| test.rb:22:22:22:32 | call to user_params | semmle.label | call to user_params |
37+
| test.rb:23:25:23:37 | call to [] | semmle.label | call to [] |
38+
| test.rb:23:25:23:37 | call to [] [element 0] | semmle.label | call to [] [element 0] |
39+
| test.rb:23:26:23:36 | call to user_params | semmle.label | call to user_params |
40+
| test.rb:24:26:24:38 | call to [] | semmle.label | call to [] |
41+
| test.rb:24:26:24:38 | call to [] [element 0] | semmle.label | call to [] [element 0] |
42+
| test.rb:24:27:24:37 | call to user_params | semmle.label | call to user_params |
43+
| test.rb:25:21:25:31 | call to user_params | semmle.label | call to user_params |
44+
| test.rb:26:24:26:34 | call to user_params | semmle.label | call to user_params |
45+
| test.rb:27:22:27:32 | call to user_params | semmle.label | call to user_params |
46+
| test.rb:28:25:28:35 | call to user_params | semmle.label | call to user_params |
47+
| test.rb:29:21:29:31 | call to user_params | semmle.label | call to user_params |
48+
| test.rb:30:21:30:33 | call to [] | semmle.label | call to [] |
49+
| test.rb:30:21:30:33 | call to [] [element 0] | semmle.label | call to [] [element 0] |
50+
| test.rb:30:22:30:32 | call to user_params | semmle.label | call to user_params |
51+
| test.rb:31:32:31:42 | call to user_params | semmle.label | call to user_params |
52+
| test.rb:32:33:32:43 | call to user_params | semmle.label | call to user_params |
53+
| test.rb:33:36:33:46 | call to user_params | semmle.label | call to user_params |
54+
| test.rb:34:32:34:42 | call to user_params | semmle.label | call to user_params |
55+
| test.rb:35:33:35:43 | call to user_params | semmle.label | call to user_params |
56+
| test.rb:36:26:36:36 | call to user_params | semmle.label | call to user_params |
57+
| test.rb:43:9:43:14 | call to params | semmle.label | call to params |
58+
| test.rb:43:9:43:29 | call to require | semmle.label | call to require |
59+
| test.rb:43:9:43:37 | call to permit! | semmle.label | call to permit! |
1060
subpaths
1161
#select
12-
| test.rb:8:18:8:28 | call to user_params | test.rb:17:9:17:14 | call to params | test.rb:8:18:8:28 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:17:9:17:14 | call to params | this remote flow source |
62+
| test.rb:8:18:8:28 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:8:18:8:28 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
63+
| test.rb:18:20:18:30 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:18:20:18:30 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
64+
| test.rb:19:21:19:31 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:19:21:19:31 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
65+
| test.rb:20:22:20:32 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:20:22:20:32 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
66+
| test.rb:21:21:21:31 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:21:21:21:31 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
67+
| test.rb:22:22:22:32 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:22:22:22:32 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
68+
| test.rb:23:25:23:37 | call to [] | test.rb:43:9:43:14 | call to params | test.rb:23:25:23:37 | call to [] | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
69+
| test.rb:24:26:24:38 | call to [] | test.rb:43:9:43:14 | call to params | test.rb:24:26:24:38 | call to [] | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
70+
| test.rb:25:21:25:31 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:25:21:25:31 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
71+
| test.rb:26:24:26:34 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:26:24:26:34 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
72+
| test.rb:27:22:27:32 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:27:22:27:32 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
73+
| test.rb:28:25:28:35 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:28:25:28:35 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
74+
| test.rb:29:21:29:31 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:29:21:29:31 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
75+
| test.rb:30:21:30:33 | call to [] | test.rb:43:9:43:14 | call to params | test.rb:30:21:30:33 | call to [] | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
76+
| test.rb:31:32:31:42 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:31:32:31:42 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
77+
| test.rb:32:33:32:43 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:32:33:32:43 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
78+
| test.rb:33:36:33:46 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:33:36:33:46 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
79+
| test.rb:34:32:34:42 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:34:32:34:42 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
80+
| test.rb:35:33:35:43 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:35:33:35:43 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |
81+
| test.rb:36:26:36:36 | call to user_params | test.rb:43:9:43:14 | call to params | test.rb:36:26:36:36 | call to user_params | This mass assignment operation can assign user-controlled attributes from $@. | test.rb:43:9:43:14 | call to params | this remote flow source |

ruby/ql/test/query-tests/security/cwe-915/test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ def create2
1313
User.new(params[:user].permit(:name,:address))
1414
end
1515

16+
def create3
17+
# each BAD
18+
User.build(user_params)
19+
User.create(user_params)
20+
User.create!(user_params)
21+
User.insert(user_params)
22+
User.insert!(user_params)
23+
User.insert_all([user_params])
24+
User.insert_all!([user_params])
25+
User.update(user_params)
26+
User.update(7, user_params)
27+
User.update!(user_params)
28+
User.update!(7, user_params)
29+
User.upsert(user_params)
30+
User.upsert([user_params])
31+
User.find_or_create_by(user_params)
32+
User.find_or_create_by!(user_params)
33+
User.find_or_initialize_by(user_params)
34+
User.create_or_find_by(user_params)
35+
User.create_or_find_by!(user_params)
36+
User.create_with(user_params)
37+
38+
user = User.where(name:"abc")
39+
user.update(user_params)
40+
end
41+
1642
def user_params
1743
params.require(:user).permit!
1844
end

0 commit comments

Comments
 (0)