File tree Expand file tree Collapse file tree 4 files changed +36
-6
lines changed
lib/semmle/python/frameworks/Stdlib
test/library-tests/frameworks Expand file tree Collapse file tree 4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ private module Urllib {
42
42
override predicate disablesCertificateValidation (
43
43
DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
44
44
) {
45
- // TODO: Look into disabling certificate validation
45
+ // cannot enable/disable certificate validation on this object, only when used
46
+ // with `urlopen`, which is modeled below
46
47
none ( )
47
48
}
48
49
}
@@ -63,7 +64,8 @@ private module Urllib {
63
64
override predicate disablesCertificateValidation (
64
65
DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
65
66
) {
66
- // TODO: Look into disabling certificate validation
67
+ // will validate certificate by default, see https://github.com/python/cpython/blob/243ed5439c32e8517aa745bc2ca9774d99c99d0f/Lib/http/client.py#L1420-L1421
68
+ // TODO: Handling of insecure SSLContext passed to context argument
67
69
none ( )
68
70
}
69
71
}
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ private module Urllib2 {
30
30
override predicate disablesCertificateValidation (
31
31
DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
32
32
) {
33
- // TODO: Look into disabling certificate validation
33
+ // cannot enable/disable certificate validation on this object, only when used
34
+ // with `urlopen`, which is modeled below
34
35
none ( )
35
36
}
36
37
}
@@ -49,7 +50,8 @@ private module Urllib2 {
49
50
override predicate disablesCertificateValidation (
50
51
DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
51
52
) {
52
- // TODO: Look into disabling certificate validation
53
+ // will validate certificate by default
54
+ // TODO: Handling of insecure SSLContext passed to context argument
53
55
none ( )
54
56
}
55
57
}
Original file line number Diff line number Diff line change 1
1
import urllib2
2
+ import ssl
2
3
3
4
resp = urllib2 .Request ("url" ) # $ clientRequestUrlPart="url"
4
5
resp = urllib2 .Request (url = "url" ) # $ clientRequestUrlPart="url"
5
6
6
7
resp = urllib2 .urlopen ("url" ) # $ clientRequestUrlPart="url"
7
- resp = urllib2 .urlopen (url = "url" ) # $ clientRequestUrlPart="url"
8
+ resp = urllib2 .urlopen (url = "url" ) # $ clientRequestUrlPart="url"
9
+
10
+ # ==============================================================================
11
+ # Certificate validation disabled
12
+ # ==============================================================================
13
+
14
+ # A manually constructed SSLContext does not have safe defaults, so is effectively the
15
+ # same as turning off SSL validation
16
+ context = ssl .SSLContext ()
17
+ assert context .check_hostname == False
18
+ assert context .verify_mode == ssl .VerifyMode .CERT_NONE
19
+
20
+ urllib2 .urlopen ("url" , context = context ) # $ clientRequestUrlPart="url" MISSING: clientRequestCertValidationDisabled
Original file line number Diff line number Diff line change
1
+ import ssl
1
2
from urllib .request import Request , urlopen
2
3
3
4
Request ("url" ) # $ clientRequestUrlPart="url"
4
5
Request (url = "url" ) # $ clientRequestUrlPart="url"
5
6
6
7
urlopen ("url" ) # $ clientRequestUrlPart="url"
7
- urlopen (url = "url" ) # $ clientRequestUrlPart="url"
8
+ urlopen (url = "url" ) # $ clientRequestUrlPart="url"
9
+
10
+ # ==============================================================================
11
+ # Certificate validation disabled
12
+ # ==============================================================================
13
+
14
+ # A manually constructed SSLContext does not have safe defaults, so is effectively the
15
+ # same as turning off SSL validation
16
+ context = ssl .SSLContext ()
17
+ assert context .check_hostname == False
18
+ assert context .verify_mode == ssl .VerifyMode .CERT_NONE
19
+
20
+ urlopen ("url" , context = context ) # $ clientRequestUrlPart="url" MISSING: clientRequestCertValidationDisabled
You can’t perform that action at this time.
0 commit comments