Files
ksmithandClaude Sonnet 5.5 698940763f 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>
2026-11-01 11:58:49 -07:00

52 lines
1.6 KiB
Python

from django import forms
from apps.core.urlutils import http_url_or_empty
from .models import Subscription
from .opml import MAX_UPLOAD_BYTES
class AddFeedForm(forms.Form):
feed_url = forms.URLField(label="Feed URL", max_length=1000, assume_scheme="https")
def clean_feed_url(self):
# URLField also accepts ftp:// and ftps://; feeds are only ever
# fetched over http(s).
url = http_url_or_empty(self.cleaned_data["feed_url"])
if not url:
raise forms.ValidationError("Enter a feed URL starting with http:// or https://.")
return url
tag_names = forms.CharField(
label="Tags",
max_length=500,
required=False,
help_text="Comma-separated. Leave blank to tag it later.",
)
class EditSubscriptionForm(forms.ModelForm):
class Meta:
model = Subscription
fields = ["custom_title"]
labels = {"custom_title": "Title (leave blank to use the feed's own title)"}
def __init__(self, *args, user=None, **kwargs):
super().__init__(*args, **kwargs)
self._user = user
class OPMLImportForm(forms.Form):
opml_file = forms.FileField(label="OPML file")
def clean_opml_file(self):
uploaded = self.cleaned_data["opml_file"]
# Checked on the upload's reported size before anything reads it
# into memory (R2-S5); the reverse proxy's client_max_body_size is
# a second, coarser limit.
if uploaded.size > MAX_UPLOAD_BYTES:
raise forms.ValidationError(
f"That file is too large (limit {MAX_UPLOAD_BYTES // (1024 * 1024)} MB)."
)
return uploaded