Skip to content

Commit 45e864a

Browse files
committed
Python: New query to test for requests without validation.
1 parent f0206a2 commit 45e864a

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @name Request Without Certificate Validation
3+
* @description Making a request without certificate validation can allow man-in-the-middle attacks.
4+
* @kind problem
5+
* @problem.severity error
6+
* @precision medium
7+
* @id py/request-without-cert-validation
8+
* @tags security
9+
* external/cwe/cwe-295
10+
*/
11+
12+
import python
13+
14+
import semmle.python.web.Http
15+
16+
17+
FunctionObject requestFunction() {
18+
exists(ModuleObject req |
19+
req.getName() = "requests" and
20+
result = req.getAttribute(httpVerbLower())
21+
)
22+
}
23+
24+
from CallNode call, FunctionObject func, ControlFlowNode false_
25+
where
26+
func = requestFunction() and
27+
func.getACall() = call and
28+
call.getArgByName("verify").refersTo(theFalseObject(), false_)
29+
30+
select call, "Call to $@ with verify=$@", func, "requests." + func.getName(), false_, "False"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| make_request.py:5:1:5:48 | ControlFlowNode for Attribute() | Call to $@ with verify=$@ | ../lib/requests.py:2:1:2:36 | Function get | requests.get | make_request.py:5:43:5:47 | ControlFlowNode for False | False |
2+
| make_request.py:7:1:7:49 | ControlFlowNode for Attribute() | Call to $@ with verify=$@ | ../lib/requests.py:11:1:11:46 | Function post | requests.post | make_request.py:7:44:7:48 | ControlFlowNode for False | False |
3+
| make_request.py:12:1:12:39 | ControlFlowNode for put() | Call to $@ with verify=$@ | ../lib/requests.py:14:1:14:34 | Function put | requests.put | make_request.py:12:34:12:38 | ControlFlowNode for False | False |
4+
| make_request.py:28:5:28:46 | ControlFlowNode for patch() | Call to $@ with verify=$@ | ../lib/requests.py:17:1:17:36 | Function patch | requests.patch | make_request.py:30:6:30:10 | ControlFlowNode for False | False |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE-295/RequestWithoutValidation.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: -p ../lib/ --max-import-depth=3

0 commit comments

Comments
 (0)