Private
Public Access
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:
1 parent
85914f9107
commit
41f99e9405
13 files changed
+192
-7
No files matched your search
@@ -554,3 +554,33 @@ def test_authenticated_pages_load_the_tab_badge_script_with_its_endpoint(client,
|
||||
assert f'data-url="{reverse("reader:new_since")}"' in content
|
||||
client.logout()
|
||||
assert "tab-badge" not in client.get(reverse("accounts:login")).content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unsafe_stored_links_are_not_rendered_as_hrefs(client, alice, django_user_model):
|
||||
"""R2-S1 render boundary: even if a bad URL is already in the database
|
||||
(stored before validation existed), it must not become a clickable
|
||||
javascript: link."""
|
||||
feed = Feed.objects.create(
|
||||
feed_url="https://example.com/feed.xml", site_url="javascript:alert(1)"
|
||||
)
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
article = Article.objects.create(
|
||||
feed=feed, guid="g1", title="Hello", link="javascript:alert(2)"
|
||||
)
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
detail = client.get(reverse("reader:article_detail", args=[article.pk])).content.decode()
|
||||
assert "javascript:" not in detail
|
||||
assert "Original" not in detail
|
||||
|
||||
article.link = "https://example.com/real"
|
||||
article.save()
|
||||
detail = client.get(reverse("reader:article_detail", args=[article.pk])).content.decode()
|
||||
assert 'href="https://example.com/real"' in detail
|
||||
|
||||
django_user_model.objects.create_user("admin", password="pw-admin-123", is_staff=True)
|
||||
client.login(username="admin", password="pw-admin-123")
|
||||
Feed.objects.filter(pk=feed.pk).update(fetch_error_count=2, last_fetch_status="error")
|
||||
dashboard = client.get(reverse("core:dashboard")).content.decode()
|
||||
assert "javascript:" not in dashboard
|
||||
Reference in new issue
Block a user