@@ -3,7 +3,8 @@ defmodule Sobelow.SQL.Query do
3
3
# SQL Injection in Query
4
4
5
5
This submodule of the `SQL` module checks for SQL injection
6
- vulnerabilities through usage of the `Ecto.Adapters.SQL.query`.
6
+ vulnerabilities through usage of the `Ecto.Adapters.SQL.query`
7
+ and `Ecto.Adapters.SQL.query!`.
7
8
8
9
Ensure that the query is parameterized and not user-controlled.
9
10
@@ -13,27 +14,32 @@ defmodule Sobelow.SQL.Query do
13
14
"""
14
15
@ uid 17
15
16
@ finding_type "SQL.Query: SQL injection"
17
+ @ query_funcs [ :query , :query! ]
16
18
17
19
use Sobelow.Finding
18
20
19
21
def run ( fun , meta_file ) do
20
22
confidence = if ! meta_file . is_controller? , do: :low
21
23
22
- Finding . init ( @ finding_type , meta_file . filename , confidence )
23
- |> Finding . multi_from_def ( fun , parse_sql_def ( fun ) )
24
- |> Enum . each ( & Print . add_finding ( & 1 ) )
25
-
26
- Finding . init ( @ finding_type , meta_file . filename , confidence )
27
- |> Finding . multi_from_def ( fun , parse_repo_query_def ( fun ) )
28
- |> Enum . each ( & Print . add_finding ( & 1 ) )
24
+ Enum . each ( @ query_funcs , fn query_func ->
25
+ Finding . init ( @ finding_type , meta_file . filename , confidence )
26
+ |> Finding . multi_from_def ( fun , parse_sql_def ( fun , query_func ) )
27
+ |> Enum . each ( & Print . add_finding ( & 1 ) )
28
+ end )
29
+
30
+ Enum . each ( @ query_funcs , fn query_func ->
31
+ Finding . init ( @ finding_type , meta_file . filename , confidence )
32
+ |> Finding . multi_from_def ( fun , parse_repo_query_def ( fun , query_func ) )
33
+ |> Enum . each ( & Print . add_finding ( & 1 ) )
34
+ end )
29
35
end
30
36
31
37
## query(repo, sql, params \\ [], opts \\ [])
32
- def parse_sql_def ( fun ) do
33
- Parse . get_fun_vars_and_meta ( fun , 1 , :query , :SQL )
38
+ def parse_sql_def ( fun , type ) do
39
+ Parse . get_fun_vars_and_meta ( fun , 1 , type , :SQL )
34
40
end
35
41
36
- def parse_repo_query_def ( fun ) do
37
- Parse . get_fun_vars_and_meta ( fun , 0 , :query , :Repo )
42
+ def parse_repo_query_def ( fun , type ) do
43
+ Parse . get_fun_vars_and_meta ( fun , 0 , type , :Repo )
38
44
end
39
45
end
0 commit comments