MiniMax M3 · 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
2 of 12
Comments published
8
Comments matching a bug
2
Comments not matching
6
Cost of this PR
$0.529

Published comments (8)

criticalbugapp/views/layouts/embed.html.erb:6-15

Raw request.referer interpolated into JS string breaks out of context — Raw `<%= request.referer %>` interpolation into a JS string lets an attacker with a single quote or `</script>` segment in the URL execute script in the parent page. Wrap with `j`/`json_escape` so the referer cannot break out of the JS context.

criticalsecurityapp/models/topic_embed.rb:13

URL interpolated raw into href attribute and link text enables XSS — Wrap both occurrences in `CGI.escapeHTML(url)` and prefer double-quoted attributes.

mediumperformancelib/topic_retriever.rb:40-43

PollFeed runs synchronously on every embed cache miss — Running `Jobs::PollFeed.new.execute({})` inline makes each cached-miss embed view pay the cost of a full RSS import. Enqueue `Jobs.enqueue(:poll_feed)` instead and only return early on the existence check.

mediumsecurityapp/assets/javascripts/embed.js:15-17

postMessage origin check uses substring match instead of origin comparison — `discourseUrl.indexOf(e.origin) === -1` accepts any origin whose string appears inside `discourseUrl`, allowing attacker-controlled origins to resize the iframe. Compare `new URL(discourseUrl).origin === e.origin` to match only the parsed origin.

mediumperformancelib/topic_retriever.rb:41-43

Synchronous PollFeed in embed render path — Invoking `Jobs::PollFeed.new.execute({})` inline in `perform_retrieve` blocks the embed render on a full RSS fetch and import per cache miss. Drop the synchronous call and let the scheduled `PollFeed` job reconcile topics, relying only on the embed_url existence check.

mediumsecurityapp/assets/javascripts/embed.js:17

postMessage origin check uses unsafe substring match — `discourseUrl.indexOf(e.origin) === -1` matches any origin substring contained in `discourseUrl`, so attackers on a shorter matching origin can resize the iframe. Replace with `e.origin === new URL(discourseUrl).origin` for an exact parsed comparison.

mediumbugspec/controllers/embed_controller_spec.rb:8-11

"is 404 without an embed_url" test sits outside "with a host" context — Move it inside the context and stub referer so only the embed_url path is exercised.

mediumsecurityapp/views/layouts/embed.html.erb:6-15

Layout echoes full request.referer (incl. query string) into JS context — Echo only the scheme and host from `URI(request.referer)` through the `j` helper so embedding-site query secrets never reach the response.

Gold bugs found (2)

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