MiniMax M3 · Balanced

enhance-embed-url-handling-and-validation-system-discourse-cursor

Discourse · Ruby · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
2 of 12
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$0.127

Published comments (4)

criticalsecurityapp/views/embed/best.html.erb:19

raw post.cooked renders unsanitized HTML in embed iframe — Embedding unsanitized `post.cooked` from `Post#cook` allows `<script>` injection (ruby-readability preserves event handlers), so a malicious embeddable_host can run JS in Discourse's origin and steal session cookies. Sanitize raw_html posts through PrettyText or escape here and only unescape known-safe subtrees, using `post.cookedHtml`.

mediumbugapp/jobs/scheduled/poll_feed.rb:24-37

poll_feed loop aborts batch on any per-item error — Any per-item failure in `poll_feed`'s `rss.items.each` loop (e.g. `i.content.scrub` raising `NoMethodError`) drops every remaining item for that hour because `retry: false` swallows the abort. Wrap each iteration in `begin/rescue`, log the exception, and also rescue `Errno::ECONNREFUSED`/`SocketError` around `open()`.

mediumperformancelib/topic_retriever.rb:35-46

PollFeed runs synchronously inside RetrieveTopic worker — Enqueue it instead via `Jobs.enqueue(:poll_feed)` so the retriever only schedules the work and returns.

mediumbugapp/jobs/scheduled/poll_feed.rb:28-29

Use URI.open instead of Kernel#open to avoid shell evaluation — Using `Kernel#open` to fetch the feed URL retains shell semantics and executes strings starting with `|`, including any value later typed into `feed_polling_url` in the admin UI. Switch to `URI.open(SiteSetting.feed_polling_url)` so the input is unambiguously treated as a URI.

Gold bugs found (2)

highPollFeed reads i.content.scrub for every feed item, so items without a content element (common in RSS feeds that only have description) raise NoMethodError and abort the import of the remaining items.
mediumEvery retrieval of an article not yet embedded synchronously polls and imports the entire RSS feed, and since throttling is per URL, many different article requests repeat the full feed download and processing.

Gold bugs missed (10)

highThe referer and embed_url host checks compare against SiteSetting.embeddable_host case-sensitively, so a host differing only in case is rejected even though hostnames are case-insensitive.
criticalTopicEmbed.import appends a footer that interpolates the URL unescaped into an <a href='...'> tag in raw HTML that is later rendered unsanitized, so a crafted URL can inject markup; it also appends to contents with << without handling nil.
highWhen the embedded post has been deleted, TopicEmbed.import's update path passes a nil embed.post to PostRevisor and crashes on every later import of that URL.
mediumClaims import_remote crashes on unparseable pages (nil content) and dead URLs because it does no nil check or network error handling around open(url).read.
mediumabsolutize_urls only handles root-relative paths: protocol-relative URLs like //cdn.example.com/x.png are rewritten to http://host/cdn.example.com/x.png and path-relative links are left unresolved, breaking links and images in imported posts.
mediumThe 'requires feed_polling_url' and 'requires embed_by_username' specs leave feed_polling_enabled at its false default, so they never reach the condition they name and would pass with those checks deleted.
high`import_remote` fetches the embed URL with open-uri, which follows redirects, so the embeddable-host check on the initial URL can be bypassed to reach internal services (SSRF).
mediumThe retrieve throttle is keyed by the full embed URL, so an anonymous client can vary the query string on the embeddable host to bypass it and make the server create an unbounded number of topics.
mediumThe "requires feed_polling_enabled?" spec leaves feed_polling_url and embed_by_username at their blank defaults, so poll_feed is skipped regardless and the test would pass even without the enabled check.
highThe embed layout references the 'embed' stylesheet and embed.js, but neither is in config.assets.precompile, so with precompiled assets in production the embed page fails to load them.