-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable use-defusedxml; add description
- Loading branch information
Showing
4 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
You might be surprised to learn that Python's standard library XML libraries are | ||
[considered insecure](https://docs.python.org/3/library/xml.html#xml-vulnerabilities) | ||
against various kinds of attacks. | ||
|
||
In fact, the [Python documentation | ||
itself](https://docs.python.org/3/library/xml.html#the-defusedxml-package) | ||
recommends the use of [defusedxml](https://pypi.org/project/defusedxml/) for | ||
parsing untrusted XML data. `defusedxml` is an | ||
[open-source](https://github.com/tiran/defusedxml), permissively licensed | ||
project that is intended as a drop-in replacement for Python's standard library | ||
XML parsers. | ||
|
||
This codemod updates all relevant uses of the standard library parsers with | ||
safe versions from `defusedxml`. It also adds the `defusedxml` dependency to | ||
your project where possible. | ||
|
||
The changes from this codemod look like this: | ||
```diff | ||
- from xml.etree.ElementTree import parse | ||
+ import defusedxml.ElementTree | ||
|
||
- et = parse('data.xml') | ||
+ et = defusedxml.ElementTree.parse('data.xml') | ||
``` |