File tree Expand file tree Collapse file tree 2 files changed +48
-14
lines changed
python/ql/src/experimental/Security/CWE-730/unit_tests Expand file tree Collapse file tree 2 files changed +48
-14
lines changed Original file line number Diff line number Diff line change 1
- # move outside test folder
2
-
3
1
from flask import request , Flask
4
2
import re
5
3
8
6
9
7
@app .route ("/direct" )
10
8
def direct ():
11
- pattern = request .args ['pattern' ]
12
- re .search (pattern , "" )
9
+ """
10
+ A RemoteFlowSource is used directly as re.search's pattern
11
+ """
12
+
13
+ unsafe_pattern = request .args ["pattern" ]
14
+ re .search (unsafe_pattern , "" )
15
+
13
16
17
+ # A RemoteFlowSource is used directly as re.compile's pattern
14
18
15
19
@app .route ("/compile" )
16
20
def compile ():
17
- pattern = re .compile (request .args ['pattern' ])
18
- pattern .search ("" )
21
+ """
22
+ A RemoteFlowSource is used directly as re.compile's pattern
23
+ which also executes .search()
24
+ """
25
+
26
+ unsafe_pattern = request .args ["pattern" ]
27
+ compiled_pattern = re .compile (unsafe_pattern )
28
+ compiled_pattern .search ("" )
19
29
20
30
21
31
@app .route ("/compile_direct" )
22
32
def compile_direct ():
23
- re .compile (request .args ['pattern' ]).search ("" )
33
+ """
34
+ A RemoteFlowSource is used directly as re.compile's pattern
35
+ which also executes .search() in the same line
36
+ """
37
+
38
+ unsafe_pattern = request .args ["pattern" ]
39
+ re .compile (unsafe_pattern ).search ("" )
24
40
25
41
# if __name__ == "__main__":
26
42
# app.run(debug=True)
Original file line number Diff line number Diff line change 1
- # move outside test folder
2
-
3
1
from flask import request , Flask
4
2
import re
5
3
8
6
9
7
@app .route ("/direct" )
10
8
def direct ():
11
- pattern = re .escape (request .args ['pattern' ])
12
- re .search (pattern , "" )
9
+ """
10
+ A RemoteFlowSource is escaped by re.escape and then used as
11
+ re'search pattern
12
+ """
13
+
14
+ unsafe_pattern = request .args ['pattern' ]
15
+ safe_pattern = re .escape (unsafe_pattern )
16
+ re .search (safe_pattern , "" )
13
17
14
18
15
19
@app .route ("/compile" )
16
20
def compile ():
17
- pattern = re .compile (re .escape (request .args ['pattern' ]))
18
- pattern .search ("" )
21
+ """
22
+ A RemoteFlowSource is escaped by re.escape and used as re.compile's
23
+ pattern which also executes .search()
24
+ """
25
+
26
+ unsafe_pattern = request .args ['pattern' ]
27
+ safe_pattern = re .escape (unsafe_pattern )
28
+ compiled_pattern = re .compile (safe_pattern )
29
+ compiled_pattern .search ("" )
19
30
20
31
21
32
@app .route ("/compile_direct" )
22
33
def compile_direct ():
23
- re .compile (re .escape (request .args ['pattern' ])).search ("" )
34
+ """
35
+ A RemoteFlowSource is escaped by re.escape and then used as re.compile's
36
+ pattern which also executes .search() in the same line
37
+ """
38
+
39
+ unsafe_pattern = request .args ['pattern' ]
40
+ safe_pattern = re .escape (unsafe_pattern )
41
+ re .compile (safe_pattern ).search ("" )
24
42
25
43
26
44
# if __name__ == "__main__":
You can’t perform that action at this time.
0 commit comments