Bound OPML uploads in size, depth, count and broker payload (R2-S5, #37)

An OPML upload was read fully into memory, parsed into a whole tree,
walked recursively, and (for large imports) embedded in a Celery
message. Nothing bounded raw size, ZIP entries, nesting depth, outline
count or feed count.

Uploads are capped at 5 MB (checked on the reported size before reading)
and ZIPs at 50 entries, with the decompressed member bounded by what it
actually yields rather than only its header. Parsing now streams with
iterparse and aborts the moment a limit is crossed — 24 levels deep,
20,000 outlines, 5,000 feeds — so a hostile file never builds a huge or
deep tree; a 50,000-level nesting bomb is rejected cleanly. Limit errors
are shown to the user. Large imports go to the worker by cache reference
(deleted once read, expires after an hour) instead of as the whole
document inside the broker message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5.5 committed 2026-11-01 11:58:49 -07:00
1 parent 41f99e9405
commit 698940763f
6 files changed
+240 -40

No files matched your search

+11 -4
View File
@@ -192,12 +192,19 @@ def reset_feed_backoff(feed_id: int):
@shared_task
def import_opml_task(user_id: int, opml_content: str):
def import_opml_task(user_id: int, upload_key: str):
"""Background path for large OPML imports — see OPML_ASYNC_THRESHOLD
in apps.feeds.views. opml_content is passed as text rather than a
file handle since Celery tasks must be JSON-serializable."""
in apps.feeds.views. The document itself waits in the cache under
upload_key (set by the view) rather than travelling in the broker
message; it's removed once read, and expires on its own if this task
never runs."""
content = cache.get(upload_key)
if content is None:
logger.warning("OPML import %s expired or missing; nothing imported", upload_key)
return None
cache.delete(upload_key)
try:
user = get_user_model().objects.get(pk=user_id)
except get_user_model().DoesNotExist:
return None
return import_opml(user, BytesIO(opml_content.encode("utf-8")))
return import_opml(user, BytesIO(content))