File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
python/ql/src/Security/CWE-295 Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE qhelp PUBLIC
2+ "-//Semmle//qhelp//EN"
3+ "qhelp.dtd">
4+ <qhelp >
5+
6+ <overview >
7+ <p >
8+ Encryption is key to the security of most, if not all, online communication.
9+ Using TLS can enusre that neither party in the communication is an interloper.
10+ For this reason, is is unwise to disable the verification that TLS provides.
11+ <code >requests</code > provides verification by default, and it is only when
12+ explicitly turned off using <code >verify=False</code > that no verification occurs.
13+ </p >
14+ </overview >
15+
16+ <recommendation >
17+ <p >
18+ Never use <code >verify=False</code > when making a request.
19+ </p >
20+ </recommendation >
21+
22+ <example >
23+ <p >
24+ The example shows an unsafe call to <a href =" https://semmle.com" >semmle.com</a >, followed by various safe alternatives.
25+ </p >
26+
27+ <sample src =" examples/make_request.py" />
28+ </example >
29+
30+ <references >
31+ <li >
32+ Common Weakness Enumeration:
33+ <a href =" https://cwe.mitre.org/data/definitions/295.html" >CWE-295: Improper Certificate Validation</a >.
34+ </li >
35+ <li >
36+ Python requests documentation: <a href =" http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification" >SSL Cert Verification</a >.
37+ </li >
38+ </references >
39+ </qhelp >
40+
Original file line number Diff line number Diff line change 1+ import requests
2+
3+ #An unsafe request
4+
5+ requests .get ('https://semmle.com' , verify = False ) # UNSAFE
6+
7+ #Various safe options
8+
9+ requests .get ('https://semmle.com' , verify = True ) # Explicitly safe
10+ requests .get ('https://semmle.com' , verify = "/path/to/cert/" )
11+ requests .get ('https://semmle.com' ) # The default is to verify.
12+
13+ #Wrapper to ensure safety
14+
15+ def make_safe_request (url , verify_cert ):
16+ if not verify_cert :
17+ raise Exception ("Trying to make unsafe request" )
18+ return requests .get (url , verify_cert )
You can’t perform that action at this time.
0 commit comments