Skip to content

Commit f78b785

Browse files
committed
Remove checks for Python2 urllib
Removal of checks for Python2 version of urllib and urllib2. Fixes #998 Signed-off-by: Eric Brown <eric_wade_brown@yahoo.com>
1 parent ff431af commit f78b785

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
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')

0 commit comments

Comments
 (0)