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>
This commit is contained in:
ksmithandClaude Sonnet 5.5 committed 2026-11-01 11:57:23 -07:00
1 parent 85914f9107
commit 41f99e9405
13 files changed
+192 -7

No files matched your search

+11
View File
@@ -117,3 +117,14 @@ def test_add_feed_view_rejects_duplicate_subscription(client, two_users):
assert response.status_code == 302
assert Subscription.objects.filter(user=alice, feed=feed).count() == 1
@pytest.mark.django_db
@pytest.mark.parametrize("url", ["ftp://example.com/feed.xml", "javascript:alert(1)"])
def test_add_feed_rejects_non_http_urls(client, two_users, url):
client.login(username="alice", password="pw-alice-123")
response = client.post(reverse("feeds:add_feed"), {"feed_url": url})
assert response.status_code == 200
assert not Feed.objects.filter(feed_url=url).exists()