Claude Sonnet 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
4 of 12
Comments published
8
Comments matching a bug
4
Comments not matching
4
Cost of this PR
$2.306

Published comments (8)

criticalsecurityapp/models/post.rb:131-133

Raw HTML posts skip sanitization in Post#cook, enabling stored XSS — `Post#cook` returns `raw` unsanitized, so HTML from an external feed or fetched page is stored in `cooked` and rendered on the forum's origin, enabling stored XSS against users and staff. Sanitize the HTML with a whitelist-based tool in the raw_html branch of `cook` or in `TopicEmbed.import`.

highperformancedb/migrate/20131219203905_add_cook_method_to_posts.rb:3

Adding NOT NULL column with default rewrites large posts table under exclusive lock — On the Postgres versions this app targets, this rewrites the whole `posts` table under an ACCESS EXCLUSIVE lock, blocking all reads and writes during the deploy. Add `cook_method` as nullable, set the default, backfill in batches, then add the `NOT NULL` constraint.

highsecurityapp/models/topic_embed.rb:13

Unescaped URL interpolated into anchor HTML allows HTML injection — A feed-supplied `url` containing `'` or `<` can break out of the `href` attribute and inject HTML or script into the post. Escape `url` with `ERB::Util.html_escape`, or build the anchor with `link_to`, before interpolating it.

mediumbugapp/models/topic_embed.rb:15-30

Concurrent imports of same URL race and raise RecordNotUnique — The check-then-create on `embed_url` is not atomic, so concurrent imports from `PollFeed` and `RetrieveTopic` both create a topic and the loser hits the unique index with an unhandled `ActiveRecord::RecordNotUnique`. Rescue `ActiveRecord::RecordNotUnique` and return the existing embed's post, or lock on the URL.

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

NoMethodError on feed items without content aborts the polling loop — `i.content.scrub` raises `NoMethodError` for items lacking `content`, which aborts the `rss.items.each` loop and skips every later item. Fall back with `(i.content || i.description || '')` and skip items with a blank body or `url`.

mediumbugapp/models/topic_embed.rb:62-73

absolutize_urls corrupts protocol-relative URLs like //cdn.example.com/x.png — Skip values starting with `//` so only genuinely site-relative paths get the prefix.

mediumsecurityapp/assets/javascripts/embed.js:17

Origin check uses substring match, allowing spoofed postMessage origins — The `discourseUrl.indexOf(e.origin) === -1` check is a substring match, so any origin that is a prefix of `discourseUrl` passes and can spoof messages. Parse `discourseUrl` into its origin and require `e.origin` to equal it exactly.

mediumbugspec/jobs/poll_feed_spec.rb:18-22

feed_polling_url test doesn't enable polling so it can't fail on the URL check — This test never enables `feed_polling_enabled?`, which defaults to false, so `execute` skips `poll_feed` regardless of the URL and the test passes even without the `feed_polling_url.present?` check. Stub `feed_polling_enabled?` to true and set `embed_by_username` so only the missing URL blocks the call. **Also found in:** - `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.
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.

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