The normal review, with one generalist agent. Judge: Claude Opus 5.5.
Gold bugs found
4 of 30
Comments published
7
Comments matching a bug
4
Comments not matching
3
Cost of this PR
$0.230
Published comments (7)
criticalsecurityapp/models/post.rb:130-137
Raw HTML cook path serves unsanitized imported feed content — External RSS content reaches HTML sinks unfiltered, so script or onerror payloads from a feed execute on the forum's origin. Sanitize imported content against a tag/attribute allowlist (e.g. `PrettyText`) before storing or serving it, and stop `CGI.unescapeHTML`-ing feed bodies in `PollFeed`.
highbugapp/jobs/scheduled/poll_feed.rb:31-37
NoMethodError on items without content aborts entire feed poll — A single item lacking a content element yields nil from `i.content`, and the resulting `NoMethodError` aborts the whole poll — with `retry: false`, such feeds never import at all. Fall back to `i.content_encoded` or `i.description` and skip blank content, also guarding `i.title` before `TopicEmbed.import`.
highperformanceapp/models/topic_embed.rb:44-53
open(url).read has no open/read timeout, can hang Sidekiq workers — A slow or hung remote host wedges Sidekiq worker threads indefinitely since `open` uses open-uri's defaults with no timeout, stalling both embed retrieval and the scheduled `PollFeed` poller. Pass explicit `read_timeout` and `open_timeout` values to `open`.
highbugapp/controllers/embed_controller.rb:26
Referer host compared case-sensitively against embeddable_host — A mixed-case Referer like `https://EvilTrout.com/page` is rejected with `Discourse::InvalidAccess`, breaking legitimate embeds, because DNS hostnames are case-insensitive. Downcase both sides of the comparison, applying the same fix in `TopicRetriever#invalid_host?`.
add_column with default+NOT NULL rewrites posts under exclusive lock — On large forums this rewrites the entire `posts` table under an ACCESS EXCLUSIVE lock, blocking every read and write for the migration's duration. Add the column without constraints, backfill in batches, then set the default and `NOT NULL`.
mediumbugapp/models/topic_embed.rb:78-80
topic_id_for_embed returns stale topic_id for deleted topics — For a deleted topic, the stale id makes `/embed/best` fail with `Discourse::NotFound` forever, and `TopicRetriever` never re-creates the discussion because the `TopicEmbed` row still exists. Filter the lookup to existing, visible topics (or destroy the row on topic destroy) so retrieval falls back to re-import.
mediumbuglib/topic_retriever.rb:26-30
SETNX and EXPIRE are not atomic, risking a permanent throttle key — If the process dies or Redis errors between `$redis.setnx` and `$redis.expire`, the key persists without a TTL and retrieval is permanently disabled for that `embed_url`. Use a single atomic `$redis.set` with `ex: 60, nx: true` instead.
Gold bugs found (4)
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.
mediumTopicEmbed.import_remote fetches the embed URL with open(url).read and no timeout or size limit, so a slow or huge remote page can block the background job and exhaust memory.
mediumtopic_id_for_embed returns the stored topic_id even after the topic is deleted, and topic_embeds rows are never removed. /embed/best errors permanently for that URL, and TopicRetriever never re-creates the topic.
Gold bugs missed (26)
mediumThe postMessage handler in embed.js checks the sender with discourseUrl.indexOf(e.origin), a substring test instead of exact origin equality, so a page on an origin that is a substring of the Discourse URL can send forged discourse-resize messages to the embedding page.
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.
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.
lowThe embed view formats post dates with a hard-coded strftime pattern, so users in non-English locales see English month names and a fixed order while the rest of the view is translated.
highThe Disqus importer now creates topics through TopicEmbed.import_remote, dropping the thread's created_at and the category option and requiring a live HTTP fetch per thread, so imported topics get wrong dates/categories and a dead link aborts the import.
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 'is 404 without an embed_url' spec never sets an embeddable host, so the request is rejected by ensure_embeddable before the embed_url check runs, and the test would pass even without that check.
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.
mediumembed_url is a varchar(255) column, so importing/embedding a URL longer than 255 characters fails on insert and that page can never get its discussion topic.
mediumPostMover#copy recreates the first post via PostCreator without passing cook_method, so a moved raw_html (embedded/imported) first post is re-cooked through the markdown pipeline and its content changes.
mediumEmbedController#best renders the 'loading' placeholder and still calls discourse_expires_in 1.minute, so the anonymous cache stores the placeholder under the embed URL and visitors keep seeing 'Loading Discussion...' for up to a minute after the topic exists.
mediumTopicEmbed.import wraps PostCreator#create in Topic.transaction, so PostCreator's post-transaction job enqueueing (process_post, feature_topic_users, etc.) runs before the outer transaction commits, and a worker that picks up ProcessPost early finds no post and skips post-processing for the imported topic.
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.
highThe embed layout writes the full request.referer into the page, and the page is anon-cached for a minute under a key without the referer. One embedding page's full URL, including query secrets, can be served to other visitors.
mediumTopicEmbed.import checks post.present? after PostCreator#create, but PostCreator returns an unsaved post when it rolls back on host spam. TopicEmbed.create! then runs with nil ids and raises, which aborts the import.
mediumabsolutize_urls calls URI(url) without a rescue, so a malformed URL that passes the http regex raises URI::InvalidURIError and aborts the PollFeed import.
highPollFeed always HTML-unescapes item content, so feeds that already carry literal HTML (CDATA) get their escaped entities decoded a second time. Escaped code samples become live markup in the raw_html post.
mediumEmbedController#best's anonymous cache key leaves out the referer. Within the cache window, a request from a non-embeddable or missing referer gets the cached page, including X-Frame-Options ALLOWALL, without ensure_embeddable running.
mediumTopicRetriever#perform_retrieve runs PollFeed inline without a rescue, so a failing or malformed feed raises and aborts retrieval before the fetch_http fallback runs.
highPollFeed fetches feed_polling_url with Kernel#open, so a setting value starting with '|' runs a shell command on the job server. Anyone who can edit site settings gets command execution.
mediumPost#cook returns self.raw for raw_html posts and ignores the text it is given. Callers that cook different text, such as add_topic_to_quotes.rake, store cooked output that does not match the new raw.