Claude Opus 5.5 · 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
4 of 12
Comments published
7
Comments matching a bug
4
Comments not matching
3
Cost of this PR
$1.099

Published comments (7)

criticalsecurityapp/models/post.rb:133

Raw HTML posts skip sanitization, allowing stored XSS — Feed content (unescaped in `poll_feed`) and remote pages reach `cooked` unsanitized, and `best.html.erb` renders it via `raw post.cooked`, so a compromised source can inject scripts. Sanitize `raw` with a whitelist before storing or while cooking.

criticalsecurityapp/models/topic_embed.rb:13

Unescaped embed URL interpolated into raw HTML link allows markup injection — `url` comes from the `embed_url` param or the feed, and the post renders raw, so a `'` or `<` can break out of the attribute and inject markup. Escape `url` with `ERB::Util.html_escape` before interpolating.

highbugapp/jobs/scheduled/poll_feed.rb:35

Feed import crashes on items with no `content` field — SimpleRSS returns nil `content` for description-only RSS 2.0 items, so `i.content.scrub` raises `NoMethodError` and aborts the import, including `TopicRetriever`'s synchronous call. Fall back to `i.description` and skip items where both are nil.

mediumbugapp/views/embed/best.html.erb:6

Stray `if` after `end` makes header buttons conditional on the next output — Ruby treats the next output expression as an `if` modifier on the whole block, so header buttons render only when the logo link's return value is truthy. Replace `<%- end if %>` with `<%- end %>`.

mediumperformancelib/topic_retriever.rb:40-45

Inline RSS feed poll on every unknown embed URL lacks a global throttle — The throttle is per-URL and the referer is spoofable, so distinct paths can trigger unbounded feed polls and outbound fetches. Drop the inline `Jobs::PollFeed` call in favor of the hourly poll, or add a global throttle.

mediumbugapp/models/topic_embed.rb:64-71

absolutize_urls mangles protocol-relative URLs starting with // — Values like `//cdn.example.com/img.png` get rewritten to `http://host/cdn.example.com/img.png`, breaking external links and images. In `absolutize_urls`, skip values starting with `//`.

mediumsecurityapp/assets/javascripts/embed.js:17

Substring origin check lets prefix-matching origins send resize messages — `indexOf` is a substring test, so any origin that prefixes `discourseUrl` (e.g. `https://forum.example.co`) can send resize messages. Compare `e.origin` exactly against the origin parsed from `discourseUrl`.

Gold bugs found (4)

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.
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.
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.
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 (8)

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.
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.
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.