Skip to content

Use defusedxml for Parsing XML#1

Open
pixeebot[bot] wants to merge 1 commit intodevelopfrom
pixeebot/drip-2024-06-20-pixee-python/use-defusedxml
Open

Use defusedxml for Parsing XML#1
pixeebot[bot] wants to merge 1 commit intodevelopfrom
pixeebot/drip-2024-06-20-pixee-python/use-defusedxml

Conversation

@pixeebot
Copy link
Copy Markdown

@pixeebot pixeebot Bot commented Jun 20, 2024

You might be surprised to learn that Python's built-in XML libraries are considered insecure against various kinds of attacks.

In fact, the Python documentation itself recommends the use of defusedxml for parsing untrusted XML data. defusedxml is an open-source, 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:

- from xml.etree.ElementTree import parse
+ import defusedxml.ElementTree

- et = parse('data.xml')
+ et = defusedxml.ElementTree.parse('data.xml')

Dependency Updates

This codemod relies on an external dependency. We have automatically added this dependency to your project's requirements.txt file.

This package is recommended by the Python community to protect against XML vulnerabilities.

There are a number of places where Python project dependencies can be expressed, including setup.py, pyproject.toml, setup.cfg, and requirements.txt files. If this change is incorrect, or if you are using another packaging system such as poetry, it may be necessary for you to manually add the dependency to the proper location in your project.

More reading

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

🧚🤖 Powered by Pixeebot

Feedback | Community | Docs | Codemod ID: pixee:python/use-defusedxml

Comment thread requirements.txt
rsa>=3.1.2,<=3.5.0
wheel==0.24.0
PyYAML>=3.10,<=3.13
defusedxml==0.7.1
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package is recommended by the Python community to protect against XML vulnerabilities.

License: PSF-2.0Open SourceMore facts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants