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
@@ -399,3 +399,27 @@ def test_old_entries_are_ingested_normally_when_retention_is_off(feed):
|
||||
responses.add(responses.GET, FEED_URL, body=xml, status=200)
|
||||
|
||||
assert len(fetch_and_ingest(feed).new_article_ids) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@responses.activate
|
||||
def test_unsafe_urls_in_a_feed_are_not_stored(feed):
|
||||
"""R2-S1: a feed's channel link and entry links are untrusted — only
|
||||
absolute http(s) URLs may be persisted (they end up in href attributes)."""
|
||||
xml = (
|
||||
'<?xml version="1.0"?><rss version="2.0"><channel><title>T</title>'
|
||||
"<link>javascript:alert(1)</link>"
|
||||
"<item><title>Bad</title><guid>bad</guid><link>javascript:alert(2)</link></item>"
|
||||
"<item><title>Relative</title><guid>rel</guid><link>/posts/1</link></item>"
|
||||
"<item><title>Good</title><guid>good</guid><link>https://example.com/good</link></item>"
|
||||
"</channel></rss>"
|
||||
)
|
||||
responses.add(responses.GET, FEED_URL, body=xml, status=200)
|
||||
|
||||
fetch_and_ingest(feed)
|
||||
|
||||
assert feed.site_url == ""
|
||||
links = dict(Article.objects.filter(feed=feed).values_list("guid", "link"))
|
||||
assert links["bad"] == ""
|
||||
assert links["rel"] == "https://example.com/posts/1"
|
||||
assert links["good"] == "https://example.com/good"
|
||||
Reference in new issue
Block a user