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
@@ -23,6 +23,7 @@ from django.utils import timezone
|
||||
|
||||
from apps.articles.models import Article, PurgedArticle
|
||||
from apps.core.models import SiteSettings
|
||||
from apps.core.urlutils import resolve_http_url
|
||||
from apps.feeds.models import Feed
|
||||
|
||||
from .ssrf_guard import SSRFBlocked, safe_get
|
||||
@@ -222,7 +223,7 @@ def fetch_and_ingest(feed: Feed) -> FetchResult:
|
||||
channel_title = parsed.feed.get("title")
|
||||
if channel_title and not feed.title:
|
||||
feed.title = channel_title[:500]
|
||||
channel_link = parsed.feed.get("link")
|
||||
channel_link = resolve_http_url(feed.feed_url, parsed.feed.get("link"))
|
||||
if channel_link and not feed.site_url:
|
||||
feed.site_url = channel_link[:1000]
|
||||
|
||||
@@ -249,7 +250,7 @@ def fetch_and_ingest(feed: Feed) -> FetchResult:
|
||||
if guid in parsed_entries:
|
||||
continue
|
||||
title = (getattr(entry, "title", "") or "")[:1000]
|
||||
link = (getattr(entry, "link", "") or "")[:2000]
|
||||
link = resolve_http_url(feed.feed_url, getattr(entry, "link", ""))[:2000]
|
||||
author = (getattr(entry, "author", "") or "")[:500]
|
||||
summary = (getattr(entry, "summary", "") or "")[:5000]
|
||||
content_html = sanitize_html(_entry_content_html(entry))
|
||||
|
||||
Reference in new issue
Block a user