GPT-6.1 Sol · 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
5 of 12
Comments published
10
Comments matching a bug
5
Comments not matching
5
Cost of this PR
$2.473

Published comments (10)

criticalbugapp/models/topic_embed.rb:13

Unescaped imported URLs allow HTML injection into posts — Quotes or markup in `url` can inject attributes or elements into imported posts because the prefix check allows them and `raw_html` preserves them. HTML-escape `url` in both the link attribute and text before interpolating it into `I18n.t`.

criticalbugapp/jobs/scheduled/poll_feed.rb:35-36

Unsanitized feed HTML becomes executable content in imported posts — Malicious feed HTML can execute on the forum's origin because `TopicEmbed.import` selects `raw_html` and `Post.cook` bypasses sanitization; `CGI.unescapeHTML` does not remove scripts or event handlers. Sanitize feed content before passing it to `TopicEmbed.import`, including on updates. **Also found in:** - `app/models/post.rb:131-133`

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

Invalid Ruby in embed template prevents comments from rendering — Rails cannot compile `<%- end if %>`, so the existing-topic branch of `EmbedController.best` fails instead of displaying comments. Replace it with `<%- end %>`.

highbugapp/models/topic_embed.rb:20-28

Concurrent imports can fail on duplicate embed URLs — Concurrent imports can both pass `embed.blank?`, then collide on `embed_url`, raising `ActiveRecord::RecordNotUnique` and aborting a feed run. Rescue the conflict outside the rolled-back transaction and retrieve the winning `TopicEmbed` and post, or serialize imports per URL.

highbugapp/jobs/scheduled/poll_feed.rb:35

RSS items without content abort the polling run — Description-only RSS items make `i.content.scrub` raise `NoMethodError`, aborting the entire polling run with retries disabled. Fall back to `i.description` and explicitly handle items with neither field before calling `scrub`.

mediumperformancelib/topic_retriever.rb:39-42

Per-article throttling causes repeated full-feed imports — Each distinct missing `@embed_url` triggers a synchronous full-feed import through `Jobs::PollFeed`, multiplying network requests and database work across article visits. Throttle polling with a shared feed-level key and let individual retrievals reuse the result.

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

Embedded post dates ignore the active locale — Readers on non-English forums still see English-style dates because `post.created_at.strftime` fixes the ordering and month abbreviation. Use `l` with a locale-defined date format.

mediumbugspec/controllers/embed_controller_spec.rb:8-10

Missing embed_url example fails at host validation instead — This test still passes if `params.require(:embed_url)` is removed because `ensure_embeddable` rejects the default blank `embeddable_host` first. Configure an allowed host and matching referer, then assert the intended missing-parameter status rather than any unsuccessful response.

mediumbugspec/jobs/poll_feed_spec.rb:18-27

Negative prerequisite tests short-circuit because polling is disabled — These tests can miss regressions because `execute` exits on the default false `feed_polling_enabled?` before checking `feed_polling_url` or `embed_by_username`. Enable polling and make every other prerequisite valid so each example isolates its named requirement.

mediumbugapp/models/topic_embed.rb:64-65

Protocol-relative links and images are rewritten to the article host — Resolve both link and image URLs against the source URI with `URI.join`, or handle double-slash prefixes separately.

Gold bugs found (5)

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

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