-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [HIGH] Fix XXE Vulnerability in XML Parsing #4
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## 2025-02-27 - [Fix XXE Vulnerability in Scrapers] | ||
| **Vulnerability:** Found `xml.etree.ElementTree.fromstring` parsing untrusted XML data (RSS feeds) in `functions/scrapers/theverge.py` and `functions/scrapers/producthunt.py`. This is vulnerable to XML Entity Expansion (Billion Laughs) and XXE attacks. | ||
| **Learning:** Standard library XML parsers in Python are not secure by default. Untrusted input must not be passed to them. | ||
| **Prevention:** Always use `defusedxml.ElementTree.fromstring` as a drop-in replacement when parsing XML from external or untrusted sources. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ beautifulsoup4==4.* | |
| feedparser==6.* | ||
| openai==1.* | ||
| tzdata | ||
| defusedxml | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||||
| import httpx | ||||||||
| from typing import List, Dict, Any | ||||||||
| from datetime import datetime | ||||||||
| from defusedxml.ElementTree import fromstring | ||||||||
| import xml.etree.ElementTree as ET | ||||||||
|
Comment on lines
+9
to
10
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. To make the code cleaner and use Then, on line 85, you should change
Suggested change
|
||||||||
| from bs4 import BeautifulSoup | ||||||||
|
|
||||||||
|
|
@@ -80,8 +81,8 @@ def fetch_producthunt(limit: int = 10) -> List[Dict[str, Any]]: | |||||||
| print(f"Product Hunt RSS returned {response.status_code}") | ||||||||
| return [] | ||||||||
|
|
||||||||
| # Parse RSS feed | ||||||||
| root = ET.fromstring(response.content) | ||||||||
| # Parse RSS feed securely | ||||||||
| root = fromstring(response.content) | ||||||||
|
|
||||||||
| products = [] | ||||||||
| items = root.findall('.//item') | ||||||||
|
|
||||||||
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.
It's a good practice to pin dependency versions to ensure reproducible builds. Consider specifying a version for
defusedxmlto align with the versioning style of other packages in this file.