-
-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lxml guidance is not useful #767
Comments
I suppose lxml could have been brought into compliance in the meantime? |
#435 was falsely closed as invalid some time ago.. AFAIK lxml actually provides secure parsing by now, users just have to apply it correctly. |
Security assessment of lxml as of https://github.com/tiran/defusedxml#python-xml-libraries:
Bandit could check for insecure use of lxml and suggest using lxml safely |
Bandit only pointed it out and [wasn't particularly helpful](PyCQA/bandit#767 (comment)).
Recently defusedxml got an update on safety information for lxml:
see tiran/defusedxml#38 and tiran/defusedxml#98 |
Hello @djbrown, Indeed, lxml has been deprecated within the package defusedxml. It would be useful to remove references to defusedxml.xml and give some guidance. There is still extra care to make when using lxml, isn't it? Both lxml and defusedxml do a good job at describing precautionary steps to put in place, e.g.
So, Bandit could simply reference these documentations. Your thoughts? BR |
I was about to start working on a pull request for this, when I saw the cross posted astral-sh/ruff#13707 (removal of suspicious-xmle-tree-usage (S320)), so I dug a bit deeper on this topic 🕵🏾♀️ ruff already removed their bandit-inherited rule suspicious-lxml-import (S410) (see issue and pull request) from that issue I found out about a controversial PSF discussion about wether to keep, replace or drop the defusedxml reference on the official python 1.12 xml docs. there were many further links and arguments, even to bandit itself, and others going in circles (defusedxml refers to lxml, lxml refers to defusedxml), and even ideas of extending the stlib. in the end they decided to keep it as it is, but there were strong arguments to replace the reference with lxml or at least remove it. nonetheless, defusedxml.lxml is deprecated and people should switch to lxml directly as already statet in the defusedxml readme and in threads dating back to 2019 tiran/defusedxml#38 (comment) and 2018 tiran/defusedxml#25 (comment) and probably further. I think the PSF should definitely update the docs to primarily refer to lxml and secondarily to defusedxml for different libs. |
I have created #1212 as the most straight forward way to resolve this issue |
@nicostubi you suggested simply changing the message to refer to the safe docs instead of just using defusedxml.lxml. |
Describe the bug
Just so this is recorded somewhere, it's certainly not a show-stopper bug:
If your program uses lxml, it's going to get warnings like this:
>> Issue: [B410:blacklist] Using lxml to parse untrusted XML data is known to be vulnerable to XML attacks. Replace lxml with the equivalent defusedxml package.
Except that the defusedxml.lxml package was never really real, it was intended as an example, and to stop people from using it as-is it's now deprecated and planned for removal. Probably bandit should not be suggesting that? The problem is - what else would one suggest?
See: https://pypi.org/project/defusedxml/#defusedxml-lxml
Reproduction steps
Expected behavior
Expect: "a useful suggestion". Possibly there's no good suggestion to make here?
Bandit version
1.7.0 (Default)
Python version
3.9 (Default)
Additional context
No response
The text was updated successfully, but these errors were encountered: