Skip to content

Commit 02d73e9

Browse files
authored
Remove checks for Python2 urllib (#999)
Removal of checks for Python2 version of urllib and urllib2. Fixes #998 Signed-off-by: Eric Brown <[email protected]>
1 parent ff431af commit 02d73e9

File tree

3 files changed

+4
-35
lines changed

3 files changed

+4
-35
lines changed

bandit/blacklists/calls.py

-6
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,10 @@ def gen_blacklist():
493493
"B310",
494494
issue.Cwe.PATH_TRAVERSAL,
495495
[
496-
"urllib.urlopen",
497496
"urllib.request.urlopen",
498-
"urllib.urlretrieve",
499497
"urllib.request.urlretrieve",
500-
"urllib.URLopener",
501498
"urllib.request.URLopener",
502-
"urllib.FancyURLopener",
503499
"urllib.request.FancyURLopener",
504-
"urllib2.urlopen",
505-
"urllib2.Request",
506500
"six.moves.urllib.request.urlopen",
507501
"six.moves.urllib.request.urlretrieve",
508502
"six.moves.urllib.request.URLopener",

examples/urlopen.py

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
1-
''' Example dangerous usage of urllib[2] opener functions
1+
''' Example dangerous usage of urllib.request opener functions
22
3-
The urllib and urllib2 opener functions and object can open http, ftp,
3+
The urllib.request opener functions and object can open http, ftp,
44
and file urls. Often, the ability to open file urls is overlooked leading
55
to code that can unexpectedly open files on the local server. This
66
could be used by an attacker to leak information about the server.
77
'''
88

9-
10-
import urllib
11-
import urllib2
12-
139
# Python 3
1410
import urllib.request
1511

1612
# Six
1713
import six
1814

1915
def test_urlopen():
20-
# urllib
21-
url = urllib.quote('file:///bin/ls')
22-
urllib.urlopen(url, 'blah', 32)
23-
urllib.urlretrieve('file:///bin/ls', '/bin/ls2')
24-
opener = urllib.URLopener()
25-
opener.open('file:///bin/ls')
26-
opener.retrieve('file:///bin/ls')
27-
opener = urllib.FancyURLopener()
28-
opener.open('file:///bin/ls')
29-
opener.retrieve('file:///bin/ls')
30-
31-
# urllib2
32-
handler = urllib2.HTTPBasicAuthHandler()
33-
handler.add_password(realm='test',
34-
uri='http://mysite.com',
35-
user='bob')
36-
opener = urllib2.build_opener(handler)
37-
urllib2.install_opener(opener)
38-
urllib2.urlopen('file:///bin/ls')
39-
urllib2.Request('file:///bin/ls')
40-
4116
# Python 3
4217
urllib.request.urlopen('file:///bin/ls')
4318
urllib.request.urlretrieve('file:///bin/ls', '/bin/ls2')

tests/functional/test_functional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ def test_subprocess_shell(self):
513513
def test_urlopen(self):
514514
"""Test for dangerous URL opening."""
515515
expect = {
516-
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 14, "HIGH": 0},
517-
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 14},
516+
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 8, "HIGH": 0},
517+
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 8},
518518
}
519519
self.check_example("urlopen.py", expect)
520520

0 commit comments

Comments
 (0)