Files
Evection/apps/feeds/forms.py
T
ksmithandClaude Sonnet 5.5 41f99e9405 Allow only http(s) URLs from feeds and OPML, at storage and render (R2-S1, #33)
A feed's channel link, an entry's link and an OPML htmlUrl were stored
as given and rendered in href attributes (bulk writes skip model
validation), so a malicious feed could supply a javascript: or data:
link. CSP is a second layer, not the control.

apps.core.urlutils accepts only absolute http(s) URLs. Fetching stores
channel/entry links through it — relative links now resolve against the
feed's own URL instead of being stored as dead relative paths — OPML
import skips non-http(s) feed URLs and blanks unsafe htmlUrl, and the
add-feed form rejects non-http(s) (URLField also allows ftp). A
safe_http_url template filter guards the two places a feed-supplied URL
becomes a link (the article's "Original" link and the dashboard), so
values already in the database from before this fix are neutralized too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 11:57:23 -07:00

40 lines
1.1 KiB
Python

from django import forms
from apps.core.urlutils import http_url_or_empty
from .models import Subscription
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")