Claude Opus 5.5 · Heavy

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

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

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
6 of 12
Comments published
12
Comments matching a bug
6
Comments not matching
6
Cost of this PR
$3.623

Published comments (12)

criticalsecurityapp/models/post.rb:133

Raw HTML posts are returned unsanitized, allowing stored XSS — `PollFeed` stores feed HTML after `CGI.unescapeHTML`, so `<script>`, `on*` handlers or `javascript:` links reach the forum and the embed view through `raw post.cooked`. Run `raw` through a sanitizer, such as the cooked-post whitelist, before returning it.

criticalsecurityapp/jobs/scheduled/poll_feed.rb:29

`Kernel#open` on `SiteSetting.feed_polling_url` allows shell commands — A value starting with `|` spawns a subprocess, so anyone who can change site settings can run commands on the job server. Parse it with `URI.parse`, require an http/https scheme, and fetch with `URI#open` or `Net::HTTP`.

criticalbugapp/models/topic_embed.rb:13

Unescaped URL in 'Imported from' footer allows HTML injection — These raw_html posts render via `raw post.cooked`, so a `url` containing a quote or angle bracket breaks out of the `href` attribute. Escape `url` with `ERB::Util.html_escape` in both the `href` and the link text.

highbugapp/jobs/scheduled/poll_feed.rb:35

NoMethodError on RSS items without `content:encoded` aborts feed import — Items with only `description` make `i.content` nil, so `.scrub` raises and the rest of the feed isn't imported. Fall back to `i.description` and skip items without content.

highbugapp/models/topic_embed.rb:15-30

Concurrent imports of the same URL raise RecordNotUnique and abort the feed — When hourly `PollFeed` and a `RetrieveTopic` job import the same URL, both see `embed.blank?` and the loser's `TopicEmbed.create!` raises uncaught, stopping the `rss.items.each` loop. Rescue `ActiveRecord::RecordNotUnique` and fall back to the existing embed, or lock on the URL.

mediumbugapp/models/topic_embed.rb:32-37

Deleted embedded post makes `embed.post` nil and `revise!` raise — `PostRevisor.new(nil).revise!` raises, so every later feed poll for this URL fails. Return early or recreate the topic when `post` is nil.

mediumperformancelib/topic_retriever.rb:40-43

Each embed miss synchronously polls and re-parses the whole feed — Staff bypass the throttle and each distinct URL has its own throttle key, so every embed miss runs `Jobs::PollFeed` synchronously and refetches the full feed. Look up only the requested item, or rate-limit the full poll with a global key.

mediumbugapp/controllers/embed_controller.rb:15-19

Loading page is cached for 1 minute, so its reload can get stale content — The 'loading' page reloads itself after 30 seconds, but `discourse_expires_in 1.minute` caches it too, so the reload may return it instead of the new topic. Set the cache header only when `topic_id` is present.

mediumsecurityapp/assets/javascripts/embed.js:17

Origin check uses substring match, so prefix-matching origins pass — With `discourseUrl.indexOf(e.origin)`, an origin like `https://forum.example.co` passes for `https://forum.example.com/` and can send resize messages. Compare `e.origin` exactly against the origin parsed from `discourseUrl`.

mediumbugapp/models/post.rb:130-136

raw_html `cook` returns stored `raw` instead of the text passed in — Callers passing new text, such as `p.cook(new_raw, ...)` in lib/tasks/add_topic_to_quotes.rake, get the old `raw` back and store a cooked value that no longer matches. Return `args.first` for raw_html posts.

mediumbugapp/models/topic_embed.rb:64-71

Protocol-relative URLs are wrongly rewritten as host-relative paths — Values like `//cdn.example.com/a.png` pass the `start_with?('/')` check and become `http://host/cdn.example.com/a.png`, breaking external images and links. Skip values starting with `//` before prefixing.

mediumbugspec/jobs/poll_feed_spec.rb:24-28

embed_by_username test passes even without the guard it is meant to test — `feed_polling_enabled?` and `feed_polling_url` default to values that already block `poll_feed`, so deleting the `embed_by_username.present?` guard wouldn't fail this test. Stub both to valid values so only this guard is tested. **Also found in:** - `spec/jobs/poll_feed_spec.rb:18-22` - `spec/jobs/poll_feed_spec.rb:12-16`

Gold bugs found (6)

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

Gold bugs missed (6)

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