DeepSeek V4.1 Flash · Balanced

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

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

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 12
Comments published
7
Comments matching a bug
3
Comments not matching
4
Cost of this PR
$0.206

Published comments (7)

criticalsecurityapp/models/post.rb:130-136

Raw HTML cook method bypasses sanitization for imported feed content — Because `cook_methods[:raw_html]` returns `raw` untouched, third-party HTML from `TopicEmbed.import` reaches the page unsanitized, letting `<script>` or `onerror` run in the Discourse origin. Sanitize the imported HTML with a tag, attribute, and scheme allowlist before storing it, rather than relying on the cook bypass.

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

Invalid `end if` in embed/best template causes SyntaxError — ERB compiles the whole view into one method, so `<%- end if %>` leaves it unbalanced and every render of `embed/best` raises a SyntaxError, including the empty-topic branch. Change it to `<%- end %>`.

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

nil feed content raises NoMethodError and aborts the poll — `i.content` is nil for items that only carry `<description>`, so `nil.scrub` raises NoMethodError, aborts the `each` loop, and skips all remaining items with no retry. Read the body defensively from `i.content` or `i.description` and skip blank items.

highperformancedb/migrate/20131219203905_add_cook_method_to_posts.rb:3

add_column with default rewrites posts and blocks access on PostgreSQL — On PostgreSQL before 11 the default and NOT NULL force a full table rewrite under an ACCESS EXCLUSIVE lock, blocking all reads and writes to posts for the whole migration. Add `cook_method` nullable without a default, backfill in batches, then set the default and NOT NULL afterward.

highbugapp/models/topic_embed.rb:32-37

Unguarded embed.post causes NoMethodError for orphaned topic embeds — A `topic_embeds` row outlives hard-deleted posts, so `PostRevisor.new(nil)` raises NoMethodError, aborting the `rss.items` loop in `Jobs::PollFeed` and leaving all later items unimported. Return early when `post.blank?` or delete the stale embed.

mediumperformancelib/topic_retriever.rb:39-43

Feed poll runs inline for every distinct embed URL retrieval — `perform_retrieve` pays the full O(feed items) poll inline for every distinct `embed_url`, since the `retrieved:` throttle is per URL and `feed_key` is unused. Enqueue the poll as its own throttled job instead of running it inline per request.

mediumperformanceapp/models/topic_embed.rb:44-48

Remote embed fetch lacks timeouts and size cap — A slow remote response blocks the worker indefinitely and an oversized body is loaded entirely into memory by `open(url).read`, reachable from the embed endpoint. Pass explicit `open_timeout` and `read_timeout` and cap the bytes read.

Gold bugs found (3)

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

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