-
Notifications
You must be signed in to change notification settings - Fork 230
Use Safe Parsers in lxml Parsing Functions
#69
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import sqlite3 | ||
| import requests | ||
| from lxml import etree | ||
| import lxml.etree | ||
|
|
||
| # Example hardcoded AWS credentials (sensitive data leakage) | ||
| aws_access_key_id = 'AKIA2JAPX77RGLB664VE' | ||
|
|
@@ -68,7 +69,7 @@ | |
| try: | ||
| # Use lxml to parse the XML data | ||
| parser = etree.XMLParser(load_dtd=True, resolve_entities=True) | ||
| tree = etree.fromstring(xml_data.encode(), parser) | ||
| tree = etree.fromstring(xml_data.encode(), parser, parser=lxml.etree.XMLParser(resolve_entities=False)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security control: Static Code Analysis Python Semgrep Potential Xxe Vulnerability With Native Python Xml Libraries Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE) Severity: HIGH Jit Bot commands and options (e.g., ignore issue)You can trigger Jit actions by commenting on this PR review:
|
||
| output = f"Parsed XML: {etree.tostring(tree, encoding='unicode')}" | ||
| except Exception as e: | ||
| output = f"XML Parsing Error: {e}" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security control: Static Code Analysis Python Semgrep
Potential Xxe Vulnerability With Native Python Xml Libraries
Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE)
attacks. The Python documentation recommends the 'defusedxml' library instead. Use 'defusedxml'.
See https://github.com/tiran/defusedxml for more information.
Severity: HIGH
Learn more about this issue
Jit Bot commands and options (e.g., ignore issue)
You can trigger Jit actions by commenting on this PR review:
#jit_ignore_fpIgnore and mark this specific single instance of finding as “False Positive”#jit_ignore_acceptIgnore and mark this specific single instance of finding as “Accept Risk”#jit_ignore_type_in_fileIgnore any finding of type "Potential XXE vulnerability with native Python XML libraries" in insecure-app/app.py; future occurrences will also be ignored.#jit_undo_ignoreUndo ignore command