Skip to content

Commit e4da0b3

Browse files
djbrownsigmavirus24ericwb
authored
Remove lxml (B320 & B410) from blacklist (#1212)
* remove B320 (xml_bad_etree) and B410 (import_lxml) * restore lxml documentation and denote removal * fix missing newline Co-authored-by: Ian Stapleton Cordasco <graffatcolmingov@gmail.com> --------- Co-authored-by: Ian Stapleton Cordasco <graffatcolmingov@gmail.com> Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
1 parent 13d3406 commit e4da0b3

File tree

4 files changed

+15
-51
lines changed

4 files changed

+15
-51
lines changed

bandit/blacklists/calls.py

+11-21
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
| B312 | telnetlib | - telnetlib.\* | High |
220220
+------+---------------------+------------------------------------+-----------+
221221
222-
B313 - B320: XML
222+
B313 - B319: XML
223223
----------------
224224
225225
Most of this is based off of Christian Heimes' work on defusedxml:
@@ -256,6 +256,15 @@
256256
| B319 | xml_bad_pulldom | - xml.dom.pulldom.parse | Medium |
257257
| | | - xml.dom.pulldom.parseString | |
258258
+------+---------------------+------------------------------------+-----------+
259+
260+
B320: xml_bad_etree
261+
-------------------
262+
263+
The check for this call has been removed.
264+
265+
+------+---------------------+------------------------------------+-----------+
266+
| ID | Name | Calls | Severity |
267+
+======+=====================+====================================+===========+
259268
| B320 | xml_bad_etree | - lxml.etree.parse | Medium |
260269
| | | - lxml.etree.fromstring | |
261270
| | | - lxml.etree.RestrictedElement | |
@@ -615,26 +624,7 @@ def gen_blacklist():
615624
)
616625
)
617626

618-
sets.append(
619-
utils.build_conf_dict(
620-
"xml_bad_etree",
621-
"B320",
622-
issue.Cwe.IMPROPER_INPUT_VALIDATION,
623-
[
624-
"lxml.etree.parse",
625-
"lxml.etree.fromstring",
626-
"lxml.etree.RestrictedElement",
627-
"lxml.etree.GlobalParserTLS",
628-
"lxml.etree.getDefaultParser",
629-
"lxml.etree.check_docinfo",
630-
],
631-
(
632-
"Using {name} to parse untrusted XML data is known to be "
633-
"vulnerable to XML attacks. Replace {name} with its "
634-
"defusedxml equivalent function."
635-
),
636-
)
637-
)
627+
# skipped B320 as the check for a call to lxml.etree has been removed
638628

639629
# end of XML tests
640630

bandit/blacklists/imports.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
B410: import_lxml
134134
-----------------
135135
136+
This import blacklist has been removed. The information here has been
137+
left for historical purposes.
138+
136139
Using various methods to parse untrusted XML data is known to be vulnerable to
137140
XML attacks. Replace vulnerable imports with the equivalent defusedxml package.
138141
@@ -297,11 +300,6 @@ def gen_blacklist():
297300
"defusedxml package, or make sure defusedxml.defuse_stdlib() "
298301
"is called."
299302
)
300-
lxml_msg = (
301-
"Using {name} to parse untrusted XML data is known to be "
302-
"vulnerable to XML attacks. Replace {name} with the "
303-
"equivalent defusedxml package."
304-
)
305303

306304
sets.append(
307305
utils.build_conf_dict(
@@ -358,16 +356,7 @@ def gen_blacklist():
358356
)
359357
)
360358

361-
sets.append(
362-
utils.build_conf_dict(
363-
"import_lxml",
364-
"B410",
365-
issue.Cwe.IMPROPER_INPUT_VALIDATION,
366-
["lxml"],
367-
lxml_msg,
368-
"LOW",
369-
)
370-
)
359+
# skipped B410 as the check for import_lxml has been removed
371360

372361
sets.append(
373362
utils.build_conf_dict(

examples/xml_lxml.py

-9
This file was deleted.

tests/functional/test_functional.py

-6
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,6 @@ def test_xml(self):
556556
}
557557
self.check_example("xml_expatbuilder.py", expect)
558558

559-
expect = {
560-
"SEVERITY": {"UNDEFINED": 0, "LOW": 3, "MEDIUM": 1, "HIGH": 0},
561-
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},
562-
}
563-
self.check_example("xml_lxml.py", expect)
564-
565559
expect = {
566560
"SEVERITY": {"UNDEFINED": 0, "LOW": 2, "MEDIUM": 2, "HIGH": 0},
567561
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},

0 commit comments

Comments
 (0)