DeepSeek V4.1 Flash · 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
4 of 12
Comments published
12
Comments matching a bug
4
Comments not matching
8
Cost of this PR
$1.307

Published comments (12)

criticalbugapp/models/topic_embed.rb:13

Unescaped feed URL interpolated into imported-from HTML footer — The feed-supplied `url` is interpolated into the href with no escaping, and the `^https?:\/\/` gate lets a quote and markup through. Since these posts render raw, build the anchor with an escaped href.

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

Unescaped referer injected into embed layout script — `request.referer` is only host-checked, so a crafted path breaks out of the script block and runs attacker script on the forum origin with access to its cookies. Emit only the parsed origin, JSON-escaped.

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

Embed view renders unsanitized raw_html cooked content (XSS) — Feeds can carry markup that bypasses the cooking pipeline via the `cook_method` shortcut, and `TopicEmbed.absolutize_urls` only rewrites links, so scripts execute on the forum origin. Sanitize `post.cooked` before rendering it raw. **Also found in:** - `app/models/post.rb:130-137`

highsecurityapp/controllers/embed_controller.rb:24-31

Referer check allows unauthenticated clients to create unlimited topics — The `Referer` header is client-supplied, so any non-browser client can pass the `ensure_embeddable` check and create unbounded topics by randomizing `embed_url` paths. Gate creation on a non-forgeable token or a per-IP rate limit.

highbugapp/jobs/scheduled/poll_feed.rb:31-36

nil feed item content raises NoMethodError and aborts polling — Items that only carry `<description>` leave `i.content` nil, so `nil.scrub` raises and aborts the whole poll; with no retries the run is lost. Fall back to `i.description` and skip blank content.

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

`end if` without a condition causes a SyntaxError in the embed/best template — `end if` with no condition is a SyntaxError, so the template fails to compile on the branch where a topic was found and `/embed/best` raises instead of rendering. Use a plain `end`.

mediumbuglib/topic_retriever.rb:26-32

Throttle key can persist without TTL due to non-atomic setnx and expire — A failure between the two calls leaves `retrieved:<url>` without a TTL, so `setnx` never succeeds again and `perform_retrieve` skips that URL forever. Make the set and TTL a single atomic operation.

mediumperformanceapp/models/topic_embed.rb:44-52

Remote embed fetch has no timeout and reads unbounded body — A slow or oversized page pins the `retrieve_topic` worker indefinitely or exhausts memory, since `open(url).read` has no timeout and no size cap. Pass explicit timeout options and limit the bytes read.

mediumbugapp/views/layouts/embed.html.erb:9-12

postMessage target origin is full referer URL, not an origin — Send the parsed origin instead.

mediumsecurityapp/assets/javascripts/embed.js:17

Message origin check uses substring match instead of exact origin — A substring match accepts messages from lookalike origins like `https://discourse.example.co`, letting an attacker drive `iframe.height`. Compare `e.origin` exactly against the forum origin and also check `e.source` is the embed iframe.

mediumbugapp/models/topic_embed.rb:15-30

TopicEmbed.import races on embed_url and raises RecordNotUnique — Two workers can both see `embed.blank?`, and the unique index on `embed_url` makes the loser's `TopicEmbed.create!` raise `RecordNotUnique`, rolling back its just-created topic and post. Rescue the conflict and reuse the existing embed.

mediumbugspec/jobs/poll_feed_spec.rb:12-16

Test for feed_polling_enabled? doesn't isolate the enabled flag — `feed_polling_url` and `embed_by_username` stay at their blank defaults, so `poll_feed` is skipped regardless of the enabled flag and the test would pass even without that guard. Make the other two conditions truthy so only the flag prevents the call. **Also found in:** - `spec/jobs/poll_feed_spec.rb:18-22` - `spec/jobs/poll_feed_spec.rb:24-28`

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

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