-
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.
- Loading branch information
1 parent
20af62a
commit c294b1c
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/core_codemods/docs/pixee_python_safe-lxml-parser-defaults.md
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,22 @@ | ||
This codemod configures safe parameter values when initializing `lxml.etree.XMLParser`, `lxml.etree.ETCompatXMLParser`, | ||
`lxml.etree.XMLTreeBuilder`, or `lxml.etree.XMLPullParser`. If parameters `resolve_entities`, `no_network`, | ||
and `dtd_validation` are not set to safe values, your code may be vulnerable to entity expansion | ||
attacks and external entity (XXE) attacks. | ||
|
||
Parameters `no_network` and `dtd_validation` have safe default values of `True` and `False`, respectively, so this | ||
codemod will set each to the default safe value if your code has assigned either to an unsafe value. | ||
|
||
Parameter `resolve_entities` has an unsafe default value of `True`. This codemod will set `resolve_entities=False` if set to `True` or omitted. | ||
|
||
The changes look as follows: | ||
|
||
```diff | ||
import lxml | ||
|
||
- parser = lxml.etree.XMLParser() | ||
- parser = lxml.etree.XMLParser(resolve_entities=True) | ||
- parser = lxml.etree.XMLParser(resolve_entities=True, no_network=False, dtd_validation=True) | ||
+ parser = lxml.etree.XMLParser(resolve_entities=False) | ||
+ parser = lxml.etree.XMLParser(resolve_entities=False) | ||
+ parser = lxml.etree.XMLParser(resolve_entities=False, no_network=True, dtd_validation=False) | ||
``` |