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 {
4242 override predicate disablesCertificateValidation (
4343 DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
4444 ) {
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
4647 none ( )
4748 }
4849 }
@@ -63,7 +64,8 @@ private module Urllib {
6364 override predicate disablesCertificateValidation (
6465 DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
6566 ) {
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
6769 none ( )
6870 }
6971 }
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ private module Urllib2 {
3030 override predicate disablesCertificateValidation (
3131 DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
3232 ) {
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
3435 none ( )
3536 }
3637 }
@@ -49,7 +50,8 @@ private module Urllib2 {
4950 override predicate disablesCertificateValidation (
5051 DataFlow:: Node disablingNode , DataFlow:: Node argumentOrigin
5152 ) {
52- // TODO: Look into disabling certificate validation
53+ // will validate certificate by default
54+ // TODO: Handling of insecure SSLContext passed to context argument
5355 none ( )
5456 }
5557 }
Original file line number Diff line number Diff line change 11import urllib2
2+ import ssl
23
34resp = urllib2 .Request ("url" ) # $ clientRequestUrlPart="url"
45resp = urllib2 .Request (url = "url" ) # $ clientRequestUrlPart="url"
56
67resp = 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
12from urllib .request import Request , urlopen
23
34Request ("url" ) # $ clientRequestUrlPart="url"
45Request (url = "url" ) # $ clientRequestUrlPart="url"
56
67urlopen ("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