Enhance embed URL handling and validation system
Tier 2 hard ruby · local · real merged PR from ai-code-review-evaluation/discourse-graphite #4
Ground-truth defects
TopicRetriever fetches the embed/feed URL with `open(url).read` (Readability) and `open(SiteSetting.feed_polling_url)`. The only guard is `invalid_host?`, which pins the initial referer/embeddable_host; open-uri transparently follows HTTP redirects, so a whitelisted host returning a 3xx to an internal address (link-local 169.254.169.254, a private IP, or a localhost admin port) reaches it. This is a redirect-based SSRF that the host whitelist does not cover.
The postMessage origin check uses reversed substring matching (`discourseUrl.indexOf(e.origin) === -1`), accepting any origin that is a substring of the configured Discourse URL rather than requiring an exact origin match; impact is limited to letting a non-Discourse frame resize the embed iframe.
The TopicEmbed.import method is susceptible to a NoMethodError if the contents parameter is nil when attempting to append a string, and an XSS vulnerability due to unescaped url interpolation in the generated HTML.
poll_feed.rb calls `i.content.scrub` on every item, but SimpleRSS returns nil for `i.content` on plain RSS 2.0 feeds (body in description/content:encoded absent), so `nil.scrub` raises NoMethodError, aborting the whole un-retried hourly poll and importing nothing.
poll_feed.rb passes raw third-party feed HTML to TopicEmbed.import with cook_method raw_html, which post.rb's cook() returns verbatim without sanitization (unlike import_remote's Readability whitelist), and best.html.erb renders it via `raw post.cooked` on a Discourse-origin page with X-Frame-Options ALLOWALL — yielding stored XSS from `<script>` in a feed item.
The change under review
diff (truncated — full diff)
@@ -206,6 +206,10 @@ gem 'unicorn', require: false gem 'puma', require: false gem 'rbtrace', require: false +# required for feed importing and embedding +gem 'ruby-readability', require: false +gem 'simple-rss', require: false + # perftools only works on 1.9 atm group :profile do # travis refuses to install this, instead of fuffing, just avoid it for now @@ -117,6 +117,7 @@ GEM fspath (2.0.5) given_core (3.1.1) sorcerer (>= 0.3.7) + guess_html_encoding (0.0.9) handlebars-source (1.1.2) hashie (2.0.5) highline (1.6.20) @@ -309,6 +310,9 @@ GEM rspec-mocks (~> 2.14.0) ruby-hmac (0.4.0) ruby-openid (2.3.0) + ruby-readability (0.5.7) + guess_html_encoding (>= 0.0.4) + nokogiri (>= 1.4.2) sanitize (2.0.6) nokogiri (>= 1.4.4) sass (3.2.12) @@ -337,6 +341,7 @@ GEM celluloid (>= 0.14.1) ice_cube (~> 0.11.0) sidekiq (~> 2.15.0) + simple-rss (1.3.1) simplecov (0.7.1) multi_json (~> 1.0) simplecov-html (~> 0.7.1) @@ -466,6 +471,7 @@ DEPENDENCIES rinku rspec-given rspec-rails + ruby-readability sanitize sass sass-rails @@ -474,6 +480,7 @@ DEPENDENCIES sidekiq (= 2.15.1) sidekiq-failures sidetiq (>= 0.3.6) + simple-rss simplecov sinatra slim new file mode 100644 @@ -0,0 +1,27 @@ +/* global discourseUrl */ +/* global discourseEmbedUrl */ +(function() { + + var comments = document.getElementById('discourse-comments'), + iframe = document.createElement('iframe'); + iframe.src = discourseUrl + "embed/best?embed_url=" + encodeURIComponent(discourseEmbedUrl); + iframe.id = 'discourse-embed-frame'; + iframe.width = "100%"; + iframe.frameBorder = "0"; + iframe.scrolling = "no"; + comments.appendChild(iframe); + + + function postMessageReceived(e) { + if (!e) { return; } + if (discourseUrl.indexOf(e.origin) === -1) { return; } + + if (e.data) { + if (e.data.type === 'discourse-resize' && e.data.height) { + iframe.height = e.data.height + "px"; + } + } + } + window.addEventListener('message', postMessageReceived, false); + +})(); new file mode 100644 @@ -0,0 +1,69 @@ +//= require ./vendor/normalize +//= require ./common/foundation/base + +article.post { + border-bottom: 1px solid #ddd; + + .post-date { + float: right; + color: #aaa; + font-size: 12px; + margin: 4px 4px 0 0; + } + + .author { + padding: 20px 0; + width: 92px; + float: left; + + text-align: center; + + h3 { + text-align: center; + color: #4a6b82; + font-size: 13px; + margin: 0; + } + } + + .cooked { + padding: 20px 0; + margin-left: 92px; + + p { + margin: 0 0 1em 0; + } + } +} + +header { + padding: 10px 10px 20px 10px; + + font-size: 18px; + + border-bottom: 1px solid #ddd; +} + +footer { + font-size: 18px; + + .logo { + margin-right: 10px; + margin-top: 10px; + } + + a[href].button { + margin: 10px 0 0 10px; + } +} + +.logo { + float: right; + max-height: 30px; +} + +a[href].button { + background-color: #eee; + padding: 5px; + display: inline-block; +} \ No newline at end of file new file mode 100644 @@ -0,0 +1,34 @@ +class EmbedController < ApplicationController + skip_before_filter :check_xhr + skip_before_filter :preload_json + before_filter :ensure_embeddable + + layout 'embed' + + def best + embed_url = params.require(:embed_url) + topic_id = TopicEmbed.topic_id_for_embed(embed_url) + + if topic_id + @topic_view = TopicView.new(topic_id, current_user, {best: 5}) + else + Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url) + render 'loading' + end + + discourse_expires_in 1.minute + end + + private + + def ensure_embeddable + raise Discourse::InvalidAccess.new('embeddable host not set') if SiteSetting.embeddable_host.blank? + raise Discourse::InvalidAccess.new('invalid referer host') if URI(request.referer || '').host != SiteSetting.embeddable_host + + response.headers['X-Frame-Options'] = "ALLOWALL" + rescue URI::InvalidURIError + raise Discourse::InvalidAccess.new('invalid referer host') + end + + +end new file mode 100644 @@ -0,0 +1,24 @@ +require_dependency 'email/sender' +require_dependency 'topic_retriever' + +module Jobs + + # Asynchronously retrieve a topic from an embedded site + class RetrieveTopic < Jobs::Base + + def execute(args) + raise Discourse::InvalidParameters.new(:embed_url) unless args[:embed_url].present? + + user = nil + if args[:user_id] + user = User.where(id: args[:user_id]).first + end + + TopicRetriever.new(args[:embed_url], no_throttle: user.try(:staff?)).retrieve + end + + end + +end + + new file mode 100644 @@ -0,0 +1,41 @@ +# +# Creates and Updates Topics based on an RSS or ATOM feed. +# +require 'digest/sha1' +require_dependency 'post_creator' +require_dependency 'post_revisor' +require 'open-uri' + +module Jobs + class PollFeed < Jobs::Scheduled + recurrence { hourly } + sidekiq_options retry: false + + def execute(args) + poll_feed if SiteSetting.feed_polling_enabled? && + SiteSetting.feed_polling_url.present? && + SiteSetting.embed_by_username.present? + end + + def feed_key + @feed_key ||= "feed-modified:#{Digest::SHA1.hexdigest(SiteSetting.feed_polling_url)}" + end + + def poll_feed + user = User.where(username_lower: SiteSetting.embed_by_username.downcase).first + return if user.blank? + + require 'simple-rss' + rss = SimpleRSS.parse open(SiteSetting.feed_polling_url) + + rss.items.each do |i| + url = i.link + url = i.id if url.blank? || url !~ /^https?\:\/\// + + content = CGI.unescapeHTML(i.content.scrub) + TopicEmbed.import(user, url, i.title, content) + end + end + + end +end @@ -60,6 +60,10 @@ class Post < ActiveRecord::Base @types ||= Enum.new(:regular, :moderator_action) end + def self.cook_methods + @cook_methods ||= Enum.new(:regular, :raw_html) + end + def self.find_by_detail(key, value) includes(:post_details).where(post_details: { key: key, value: value }).first end @@ -124,6 +128,11 @@ class Post < ActiveRecord::Base end def cook(*args) + # For some posts, for example those imported via RSS, we support raw HTML. In that + # case we can skip the rendering pipeline. + return raw if cook_method == Post.cook_methods[:raw_html] + + # Default is to cook posts Plugin::Filter.apply(:after_post_cook, self, post_analyzer.cook(*args)) end new file mode 100644 @@ -0,0 +1,82 @@ +require_dependency 'nokogiri' + +class TopicEmbed < ActiveRecord::Base + belongs_to :topic + belongs_to :post + validates_presence_of :embed_url + validates_presence_of :content_sha1 + + # Import an article from a source (RSS/Atom/Other) + def self.import(user, url, title, contents) + return unless url =~ /^https?\:\/\// + + contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n" + + embed = TopicEmbed.where(embed_url: url).first + content_sha1 = Digest::SHA1.hexdigest(contents) + post = nil + + # If there is no embed, create a topic, post and the embed. + if embed.blank? + Topic.transaction do + creator = PostCreator.new(user, title: title, raw: absolutize_urls(url, contents), skip_validations: true, cook_method: Post.cook_methods[:raw_html]) + post = creator.create + if post.present? + TopicEmbed.create!(topic_id: post.topic_id, + embed_url: url, + content_sha1: content_sha1, + post_id: post.id) + end + end + else + post = embed.post + # Update the topic if it changed + if content_sha1 != embed.content_sha1 + revisor = PostRevisor.new(post) + revisor.revise!(user, absolutize_urls(url, contents), skip_validations: true, bypass_rate_limiter: true) + embed.update_column(:content_sha1, content_sha1) + end + end + + post + end + + def self.import_remote(user, url, opts=nil) + require 'ruby-readability' + + opts = opts || {} + doc = Readability::Document.new(open(url).read, + tags: %w[div p code pre h1 h2 h3 b em i strong a img], + attributes: %w[href src]) + + TopicEmbed.import(user, url, opts[:title] || doc.title, doc.content) + end + + # Convert any relative URLs to absolute. RSS is annoying for this. + def self.absolutize_urls(url, contents) + uri = URI(url) + prefix = "#{uri.scheme}://#{uri.host}" + prefix << ":#{uri.port}" if uri.port != 80 && uri.port != 443 + + fragment = Nokogiri::HTML.fragment(contents) + fragment.css('a').each do |a| + href = a['href'] + if href.present? && href.start_with?('/') + a['href'] = "#{prefix}/#{href.sub(/^\/+/, '')}" + end + end + fragment.css('img').each do |a| + src = a['src'] + if src.present? && src.start_with?('/') + a['src'] = "#{prefix}/#{src.sub(/^\/+/, '')}" + end + end + + fragment.to_html + end + + def self.topic_id_for_embed(embed_url) + TopicEmbed.where(embed_url: embed_url).pluck(:topic_id).first + end + +end new file mode 100644 @@ -0,0 +1,30 @@ +<header> + <%- if @topic_view.posts.present? %> + <%= link_to(I18n.t('embed.title'), @topic_view.topic.url, class: 'button', target: '_blank') %> + <%- else %> + <%= link_to(I18n.t('embed.start_discussion'), @topic_view.topic.url, class: 'button', target: '_blank') %> + <%- end if %> + + <%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %> +</header> + +<%- if @topic_view.posts.present? %> + <%- @topic_view.posts.each do |post| %> + <article class='post'> + <%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %> + <div class='author'> + <img src='<%= post.user.small_avatar_url %>'> + <h3><%= post.user.username %></h3> + </div> + <div class='cooked'><%= raw post.cooked %></div> + <div style='clear: both'></div> + </article> + <%- end %> + + <footer> + <%= link_to(I18n.t('embed.continue'), @topic_view.topic.url, class: 'button', target: '_blank') %> + <%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %> + </footer> + +<% end %> + new file mode 100644 @@ -0,0 +1,12 @@ +<header> + <%= t 'embed.loading' %> + <%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %> +</header> + +<script> + (function() { + setTimeout(function() { + document.location.reload(); + }, 30000); + })(); +</script> \ No newline at end of file new file mode 100644 @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<html> + <head> + <%= stylesheet_link_tag 'embed' %> + + <script> + (function() { + window.onload = function() { + if (parent) { + // Send a post message with our loaded height + parent.postMessage({type: 'discourse-resize', height: document['body'].offsetHeight}, '<%= request.referer %>'); + } + } + })(); + </script> + </head> + <body> + <%= yield %> + </body> +</html> \ No newline at end of file @@ -1474,6 +1474,7 @@ en: spam: 'Spam' rate_limits: 'Rate Limits' developer: 'Developer' + embedding: "Embedding" uncategorized: 'Uncategorized' lightbox:
Leaderboard for this case
hard · 2 of 9 bots fully caught it (22% solve rate) · 58% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Drape (Deep Review) | solved | 5/5 | 100.0% | 17 | 0 |
| 2 | Drape (Review) | solved | 5/5 | 100.0% | 11 | 0 |
| 3 | cursor | partial | 4/5 | 93.3% | 8 | 1 |
| 4 | Claude Code (Opus 5.5) | partial | 4/5 | 73.3% | 11 | 1 |
| 5 | Mjolnir (Opus 5.5) | partial | 3/5 | 66.7% | 8 | 0 |
| 6 | Mjolnir (Sonnet 5.5) | partial | 3/5 | 66.7% | 8 | 0 |
| 7 | greptile | partial | 1/5 | 26.7% | 1 | 0 |
| 8 | Cubic | partial | 1/5 | 26.7% | 14 | 2 |
| 9 | qodo | miss | 0/5 | 0.0% | 1 | 0 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✓ | exact |
| d5 | high | ✓ | exact |
| d7 | medium | ✓ | off by one |
| d8 | high | ✓ | off by one |
The only check is a client-supplied Referer header. The throttle is keyed on the exact URL (`retrieved:#{@embed_url}`), so changing the query string gets past it, and each distinct URL on the embeddable host gets fetched and imported as a new topic. [grounded: tree app/controllers/embed_controller.rb] [consensus 3/3: valid=3]
Ruby allows a line break after a modifier `if`, so `end if` followed by the next generated `_erbout.concat` statement is valid. That concat always returns a truthy string, so the block still renders. The template is neither unparseable nor unpredictable. [invalid: contradiction] [consensus 3/3: invalid=3]
The diff removes the `--category` option and the `created_at` that used to be passed to PostCreator. It now fetches every thread link over HTTP with `open(url)`, which raises for unreachable links and returns nil for links that aren't http(s). [grounded: diff-section lib/tasks/disqus.thor] [consensus 3/3: valid=3]
Post is Trashable, which applies a default_scope that hides deleted posts, so `embed.post` is nil once the post is trashed. `PostRevisor#should_revise?` then calls `@post.raw` on nil, raising NoMethodError inside the `rss.items.each` loop, which stops the rest of the feed from being processed. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
Whenever no embed exists for a URL and feed polling is on, the retrieve job downloads and re-imports the whole feed. The per-URL throttle can be bypassed by varying the URL, so anonymous visitors can trigger this repeatedly. [grounded: tree lib/topic_retriever.rb] [consensus 3/3: valid=3]
AnonymousCache sits at position 0 in the middleware stack, keys only on host and REQUEST_URI, and returns cached hits without calling the app. Later anonymous requests therefore skip the `ensure_embeddable` before_filter, and they also get the earlier requester's Referer baked into the cached page. [grounded: tree app/controllers/embed_controller.rb] [consensus 3/3: valid=3]
`force: true` drops an existing table whenever this migration runs. Installs that already ran it won't re-run it, and top_topics holds derived data, so the practical impact is small. [grounded: diff] [consensus 3/4: valid=3, uncertain=1]
raw comments (11)
When `cook_method` is `raw_html`, `cook` returns `raw` unchanged, with no sanitization. That raw HTML is stored as `cooked` and shown to every forum user. The content comes from external RSS/Atom feeds and is not filtered: `poll_feed` only calls `CGI.unescapeHTML` on it. So a feed item containing `<script>`, `onerror=` or `javascript:` links becomes stored XSS on the forum. PostRevisor also re-cooks through this path, so anyone who later edits one of these posts in the normal editor can inject arbitrary HTML too.
`url` is put into HTML as `<a href='#{url}'>#{url}</a>` without escaping, and the post skips the cooking pipeline. A feed item link or id such as `http://x/'onmouseover='alert(1)` passes the `^https?://` check and breaks out of the attribute. That injects script into a raw-HTML post.
`i.content.scrub` assumes every item has a `<content>` element. Many RSS 2.0 items only have `<description>` or `content:encoded`, so `i.content` is nil and the code raises NoMethodError. That aborts the whole poll, and `TopicRetriever` breaks too because it calls `PollFeed#execute` synchronously.
Any anonymous request with a spoofed Referer header can enqueue `RetrieveTopic` for any `embed_url` on the embeddable host. The throttle is keyed per URL, so varying the query string or fragment gets around it. Each unique URL fetches the remote page and creates a new topic, letting an unauthenticated user spam topics and trigger outbound fetches.
`<%- end if %>` produces `end if` with nothing after the modifier `if` on that line. Ruby then either fails to parse the template or uses the next generated output statement as the `if` condition. Either way the template is broken or behaves unpredictably. It should be `<%- end %>`.
The Disqus import now goes through `TopicEmbed.import_remote`, which causes several regressions. The `--category` option is removed. `created_at` is no longer kept, so topics get the import time instead of their original date. Each thread link is now fetched over HTTP, and an unreachable or non-http link gives a nil post or an exception. Re-running the import returns the existing post, so the comment loop adds duplicate replies.
When an embed already exists, `embed.post` may be nil if the post was deleted. `PostRevisor.new(nil).revise!` then raises, and that aborts the feed poll for every remaining item.
On every cache miss, `perform_retrieve` runs `Jobs::PollFeed.new.execute` synchronously, which downloads and re-imports the whole feed. Uncached embed loads, which anonymous visitors can trigger, therefore cause repeated full feed fetches and imports. This compounds the topic-spam issue above.
`discourse_expires_in` puts the response in the anonymous middleware cache. Middleware serves cached hits before the controller runs, so later anonymous requests skip the `ensure_embeddable` Referer check and the X-Frame-Options header logic for up to a minute.
The origin check `discourseUrl.indexOf(e.origin) === -1` is a substring test, not an exact match. A prefix origin such as `https://forum.example.co` for `https://forum.example.com/` passes, so another frame can resize the iframe.
This edits an existing migration to add `force: true`, which silently drops and recreates the `top_topics` table if it already exists. Editing already-run migrations is risky, and it is unrelated to this feature.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✗ | — |
| d5 | high | ✗ | — |
| d7 | medium | ✗ | — |
| d8 | high | ✓ | exact |
`end if` followed by a newline is valid Ruby: the modifier `if` takes the next generated statement as its condition, so the template compiles and renders. The claimed compile failure doesn't happen. [invalid: contradiction] [consensus 5/5: invalid=5]
force: true does drop an existing top_topics table when the migration runs. In practice that only happens if the table exists but the migration isn't recorded, so the trigger is rare, but the behavior is real. [grounded: diff] [consensus 5/5: valid=5]
The precompile list doesn't include embed.css, and a grep of config finds no other place that adds it. The embed layout links the 'embed' stylesheet, so in production the page won't get its compiled CSS. [grounded: tree config/application.rb] [consensus 5/5: valid=5]
A plain t.string defaults to varchar(255) and nothing validates URL length, so a URL longer than 255 characters makes TopicEmbed.create! fail. [grounded: diff] [consensus 5/5: valid=5]
import checks whether a row exists and then calls create! as two separate steps. The no_throttle option for staff and the hourly PollFeed job both let imports of the same URL run at once, so the second create! can raise RecordNotUnique. [grounded: diff] [consensus 5/5: valid=5]
The response is marked publicly cacheable even though access depends on the request's referer, so a shared cache could serve it, including the ALLOWALL frame header, without the check running. Impact is limited because the content is public and the referer can be spoofed anyway. [grounded: diff] [consensus 5/5: valid=5]
The removed PostCreator call passed created_at: Date.parse(t[:created_at]). The new import_remote path never passes the thread's timestamp, so the first post gets the import time. [grounded: diff] [consensus 5/5: valid=5]
feed_polling_enabled defaults to false and these tests don't stub it, so the && chain stops there. The URL and username tests would still pass even if those guards were removed. [grounded: tree spec/jobs/poll_feed_spec.rb] [consensus 5/5: valid=5]
open-uri is called without explicit timeouts. A slow feed can hold a worker, and the same call also runs inline from TopicRetriever. [grounded: diff] [consensus 5/5: valid=5]
In the default Rails 4 mode, Bundler uses Gemfile_rails4.lock, and this diff updates that file with both gems. Gemfile.lock is only read in the deprecated RAILS3 mode, so default deployments aren't broken. The comment's claimed dependencies are also wrong. [invalid: contradiction] [consensus 4/5: invalid=4, valid=1]
Plain relative paths such as 'img/x.png' are left alone and will resolve against the Discourse host. Protocol-relative '//cdn/x' URLs start with '/' and get rewritten to prefix/cdn/x, which is wrong. [grounded: diff] [consensus 5/5: valid=5]
invalid_host? only compares the host, so an ftp:// URL on the allowed host passes. import_remote then fetches it with open() before import applies its http(s)-only regex. [grounded: diff] [consensus 5/5: valid=5]
This is a test-coverage suggestion. It does not claim the code behaves incorrectly. [consensus 4/5: minor=4, valid=1]
raw comments (15)
<!-- cubic:v=0d1663a1-2949-4122-b2a6-ad48b91f1f8f -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":10} -->
P1: This template fails to compile because `<%- end if %>` emits `end if` with no condition. Replace it with `<%- end %>` so the embed action can render.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/views/embed/best.html.erb, line 6:
<comment>This template fails to compile because `<%- end if %>` emits `end if` with no condition. Replace it with `<%- end %>` so the embed action can render.</comment>
<file context>
@@ -0,0 +1,30 @@
+ <%= link_to(I18n.t('embed.title'), @topic_view.topic.url, class: 'button', target: '_blank') %>
+ <%- else %>
+ <%= link_to(I18n.t('embed.start_discussion'), @topic_view.topic.url, class: 'button', target: '_blank') %>
+ <%- end if %>
+
+ <%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url) %>
</file context>
```
</details>
```suggestion
<%- end %>
```
<!-- cubic:v=7c504590-f3c9-4165-b3b7-8de87c662226 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":9} -->
P1: When this migration runs against a database that already has `top_topics`, `force: true` drops the table and destroys its data before recreating it. Remove `force: true` so the migration cannot silently cause data loss.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At db/migrate/20131223171005_create_top_topics.rb, line 3:
<comment>When this migration runs against a database that already has `top_topics`, `force: true` drops the table and destroys its data before recreating it. Remove `force: true` so the migration cannot silently cause data loss.</comment>
<file context>
@@ -1,6 +1,6 @@
class CreateTopTopics < ActiveRecord::Migration
def change
- create_table :top_topics do |t|
+ create_table :top_topics, force: true do |t|
t.belongs_to :topic
</file context>
```
</details>
```suggestion
create_table :top_topics do |t|
```
<!-- cubic:v=fb5b355a-f724-4c9e-a3f5-4441ca911b13 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":9} -->
P1: When a configured RSS feed contains active HTML, this branch stores it directly in `cooked` without sanitization, creating stored XSS because topic views mark `post.cooked` as HTML-safe. Sanitize or restrict the imported markup before returning the raw-HTML result.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/models/post.rb, line 133:
<comment>When a configured RSS feed contains active HTML, this branch stores it directly in `cooked` without sanitization, creating stored XSS because topic views mark `post.cooked` as HTML-safe. Sanitize or restrict the imported markup before returning the raw-HTML result.</comment>
<file context>
@@ -124,6 +128,11 @@ def post_analyzer
def cook(*args)
+ # For some posts, for example those imported via RSS, we support raw HTML. In that
+ # case we can skip the rendering pipeline.
+ return raw if cook_method == Post.cook_methods[:raw_html]
+
+ # Default is to cook posts
</file context>
```
</details>
<!-- cubic:v=ac5bc1e1-19ab-42c3-9fd1-de4248b3d9f3 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":8} -->
P1: This new stylesheet is never precompiled. The embed layout renders stylesheet_link_tag 'embed', but config.assets.precompile in config/application.rb does not include 'embed.css' and production sets config.assets.compile = false, so the asset is not built and the embed/best page 500s or renders unstyled in production. Add 'embed.css' to the config.assets.precompile list.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/assets/stylesheets/embed.css.scss, line 1:
<comment>This new stylesheet is never precompiled. The embed layout renders stylesheet_link_tag 'embed', but config.assets.precompile in config/application.rb does not include 'embed.css' and production sets config.assets.compile = false, so the asset is not built and the embed/best page 500s or renders unstyled in production. Add 'embed.css' to the config.assets.precompile list.</comment>
<file context>
@@ -0,0 +1,69 @@
+//= require ./vendor/normalize
+//= require ./common/foundation/base
+
</file context>
```
</details>
<!-- cubic:v=03b6452d-8071-4fe0-9454-10609a8c8b64 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":8} -->
P2: When an allowed page URL exceeds 255 characters, PostgreSQL rejects `TopicEmbed.create!` because this column defaults to `varchar(255)`, and the retrieval path has no length validation. Store the URL in a larger bounded column or reject overlong URLs before enqueueing retrieval.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At db/migrate/20131217174004_create_topic_embeds.rb, line 6:
<comment>When an allowed page URL exceeds 255 characters, PostgreSQL rejects `TopicEmbed.create!` because this column defaults to `varchar(255)`, and the retrieval path has no length validation. Store the URL in a larger bounded column or reject overlong URLs before enqueueing retrieval.</comment>
<file context>
@@ -0,0 +1,13 @@
+ create_table :topic_embeds, force: true do |t|
+ t.integer :topic_id, null: false
+ t.integer :post_id, null: false
+ t.string :embed_url, null: false
+ t.string :content_sha1, null: false, limit: 40
+ t.timestamps
</file context>
```
</details>
```suggestion
t.string :embed_url, limit: 1000, null: false
```
<!-- cubic:v=7c5d672b-1095-4bf3-9d67-29f3ce0a3c8a -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":9} -->
P2: When two retrievals for a new URL run concurrently, both imports pass the existing-row check, but this index makes the second `TopicEmbed.create!` raise `ActiveRecord::RecordNotUnique` and roll back its transaction. Make the import atomic or rescue the uniqueness error and reuse the existing row.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At db/migrate/20131217174004_create_topic_embeds.rb, line 11:
<comment>When two retrievals for a new URL run concurrently, both imports pass the existing-row check, but this index makes the second `TopicEmbed.create!` raise `ActiveRecord::RecordNotUnique` and roll back its transaction. Make the import atomic or rescue the uniqueness error and reuse the existing row.</comment>
<file context>
@@ -0,0 +1,13 @@
+ t.timestamps
+ end
+
+ add_index :topic_embeds, :embed_url, unique: true
+ end
+end
</file context>
```
</details>
<!-- cubic:v=320aa5d5-be5f-4c9a-b91f-3a99a25e0e6e -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":10} -->
P2: Anonymous caching bypasses `ensure_embeddable`: after one valid request, anyone can receive the same response for one minute without a matching embedding host. Remove anonymous caching for this referer-authorized action, or make the cache key vary by referer.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/controllers/embed_controller.rb, line 19:
<comment>Anonymous caching bypasses `ensure_embeddable`: after one valid request, anyone can receive the same response for one minute without a matching embedding host. Remove anonymous caching for this referer-authorized action, or make the cache key vary by referer.</comment>
<file context>
@@ -0,0 +1,34 @@
+ render 'loading'
+ end
+
+ discourse_expires_in 1.minute
+ end
+
</file context>
```
</details>
<!-- cubic:v=e954eeeb-c965-4283-b552-cdbe802d1832 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":9} -->
P2: This creates the imported thread’s first post with the import time instead of `t[:created_at]`, leaving the first post newer than its historical replies. Propagate the thread timestamp through `TopicEmbed.import_remote` and `TopicEmbed.import` to `PostCreator`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At lib/tasks/disqus.thor, line 148:
<comment>This creates the imported thread’s first post with the import time instead of `t[:created_at]`, leaving the first post newer than its historical replies. Propagate the thread timestamp through `TopicEmbed.import_remote` and `TopicEmbed.import` to `PostCreator`.</comment>
<file context>
@@ -141,18 +140,12 @@ class Disqus < Thor
- creator = PostCreator.new(user, title: t[:title], raw: "\[[Permalink](#{t[:link]})\]", created_at: Date.parse(t[:created_at]), category: category_id)
- post = creator.create
+ post = TopicEmbed.import_remote(user, t[:link], title: t[:title])
if post.present?
t[:posts].each do |p|
</file context>
```
</details>
<!-- cubic:v=a22bf0c5-0641-4f9d-9482-76013e977b95 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":8} -->
P2: These two tests pass for the wrong reason. `feed_polling_enabled?` is left unstubbed and defaults to false, so the `&&` chain short-circuits before the URL/username checks; `poll_feed` would be skipped even if the `feed_polling_url.present?` or `embed_by_username.present?` guard were removed from the job. Stub the other conditions to true so each test actually isolates the missing setting.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At spec/jobs/poll_feed_spec.rb, line 19:
<comment>These two tests pass for the wrong reason. `feed_polling_enabled?` is left unstubbed and defaults to false, so the `&&` chain short-circuits before the URL/username checks; `poll_feed` would be skipped even if the `feed_polling_url.present?` or `embed_by_username.present?` guard were removed from the job. Stub the other conditions to true so each test actually isolates the missing setting.</comment>
<file context>
@@ -0,0 +1,40 @@
+ end
+
+ it "requires feed_polling_url" do
+ SiteSetting.stubs(:feed_polling_url).returns(nil)
+ poller.expects(:poll_feed).never
+ poller.execute({})
</file context>
```
</details>
```suggestion
SiteSetting.stubs(:feed_polling_enabled?).returns(true)
SiteSetting.stubs(:embed_by_username).returns(embed_by_username)
SiteSetting.stubs(:feed_polling_url).returns(nil)
poller.expects(:poll_feed).never
poller.execute({})
```
<!-- cubic:v=bafaec32-efac-4bb2-a713-043b05bf3f5c -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":8} -->
P2: When the configured feed is slow or unresponsive, this call can block a Sidekiq worker for the network client's full timeout. Pass bounded open and read timeouts to keep feed polling from tying up workers.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/jobs/scheduled/poll_feed.rb, line 29:
<comment>When the configured feed is slow or unresponsive, this call can block a Sidekiq worker for the network client's full timeout. Pass bounded open and read timeouts to keep feed polling from tying up workers.</comment>
<file context>
@@ -0,0 +1,41 @@
+ return if user.blank?
+
+ require 'simple-rss'
+ rss = SimpleRSS.parse open(SiteSetting.feed_polling_url)
+
+ rss.items.each do |i|
</file context>
```
</details>
<!-- cubic:v=ce2b9e6d-5f78-4af0-b69c-36b26f61f810 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":7} -->
P2: Gemfile.lock is not updated for the two new gems. Bundler's lock file is tracked in this repo, so a fresh `bundle install` will have to re-resolve dependencies (including ruby-readability's new deps guess_html_parser and ruby_parser), and any `bundle install --deployment` deploy fails until the lock is regenerated. Run `bundle install` and commit the updated Gemfile.lock.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At Gemfile, line 210:
<comment>Gemfile.lock is not updated for the two new gems. Bundler's lock file is tracked in this repo, so a fresh `bundle install` will have to re-resolve dependencies (including ruby-readability's new deps guess_html_parser and ruby_parser), and any `bundle install --deployment` deploy fails until the lock is regenerated. Run `bundle install` and commit the updated Gemfile.lock.</comment>
<file context>
@@ -206,6 +206,10 @@ gem 'unicorn', require: false
gem 'rbtrace', require: false
+# required for feed importing and embedding
+gem 'ruby-readability', require: false
+gem 'simple-rss', require: false
+
</file context>
```
</details>
<!-- cubic:v=eafe6f99-25e8-4fc8-a578-33726ba1d620 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":9} -->
P2: Imported links and images with ordinary or protocol-relative URLs resolve incorrectly because this branch handles only slash-prefixed paths. Resolve each URL with `URI.join(url, href)` or `URI.join(url, src)` instead of checking only `start_with?('/')`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At app/models/topic_embed.rb, line 64:
<comment>Imported links and images with ordinary or protocol-relative URLs resolve incorrectly because this branch handles only slash-prefixed paths. Resolve each URL with `URI.join(url, href)` or `URI.join(url, src)` instead of checking only `start_with?('/')`.</comment>
<file context>
@@ -0,0 +1,82 @@
+ fragment = Nokogiri::HTML.fragment(contents)
+ fragment.css('a').each do |a|
+ href = a['href']
+ if href.present? && href.start_with?('/')
+ a['href'] = "#{prefix}/#{href.sub(/^\/+/, '')}"
+ end
</file context>
```
</details>
<!-- cubic:v=4684fcf1-8aa9-4541-a98d-ec38f4050acd -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":8} -->
P2: The host check allows non-HTTP schemes to reach `TopicEmbed.import_remote`, which fetches them before the later HTTP-only validation. Restrict the URI scheme to `http` or `https` before performing the request.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At lib/topic_retriever.rb, line 15:
<comment>The host check allows non-HTTP schemes to reach `TopicEmbed.import_remote`, which fetches them before the later HTTP-only validation. Restrict the URI scheme to `http` or `https` before performing the request.</comment>
<file context>
@@ -0,0 +1,55 @@
+ private
+
+ def invalid_host?
+ SiteSetting.embeddable_host != URI(@embed_url).host
+ rescue URI::InvalidURIError
+ # An invalid URI is an invalid host
</file context>
```
</details>
<!-- cubic:v=08ece81a-1d32-4bf1-97e2-8e0328afb706 -->
<!-- cubic:review-run=47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
<!-- metadata:{"confidence":6} -->
P3: The "calls perform_retrieve" test stubs `retrieved_recently?` to return false, so the real throttling logic in `lib/topic_retriever.rb` (`no_throttle` opt-out and the redis `setnx`/expire path) is never exercised by any test. Tests 4 and 5 verify only the mocked branches; the actual redis throttle behavior remains untested. Add a test that lets `retrieved_recently?` run (e.g. stubbing `$redis.setnx` to return true) so the branch `perform_retrieve unless (invalid_host? || retrieved_recently?)` is verified end to end.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At spec/components/topic_retriever_spec.rb, line 34:
<comment>The "calls perform_retrieve" test stubs `retrieved_recently?` to return false, so the real throttling logic in `lib/topic_retriever.rb` (`no_throttle` opt-out and the redis `setnx`/expire path) is never exercised by any test. Tests 4 and 5 verify only the mocked branches; the actual redis throttle behavior remains untested. Add a test that lets `retrieved_recently?` run (e.g. stubbing `$redis.setnx` to return true) so the branch `perform_retrieve unless (invalid_host? || retrieved_recently?)` is verified end to end.</comment>
<file context>
@@ -0,0 +1,46 @@
+
+ it "calls perform_retrieve if it hasn't been retrieved recently" do
+ topic_retriever.expects(:perform_retrieve).once
+ topic_retriever.expects(:retrieved_recently?).returns(false)
+ topic_retriever.retrieve
+ end
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**14 issues found** across 28 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/views/embed/best.html.erb">
<violation number="1" location="app/views/embed/best.html.erb:6">
P1: This template fails to compile because `<%- end if %>` emits `end if` with no condition. Replace it with `<%- end %>` so the embed action can render.</violation>
</file>
<file name="db/migrate/20131223171005_create_top_topics.rb">
<violation number="1" location="db/migrate/20131223171005_create_top_topics.rb:3">
P1: When this migration runs against a database that already has `top_topics`, `force: true` drops the table and destroys its data before recreating it. Remove `force: true` so the migration cannot silently cause data loss.</violation>
</file>
<file name="app/models/post.rb">
<violation number="1" location="app/models/post.rb:133">
P1: When a configured RSS feed contains active HTML, this branch stores it directly in `cooked` without sanitization, creating stored XSS because topic views mark `post.cooked` as HTML-safe. Sanitize or restrict the imported markup before returning the raw-HTML result.</violation>
</file>
<file name="db/migrate/20131217174004_create_topic_embeds.rb">
<violation number="1" location="db/migrate/20131217174004_create_topic_embeds.rb:6">
P2: When an allowed page URL exceeds 255 characters, PostgreSQL rejects `TopicEmbed.create!` because this column defaults to `varchar(255)`, and the retrieval path has no length validation. Store the URL in a larger bounded column or reject overlong URLs before enqueueing retrieval.</violation>
<violation number="2" location="db/migrate/20131217174004_create_topic_embeds.rb:11">
P2: When two retrievals for a new URL run concurrently, both imports pass the existing-row check, but this index makes the second `TopicEmbed.create!` raise `ActiveRecord::RecordNotUnique` and roll back its transaction. Make the import atomic or rescue the uniqueness error and reuse the existing row.</violation>
</file>
<file name="app/controllers/embed_controller.rb">
<violation number="1" location="app/controllers/embed_controller.rb:19">
P2: Anonymous caching bypasses `ensure_embeddable`: after one valid request, anyone can receive the same response for one minute without a matching embedding host. Remove anonymous caching for this referer-authorized action, or make the cache key vary by referer.</violation>
</file>
<file name="lib/tasks/disqus.thor">
<violation number="1" location="lib/tasks/disqus.thor:148">
P2: This creates the imported thread’s first post with the import time instead of `t[:created_at]`, leaving the first post newer than its historical replies. Propagate the thread timestamp through `TopicEmbed.import_remote` and `TopicEmbed.import` to `PostCreator`.</violation>
</file>
<file name="spec/jobs/poll_feed_spec.rb">
<violation number="1" location="spec/jobs/poll_feed_spec.rb:19">
P2: These two tests pass for the wrong reason. `feed_polling_enabled?` is left unstubbed and defaults to false, so the `&&` chain short-circuits before the URL/username checks; `poll_feed` would be skipped even if the `feed_polling_url.present?` or `embed_by_username.present?` guard were removed from the job. Stub the other conditions to true so each test actually isolates the missing setting.</violation>
</file>
<file name="app/jobs/scheduled/poll_feed.rb">
<violation number="1" location="app/jobs/scheduled/poll_feed.rb:29">
P2: When the configured feed is slow or unresponsive, this call can block a Sidekiq worker for the network client's full timeout. Pass bounded open and read timeouts to keep feed polling from tying up workers.</violation>
</file>
<file name="Gemfile">
<violation number="1" location="Gemfile:210">
P2: Gemfile.lock is not updated for the two new gems. Bundler's lock file is tracked in this repo, so a fresh `bundle install` will have to re-resolve dependencies (including ruby-readability's new deps guess_html_parser and ruby_parser), and any `bundle install --deployment` deploy fails until the lock is regenerated. Run `bundle install` and commit the updated Gemfile.lock.</violation>
</file>
<file name="spec/components/topic_retriever_spec.rb">
<violation number="1" location="spec/components/topic_retriever_spec.rb:34">
P3: The "calls perform_retrieve" test stubs `retrieved_recently?` to return false, so the real throttling logic in `lib/topic_retriever.rb` (`no_throttle` opt-out and the redis `setnx`/expire path) is never exercised by any test. Tests 4 and 5 verify only the mocked branches; the actual redis throttle behavior remains untested. Add a test that lets `retrieved_recently?` run (e.g. stubbing `$redis.setnx` to return true) so the branch `perform_retrieve unless (invalid_host? || retrieved_recently?)` is verified end to end.</violation>
</file>
<file name="app/models/topic_embed.rb">
<violation number="1" location="app/models/topic_embed.rb:64">
P2: Imported links and images with ordinary or protocol-relative URLs resolve incorrectly because this branch handles only slash-prefixed paths. Resolve each URL with `URI.join(url, href)` or `URI.join(url, src)` instead of checking only `start_with?('/')`.</violation>
</file>
<file name="lib/topic_retriever.rb">
<violation number="1" location="lib/topic_retriever.rb:15">
P2: The host check allows non-HTTP schemes to reach `TopicEmbed.import_remote`, which fetches them before the later HTTP-only validation. Restrict the URI scheme to `http` or `https` before performing the request.</violation>
</file>
<file name="app/assets/stylesheets/embed.css.scss">
<violation number="1" location="app/assets/stylesheets/embed.css.scss:1">
P1: This new stylesheet is never precompiled. The embed layout renders stylesheet_link_tag 'embed', but config.assets.precompile in config/application.rb does not include 'embed.css' and production sets config.assets.compile = false, so the asset is not built and the embed/best page 500s or renders unstyled in production. Add 'embed.css' to the config.assets.precompile list.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/33/ai_pr_review_github_delivery_a17ccb9bae3ff0d6005280b1a13a79af7b394e5587f1c36b5e972286a21f6611?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F33)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_a17ccb9bae3ff0d6005280b1a13a79af7b394e5587f1c36b5e972286a21f6611:74571f0b33bb36e9bf6d7b6157bf3999330e6570:47aeed70-4090-5a51-9da7-5f3f90113bf9 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | off by one |
| d2 | low | ✗ | — |
| d5 | high | ✓ | exact |
| d7 | medium | ✓ | off by one |
| d8 | high | ✓ | exact |
config/application.rb's precompile list (vendor.js, common.css, desktop.css, ... browser-update.js) doesn't include embed.css or embed.js, and production sets config.assets.compile = false, so the new embed assets aren't precompiled. [grounded: tree app/views/layouts/embed.html.erb] [consensus 5/5: valid=5]
open-uri is a global Kernel#open patch already required by poll_feed.rb, lib/oneboxer.rb and several onebox files loaded in the app, so open(url) in import_remote does fetch over HTTP at runtime. [invalid: contradiction] [consensus 4/5: invalid=4, uncertain=1]
discourse_expires_in runs AnonymousCache.anon_cache for 1 minute even on the loading branch. The loading page reloads after 30s, so anonymous viewers can get the cached loading page again after the topic has been created. [grounded: tree app/controllers/embed_controller.rb] [consensus 5/5: valid=5]
Before this change, PostCreator always created the topic. Now import_remote must fetch the article successfully and import requires an http(s) URL; otherwise it returns nil or raises, so the thread's comments are skipped or the import aborts. [grounded: diff-section lib/tasks/disqus.thor] [consensus 5/5: valid=5]
raw comments (9)
### RSS poll crashes without content
**High Severity**
<!-- DESCRIPTION START -->
`poll_feed` always calls `scrub` on `i.content`. Typical RSS 2.0 items expose `description` or `content:encoded`, not `content`, so `i.content` is `nil`. The hourly job raises `NoMethodError` and skips the rest of the feed.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 67a02e9a-23fc-4f05-8694-908bf3f3bb4e -->
<!-- LOCATIONS START
app/jobs/scheduled/poll_feed.rb#L30-L37
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjJhMzkyNDEyLTNjYzgtNDljNi05NWYwLWQ0YTZhOGRmODhjNCIsImVuY3J5cHRpb25LZXkiOiI0RERvUi1UbzdQS0l5cC1Ld2JhQWFOQl9VQnVTYWJObTJpNFB0eHhRcHc0IiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjJhMzkyNDEyLTNjYzgtNDljNi05NWYwLWQ0YTZhOGRmODhjNCIsImVuY3J5cHRpb25LZXkiOiI0RERvUi1UbzdQS0l5cC1Ld2JhQWFOQl9VQnVTYWJObTJpNFB0eHhRcHc0IiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Embed assets skipped in production
**High Severity**
<!-- DESCRIPTION START -->
The embed layout links `embed` CSS, and host sites need `embed.js`, but neither file is added to `config.assets.precompile`. Production sets `config.assets.compile = false`, so the iframe raises an asset error and the external script is not served.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 8e28544a-5c86-4e34-bb6a-f1f05dbc182c -->
<!-- LOCATIONS START
app/views/layouts/embed.html.erb#L3-L4
app/assets/javascripts/embed.js#L1-L27
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`app/assets/javascripts/embed.js#L1-L27`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/app/assets/javascripts/embed.js#L1-L27)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjU3MDljMWU5LTQ4OGMtNGQzNS04MTgwLTc5YjViOTE0NTYxOSIsImVuY3J5cHRpb25LZXkiOiJ4WW8zenBhdHRmUWhqOVhoRXdvQ04td3Z3bFJKaEs4ci1mNXpUTklwWVBBIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjU3MDljMWU5LTQ4OGMtNGQzNS04MTgwLTc5YjViOTE0NTYxOSIsImVuY3J5cHRpb25LZXkiOiJ4WW8zenBhdHRmUWhqOVhoRXdvQ04td3Z3bFJKaEs4ci1mNXpUTklwWVBBIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Imported footer HTML is unsanitized
**High Severity**
<!-- DESCRIPTION START -->
The import footer interpolates `url` into an HTML tag without escaping, then stores the post as `raw_html` and renders it with `raw`. A crafted `embed_url` or feed link can inject markup that runs on the Discourse origin.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: e78e3f36-781b-4252-a921-5c9478e63928 -->
<!-- LOCATIONS START
app/models/topic_embed.rb#L12-L13
app/models/post.rb#L129-L133
app/views/embed/best.html.erb#L18-L19
LOCATIONS END -->
<details>
<summary>Additional Locations (2)</summary>
- [`app/models/post.rb#L129-L133`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/app/models/post.rb#L129-L133)
- [`app/views/embed/best.html.erb#L18-L19`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/app/views/embed/best.html.erb#L18-L19)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE1YWM4OTFlLWExODEtNDI1Mi1hODJjLTk4OGE3MDcyN2Y4YSIsImVuY3J5cHRpb25LZXkiOiJOYTVNZWltendwSWJKZlpwcUU0UVlfVjFyczNGRmhYc1llMVRpN3JsMGtjIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE1YWM4OTFlLWExODEtNDI1Mi1hODJjLTk4OGE3MDcyN2Y4YSIsImVuY3J5cHRpb25LZXkiOiJOYTVNZWltendwSWJKZlpwcUU0UVlfVjFyczNGRmhYc1llMVRpN3JsMGtjIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### RSS HTML skips sanitization
**High Severity**
<!-- DESCRIPTION START -->
Feed item HTML is unescaped and imported with `cook_method` `raw_html`, so it never passes PrettyText sanitization. Remote feed markup is then stored and shown as-is on the forum and in the embed iframe.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: f02becbe-4fbe-43b3-b853-5df4ae581027 -->
<!-- LOCATIONS START
app/jobs/scheduled/poll_feed.rb#L34-L36
app/models/post.rb#L129-L133
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`app/models/post.rb#L129-L133`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/app/models/post.rb#L129-L133)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjM0NGI5ZTQ4LTcxODYtNGU3Zi04ZWIyLWU3MjVlMzRlNzcxNSIsImVuY3J5cHRpb25LZXkiOiJDY1pPSWQwX3FZcEJPcEdINF9OWF9lNjZlUGNCRU9xTTBXZU05S1pOMWRjIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjM0NGI5ZTQ4LTcxODYtNGU3Zi04ZWIyLWU3MjVlMzRlNzcxNSIsImVuY3J5cHRpb25LZXkiOiJDY1pPSWQwX3FZcEJPcEdINF9OWF9lNjZlUGNCRU9xTTBXZU05S1pOMWRjIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Remote import omits open-uri
**High Severity**
<!-- DESCRIPTION START -->
`import_remote` calls `open(url)` without `require 'open-uri'`. Without that library, Ruby treats the HTTP URL as a local path, so embed retrieval and Disqus `import_remote` fail to fetch the page.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 95dc334c-f022-478a-af46-cc6c71853436 -->
<!-- LOCATIONS START
app/models/topic_embed.rb#L43-L52
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYwMDAxYzVmLTc1ZGEtNGZiYS05YWUyLTFhZGZiNzA3MWVhZSIsImVuY3J5cHRpb25LZXkiOiJ1SUx3Tm44U2NKWkZnQ2d6SFBMQ3FTTnVxcDljV1N1dS1rckxlUnN1RXFVIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYwMDAxYzVmLTc1ZGEtNGZiYS05YWUyLTFhZGZiNzA3MWVhZSIsImVuY3J5cHRpb25LZXkiOiJ1SUx3Tm44U2NKWkZnQ2d6SFBMQ3FTTnVxcDljV1N1dS1rckxlUnN1RXFVIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Loading embed response is cached
**Medium Severity**
<!-- DESCRIPTION START -->
When no topic exists yet, `best` renders `loading` and then always calls `discourse_expires_in 1.minute`. Anonymous cache can keep serving the loading page after `retrieve_topic` has already created the topic, so the 30-second reload still shows loading.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: ae51fa51-0a3e-41ca-b606-f8ed774fc64c -->
<!-- LOCATIONS START
app/controllers/embed_controller.rb#L11-L19
app/views/embed/loading.html.erb#L5-L11
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`app/views/embed/loading.html.erb#L5-L11`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/app/views/embed/loading.html.erb#L5-L11)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUwZDJiOGU0LWRhYjgtNDAzNC1hZDgzLWQxNDc4OWI1ZmUzMiIsImVuY3J5cHRpb25LZXkiOiJtanc1d2docjB4YzBnOGkyeXVDT2FmV3o2Zlp4UVpFYjBRb1JXcFdITU8wIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUwZDJiOGU0LWRhYjgtNDAzNC1hZDgzLWQxNDc4OWI1ZmUzMiIsImVuY3J5cHRpb25LZXkiOiJtanc1d2docjB4YzBnOGkyeXVDT2FmV3o2Zlp4UVpFYjBRb1JXcFdITU8wIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Remote fetch follows unsafe redirects
**Medium Severity**
<!-- DESCRIPTION START -->
`import_remote` uses `open(url)` after only checking that the original host equals `embeddable_host`. `open-uri` follows redirects, so a page on that host can bounce the server to internal addresses.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 79326241-8340-487c-9e20-c1181d4b17b1 -->
<!-- LOCATIONS START
app/models/topic_embed.rb#L47-L50
lib/topic_retriever.rb#L13-L15
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`lib/topic_retriever.rb#L13-L15`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8767d4792fe46e4808979f977a41edeacc4f228/lib/topic_retriever.rb#L13-L15)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI4NDViNTgzLTViNjAtNGE2Zi1iOTc4LTI2MGZhYzVjNTA4YyIsImVuY3J5cHRpb25LZXkiOiJQV0l0RFk2S1V4dURBLXlpRUhrZzVrYnl1MThsYXNiRTc3SEpVMGF4cE9VIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjI4NDViNTgzLTViNjAtNGE2Zi1iOTc4LTI2MGZhYzVjNTA4YyIsImVuY3J5cHRpb25LZXkiOiJQV0l0RFk2S1V4dURBLXlpRUhrZzVrYnl1MThsYXNiRTc3SEpVMGF4cE9VIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Disqus import drops threads on fetch failure
**Medium Severity**
<!-- DESCRIPTION START -->
The importer now creates each thread via `TopicEmbed.import_remote` and only imports Disqus replies if that fetch returns a post. If the original article URL is gone or unreadable, the whole thread including comments is skipped.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 4921f789-c807-45e6-9718-4aa68d1b5c04 -->
<!-- LOCATIONS START
lib/tasks/disqus.thor#L147-L149
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjZkNDNjMWE2LWZlY2QtNGFiOC1hNDcyLWZmMTkxNWRmMzE0OCIsImVuY3J5cHRpb25LZXkiOiJqbHBJT3U3TV9pZVF3ZGRxVzRYOXRJOFJRb3NsalMtMmJWaXRybV9aS21zIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjZkNDNjMWE2LWZlY2QtNGFiOC1hNDcyLWZmMTkxNWRmMzE0OCIsImVuY3J5cHRpb25LZXkiOiJqbHBJT3U3TV9pZVF3ZGRxVzRYOXRJOFJRb3NsalMtMmJWaXRybV9aS21zIiwiYnJhbmNoIjoidDItZGlzY291cnNlLWdyYXBoaXRlLTQiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjozNCwiY29tbWl0U2hhIjoiYTg3NjdkNDc5MmZlNDZlNDgwODk3OWY5NzdhNDFlZGVhY2M0ZjIyOCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 8 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTpjY2RhOTg2OC01OGY5LTRlZjctYTVkZS1mZWFhZDkwYWZhYWMiLCJlbmNyeXB0aW9uS2V5IjoiblRTRXlCMWZ1R2cyVnZsRHp6NUhmemFwYjhBaGVIcDBxWFRDcV84OW9hNCIsImJyYW5jaCI6InQyLWRpc2NvdXJzZS1ncmFwaGl0ZS00IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8767d4792fe46e4808979f977a41edeacc4f228. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | off by one |
| d2 | low | ✓ | exact |
| d5 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | high | ✓ | off by one |
A '//cdn.host/x' value passes start_with?('/') and has all leading slashes stripped, so it becomes prefix/cdn.host/x, pointing at the article's host. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
The port check ignores the scheme, so a URL like https://host:80 loses its non-default port. This is a real but rare edge case. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
open-uri's Kernel#open sends non-URI strings to the original open, which runs '|cmd' as a command or reads a local path. The site setting is admin-controlled, so the attacker must already be an admin. [grounded: tree app/jobs/scheduled/poll_feed.rb] [consensus 3/3: valid=3]
The diff removes the --category option and the created_at/category arguments to PostCreator. import_remote passes neither through, and a fetch that fails or returns nil skips that thread's comments. [grounded: diff] [consensus 3/3: valid=3]
The throttle key is the exact URL, and the host check only compares hosts. Any request with a forged Referer and a new path or query on the embeddable host therefore enqueues a fresh import. [grounded: tree lib/topic_retriever.rb] [consensus 3/3: valid=3]
Post's default scope excludes trashed posts, so embed.post returns nil after deletion. When the content changes, PostRevisor#should_revise? then calls nil.raw and raises, which stops the rest of the poll. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
The before_save hook recooks on every update. For raw_html posts cook returns raw unchanged, so any edit through PostsController#update stores user-supplied HTML/script as cooked, and best.html.erb renders it with raw. [grounded: diff] [consensus 3/3: valid=3]
The method does mutate its argument. However, every current caller passes a freshly built string, so there is no present trigger for a frozen-string error or a duplicated footer. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
discourse_expires_in sets the anonymous-cache duration. The cache key is host plus URI only, and cached responses, including the ALLOWALL header, are served by the middleware before the controller's ensure_embeddable filter runs. [grounded: tree lib/middleware/anonymous_cache.rb] [consensus 3/3: valid=3]
import_remote calls Kernel#open before import's http(s) check, and the Disqus task now passes links taken from the export file. The file is supplied by an admin, so the risk is limited. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
Checking for an existing embed and then creating one is not atomic. Concurrent runs (a staff no_throttle job, the hourly poll, or a retrieve job) can both create a topic, and the unique index makes the second create! raise. [grounded: diff] [consensus 3/3: valid=3]
Every retrieval of an unknown URL runs a full feed fetch and import inline. Because the throttle is keyed per URL, anonymous visitors can trigger repeated feed downloads. [grounded: tree lib/topic_retriever.rb] [consensus 3/3: valid=3]
raw comments (17)
**Protocol-relative links rewritten to the wrong host**
`absolutize_urls` treats any href/src starting with '/' as host-relative. For `//cdn.example.com/a.png` it strips both slashes and points the link at the article's own host. Skip values starting with '//', or resolve each one with `URI.join(url, href)`.
```
app/models/topic_embed.rb:64 if href.present? && href.start_with?('/')
app/models/topic_embed.rb:65 a['href'] = "#{prefix}/#{href.sub(/^\/+/, '')}"
app/models/topic_embed.rb:66 end
app/models/topic_embed.rb:67 end
app/models/topic_embed.rb:72 end
app/models/topic_embed.rb:73 end
```
**Port dropped for mismatched scheme/port**
The port is left out whenever it is 80 or 443, whatever the scheme. So http://host:443 and https://host:80 lose their port. Omit the port only when it equals `uri.default_port`.
```
app/models/topic_embed.rb:58 prefix = "#{uri.scheme}://#{uri.host}"
app/models/topic_embed.rb:59 prefix << ":#{uri.port}" if uri.port != 80 && uri.port != 443
```
**Plain RSS feeds crash on nil `content`**
SimpleRSS only fills `content` for Atom entries. RSS 2.0 items use `description` / `content_encoded`, so `i.content` is nil and `.scrub` raises, which aborts the whole poll. Use `i.content || i.content_encoded || i.description` and skip items that have none.
```
app/jobs/scheduled/poll_feed.rb:36 TopicEmbed.import(user, url, i.title, content)
```
**Feed URL opened with Kernel#open**
`open(SiteSetting.feed_polling_url)` uses open-uri's `Kernel#open`. A value starting with '|' runs a shell command and a plain path reads a local file, so an admin setting becomes command execution on the server. Parse the URL, require an http/https scheme, and fetch with `URI.parse(url).open` or Net::HTTP.
**Disqus import drops dates and category**
The import now goes through `TopicEmbed.import_remote`, which ignores the thread's `created_at`, and the `--category` option was removed. A failed remote fetch or a non-http link now raises or returns nil, so that thread's comments are skipped. Pass created_at/category through to the PostCreator, and rescue fetch errors per thread.
```
lib/tasks/disqus.thor:148 post = TopicEmbed.import_remote(user, t[:link], title: t[:title])
lib/tasks/disqus.thor:117 (base) method_option :category, aliases: '-c', desc: "The category to post in"
lib/tasks/disqus.thor:144 (base) category_id = nil
lib/tasks/disqus.thor:145 (base) if options[:category]
app/models/topic_embed.rb:48 doc = Readability::Document.new(open(url).read,
lib/tasks/disqus.thor:153 (base) creator = PostCreator.new(user, title: t[:title], raw: "\[[Permalink](#{t[:link]})\]", created_at: Date.parse(t[:created_at]), category: category_id)
```
**postMessage origin checked by substring**
`discourseUrl.indexOf(e.origin)` accepts any origin that is a prefix of the forum URL. For example, `https://forum.example.co` passes for `https://forum.example.com/`. Compare `e.origin` exactly to the origin parsed from `discourseUrl`.
```
app/assets/javascripts/embed.js:17 if (discourseUrl.indexOf(e.origin) === -1) { return; }
```
**Anonymous users can create unlimited topics**
The throttle is keyed on the exact `embed_url`. Changing the query string with a forged Referer gets past it, and each request imports a new topic and polls the feed. Add a global or per-IP rate limit on topic creation.
```
lib/topic_retriever.rb:21 def retrieved_recently?
lib/topic_retriever.rb:22 # We can disable the throttle for some users, such as staff
lib/topic_retriever.rb:23 return false if @opts[:no_throttle]
lib/topic_retriever.rb:25 # Throttle other users to once every 60 seconds
lib/topic_retriever.rb:27 if $redis.setnx(retrieved_key, "1")
app/controllers/embed_controller.rb:26 raise Discourse::InvalidAccess.new('invalid referer host') if URI(request.referer || '').host != SiteSetting.embeddable_host
```
**Embed URL injected unescaped into raw-HTML post**
The URL goes unescaped into a single-quoted `href` of a `raw_html` post. A URL on the embeddable host like `http://host/x'onmouseover='alert(1)` passes `URI()` and becomes stored XSS. HTML-escape `url` (e.g. `ERB::Util.html_escape`) for both the attribute and the link text.
```
app/models/topic_embed.rb:13 contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
app/models/post.rb:131 # For some posts, for example those imported via RSS, we support raw HTML. In that
app/models/post.rb:132 # case we can skip the rendering pipeline.
app/models/post.rb:133 return raw if cook_method == Post.cook_methods[:raw_html]
app/models/topic_embed.rb:22 creator = PostCreator.new(user, title: title, raw: absolutize_urls(url, contents), skip_validations: true, cook_method: Post.cook_methods[:raw_html])
app/views/embed/best.html.erb:19 <div class='cooked'><%= raw post.cooked %></div>
```
**Feed update crashes after imported post is deleted**
Deleted posts are hidden by the default scope, so `embed.post` returns nil once a moderator deletes the imported post. When that feed item's content changes, `PostRevisor.new(nil).revise!` raises and stops the rest of the poll. Return early (or recreate the post) when `embed.post` is nil.
```
app/models/topic_embed.rb:32 post = embed.post
app/models/topic_embed.rb:33 # Update the topic if it changed
app/models/topic_embed.rb:34 if content_sha1 != embed.content_sha1
app/models/topic_embed.rb:35 revisor = PostRevisor.new(post)
lib/trashable.rb:5 default_scope { where(with_deleted_scope_sql) }
lib/post_revisor.rb:27 @post.raw != @new_raw
```
**Editing an imported post allows arbitrary script**
When a `raw_html` post is edited, the new raw text is saved as `cooked` verbatim. Its owner (`embed_by_username`, who may not be staff) or any staff member can inject `<script>`. Sanitize raw HTML before using it as cooked, or switch back to regular cooking on user edits.
```
app/models/post.rb:130 def cook(*args)
app/models/post.rb:131 # For some posts, for example those imported via RSS, we support raw HTML. In that
app/models/post.rb:132 # case we can skip the rendering pipeline.
app/models/post.rb:133 return raw if cook_method == Post.cook_methods[:raw_html]
app/models/post.rb:321 self.cooked = cook(raw, topic_id: topic_id) unless new_record?
```
**Feed/remote HTML stored and served unsanitized**
Imported content is saved as `raw_html` and served as-is. Feed items get no filtering at all, and Readability still keeps `javascript:` hrefs, so scripts and event handlers come through. Sanitize imported HTML with a strict whitelist before storing.
```
app/models/topic_embed.rb:13 contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
app/models/topic_embed.rb:15 embed = TopicEmbed.where(embed_url: url).first
app/models/topic_embed.rb:16 content_sha1 = Digest::SHA1.hexdigest(contents)
app/models/topic_embed.rb:17 post = nil
app/models/post.rb:133 return raw if cook_method == Post.cook_methods[:raw_html]
app/views/embed/best.html.erb:18 </div>
```
**`import` mutates the caller's content string**
`contents << ...` appends the footer to the string the caller passed in. A frozen literal raises, and a caller that reuses the string gets the footer appended again. Use `contents = contents + ...`.
```
app/models/topic_embed.rb:13 contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
```
**Cached embed page skips the Referer check**
`discourse_expires_in` caches the response by URL only. Later anonymous requests are served by the middleware before `ensure_embeddable` runs, so any site gets the ALLOWALL page. Don't anon-cache this action.
```
app/controllers/embed_controller.rb:20 end
app/controllers/embed_controller.rb:25 raise Discourse::InvalidAccess.new('embeddable host not set') if SiteSetting.embeddable_host.blank?
app/controllers/embed_controller.rb:26 raise Discourse::InvalidAccess.new('invalid referer host') if URI(request.referer || '').host != SiteSetting.embeddable_host
app/controllers/embed_controller.rb:28 response.headers['X-Frame-Options'] = "ALLOWALL"
lib/middleware/anonymous_cache.rb:83 helper.cached or helper.cache(@app.call(env))
app/views/layouts/embed.html.erb:11 parent.postMessage({type: 'discourse-resize', height: document['body'].offsetHeight}, '<%= request.referer %>');
```
**Remote URL opened before its scheme is checked**
`import_remote` calls `open(url)` before `import` checks for `http(s)`. For the Disqus import, `t[:link]` comes from the export file, so a link like `|cmd` or a local path is executed or read. Return early unless `url =~ /^https?:\/\//`, and fetch via `URI.parse(url).open`.
```
app/models/topic_embed.rb:48 doc = Readability::Document.new(open(url).read,
app/models/topic_embed.rb:49 tags: %w[div p code pre h1 h2 h3 b em i strong a img],
app/models/topic_embed.rb:50 attributes: %w[href src])
lib/tasks/disqus.thor:148 post = TopicEmbed.import_remote(user, t[:link], title: t[:title])
app/models/topic_embed.rb:11 return unless url =~ /^https?\:\/\//
```
**Concurrent imports create duplicate topics or crash**
Two workers (repeated retrieve jobs, or a job plus the hourly poll) can both find no embed for a URL and both create a topic; the unique index makes the second `create!` raise. Lock per URL around the import, or rescue `RecordNotUnique` and return the existing post.
```
app/models/topic_embed.rb:15 embed = TopicEmbed.where(embed_url: url).first
app/models/topic_embed.rb:16 content_sha1 = Digest::SHA1.hexdigest(contents)
app/models/topic_embed.rb:17 post = nil
app/models/topic_embed.rb:19 # If there is no embed, create a topic, post and the embed.
db/migrate/20131217174004_create_topic_embeds.rb:11 add_index :topic_embeds, :embed_url, unique: true
```
**Remote fetch follows redirects to internal hosts**
`open(url)` (open-uri) follows redirects to any host, and only the first URL's host is checked. An open redirect on the embeddable host lets an anonymous user fetch internal addresses and publish the response as a topic. Disable redirects (`redirect: false`) or re-check the host of each redirect target.
```
app/models/topic_embed.rb:48 doc = Readability::Document.new(open(url).read,
app/models/topic_embed.rb:49 tags: %w[div p code pre h1 h2 h3 b em i strong a img],
app/models/topic_embed.rb:50 attributes: %w[href src])
app/models/topic_embed.rb:52 TopicEmbed.import(user, url, opts[:title] || doc.title, doc.content)
lib/topic_retriever.rb:14 def invalid_host?
lib/topic_retriever.rb:15 SiteSetting.embeddable_host != URI(@embed_url).host
lib/topic_retriever.rb:16 rescue URI::InvalidURIError
lib/topic_retriever.rb:17 # An invalid URI is an invalid host
lib/topic_retriever.rb:18 true
lib/topic_retriever.rb:19 end
```
**Each unknown embed URL refetches the whole feed**
With feed polling on, every retrieval for a URL the forum hasn't seen runs the full `PollFeed` fetch and import inline. Anonymous visitors can trigger repeated feed downloads. Rate-limit feed polls (e.g. using a Redis key) rather than polling for every request.
```
lib/topic_retriever.rb:39 # First check RSS if that is enabled
lib/topic_retriever.rb:40 if SiteSetting.feed_polling_enabled?
lib/topic_retriever.rb:41 Jobs::PollFeed.new.execute({})
lib/topic_retriever.rb:42 return if TopicEmbed.where(embed_url: @embed_url).exists?
app/jobs/scheduled/poll_feed.rb:24 def poll_feed
app/jobs/scheduled/poll_feed.rb:25 user = User.where(username_lower: SiteSetting.embed_by_username.downcase).first
app/jobs/scheduled/poll_feed.rb:26 return if user.blank?
app/jobs/scheduled/poll_feed.rb:28 require 'simple-rss'
app/jobs/scheduled/poll_feed.rb:29 rss = SimpleRSS.parse open(SiteSetting.feed_polling_url)
app/jobs/scheduled/poll_feed.rb:31 rss.items.each do |i|
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | off by one |
| d2 | low | ✓ | exact |
| d5 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | high | ✓ | exact |
Post includes Trashable, whose default_scope hides deleted rows, so `embed.post` is nil for a trashed post. If the content hash has changed, `PostRevisor#should_revise?` then calls `@post.raw` on nil and raises. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
The diff removes the --category option and the created_at argument. It also replaces the Permalink post with `import_remote`, which fetches each thread over HTTP via `open(url)` with no rescue. The behaviour regressions are real, though they look partly intentional. [grounded: diff] [consensus 3/3: valid=3]
`setnx` and `expire` are two separate, non-atomic calls. If the process crashes between them, the key is left with no TTL and that URL stays throttled forever. The failure window is narrow. [grounded: tree lib/topic_retriever.rb] [consensus 3/3: valid=3]
`//cdn.example.com/x.png` starts with '/', and `sub(/^\/+/, '')` strips both slashes. The URL is rewritten to `http://host/cdn.example.com/x.png`, which breaks the link or image. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
`discourse_expires_in` turns on AnonymousCache, a Rack middleware keyed only by host and URI. It serves cached 200 responses, including the ALLOWALL header, before the controller runs, so `ensure_embeddable`'s referer check is skipped for later anonymous requests. [grounded: tree lib/middleware/anonymous_cache.rb] [consensus 3/3: valid=3]
The `^https?://` regex only checks the prefix, so a URL such as 'http://a b' gets through. `URI()` then raises InvalidURIError, and nothing in `import` or `PollFeed`'s loop rescues it, so the remaining feed items are not imported. [grounded: tree app/models/topic_embed.rb] [consensus 3/3: valid=3]
raw comments (11)
**Item without content aborts the feed poll**
When a feed item has no content element, `i.content` is nil and `.scrub` raises NoMethodError. This aborts the poll, and the embed retrieval that runs it, so later items are never imported. Fall back to description, or skip items with nil content.
```
app/jobs/scheduled/poll_feed.rb:36 TopicEmbed.import(user, url, i.title, content)
```
**Crash when embedded post was deleted**
When a `TopicEmbed` row exists but its post or topic has been deleted, `embed.post` is nil. If the feed content has changed, `PostRevisor.new(nil).revise!` raises NoMethodError. Handle `embed.post.blank?` before revising.
```
app/models/topic_embed.rb:27 content_sha1: content_sha1,
app/models/topic_embed.rb:28 post_id: post.id)
app/models/topic_embed.rb:29 end
app/models/topic_embed.rb:30 end
```
**Disqus import loses category and date, fetches web**
The change removes the `--category` option, and `created_at` is no longer passed. Each thread now needs a live HTTP fetch via `TopicEmbed.import_remote`. It no longer posts the Permalink. Keep the category/created_at options, and rescue fetch errors, falling back to the Permalink post.
```
lib/tasks/disqus.thor:117 (base) method_option :category, aliases: '-c', desc: "The category to post in"
lib/tasks/disqus.thor:144 (base) category_id = nil
lib/tasks/disqus.thor:145 (base) if options[:category]
lib/tasks/disqus.thor:146 (base) category_id = Category.where(name: options[:category]).first.try(:id)
```
**Remote fetch follows redirects to any host**
`import_remote` calls `open(url)` (open-uri) with the embed_url param. `TopicRetriever` only checks the host of the initial URL, and open-uri follows redirects to other hosts, including internal ones. Fetch with redirects disabled or re-check the host after each redirect.
```
app/models/topic_embed.rb:42 end
app/models/topic_embed.rb:44 def self.import_remote(user, url, opts=nil)
app/models/topic_embed.rb:45 require 'ruby-readability'
app/models/topic_embed.rb:47 opts = opts || {}
```
**Weak origin check on resize message**
`discourseUrl.indexOf(e.origin) === -1` is a substring test. Any origin that is a substring of discourseUrl (including an empty string) passes, so it is not an exact origin comparison. Parse discourseUrl and compare `e.origin` for strict equality.
```
app/assets/javascripts/embed.js:17 if (discourseUrl.indexOf(e.origin) === -1) { return; }
```
**Throttle key can get stuck forever**
`retrieved_recently?` runs `setnx` and `expire` as two separate Redis calls. If the process dies or Redis fails between them, the key never expires. Set the key and its TTL atomically (`SET key 1 NX EX 60`).
```
lib/topic_retriever.rb:27 if $redis.setnx(retrieved_key, "1")
lib/topic_retriever.rb:28 $redis.expire(retrieved_key, 60)
lib/topic_retriever.rb:29 return false
lib/topic_retriever.rb:30 end
```
**Protocol-relative URLs get mangled into wrong links**
`absolutize_urls` treats any href/src starting with `/` as site-relative, including protocol-relative `//cdn.example.com/x.png`. These are rewritten to `http://host/cdn.example.com/x.png`, breaking images and links. Skip values starting with `//` (or prepend only the scheme).
```
app/models/topic_embed.rb:61 fragment = Nokogiri::HTML.fragment(contents)
app/models/topic_embed.rb:62 fragment.css('a').each do |a|
app/models/topic_embed.rb:63 href = a['href']
app/models/topic_embed.rb:64 if href.present? && href.start_with?('/')
```
**Imported feed HTML stored unsanitized, enabling stored XSS**
For `raw_html` posts, `cook` returns `raw` without any sanitizing. Feed content from `PollFeed` is attacker-controlled, so script or `onerror` markup ends up in `cooked` and renders for every viewer. Sanitize the HTML with an allowlist in `cook` for raw_html posts.
```
app/models/post.rb:130 def cook(*args)
app/models/post.rb:131 # For some posts, for example those imported via RSS, we support raw HTML. In that
app/models/post.rb:132 # case we can skip the rendering pipeline.
app/models/post.rb:133 return raw if cook_method == Post.cook_methods[:raw_html]
```
**Unescaped URL injected into HTML attribute**
`url` is put into `<a href='#{url}'>` unescaped. The `^https?://` check is line-anchored and allows `'`, so a URL can break out of the attribute and inject handlers into the stored raw HTML. HTML-escape url in the footer and use \A anchors.
```
app/models/topic_embed.rb:7 validates_presence_of :content_sha1
app/models/topic_embed.rb:9 # Import an article from a source (RSS/Atom/Other)
app/models/topic_embed.rb:10 def self.import(user, url, title, contents)
```
**Cached embed page skips the referer check**
`discourse_expires_in` caches the 200 response keyed only by host and URI. Later anonymous requests with any referer are served from the cache before `ensure_embeddable` runs, with `X-Frame-Options: ALLOWALL`. Don't cache these responses, or include the referer host in the cache key.
```
app/controllers/embed_controller.rb:4 before_filter :ensure_embeddable
app/controllers/embed_controller.rb:19 discourse_expires_in 1.minute
```
**Invalid feed link URI aborts whole import**
`absolutize_urls` calls `URI(url)`, which raises `URI::InvalidURIError` for links with spaces or non-ASCII characters. The `^https?://` check lets these through and nothing rescues the error, so `PollFeed` dies for the whole feed. Rescue `URI::InvalidURIError` in `import` and skip the item.
```
app/models/topic_embed.rb:58 prefix = "#{uri.scheme}://#{uri.host}"
app/models/topic_embed.rb:59 prefix << ":#{uri.port}" if uri.port != 80 && uri.port != 443
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✗ | — |
| d5 | high | ✗ | — |
| d7 | medium | ✗ | — |
| d8 | high | ✓ | exact |
raw comments (2)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> <a href="#"><img alt="security" src="https://greptile-static-assets.s3.amazonaws.com/badges/Security.svg?v=2" align="top"></a> **Imported HTML Enables XSS**
Imported RSS content is passed to `PostCreator` with the new `raw_html` cook method. This returns external HTML without the normal rendering or sanitization pipeline. The feed-controlled markup is then stored as `cooked` and rendered with `raw post.cooked` on the Discourse origin, so a malicious or compromised feed can execute stored JavaScript in viewers' sessions. Sanitize imported HTML before storing or rendering it instead of treating it as trusted raw HTML.
**How this was verified:** RSS item content flows directly through `TopicEmbed.import` into the raw-HTML cooking branch and is rendered unescaped by the embed view.
<h3>Greptile Summary</h3>
This PR adds externally embeddable discussion highlights, asynchronous article retrieval, RSS/Atom topic importing, and a raw-HTML cooking mode for imported posts. It also adds the supporting settings, routes, migrations, dependencies, views, assets, and tests.
- Creates topics from configured feeds or pages on the embeddable host.
- Serves selected replies through an iframe and resizes it using `postMessage`.
- Adds persistent mappings between source URLs and imported topics/posts.
- Introduces a serious trust-boundary issue because imported feed HTML bypasses sanitization.
<h3>Confidence Score: 3/5</h3>
This PR is not safe to merge until externally sourced article and feed HTML is sanitized before being stored or rendered on the Discourse origin.
The new import path deliberately bypasses the normal cooking pipeline for untrusted feed content and then renders that content as raw HTML, creating a concrete stored cross-site scripting path.
**Files Needing Attention:** app/models/topic_embed.rb, app/models/post.rb, app/jobs/scheduled/poll_feed.rb, app/views/embed/best.html.erb
<details open><summary><h3>Security Review</h3></summary>
Imported RSS content is persisted and rendered as raw HTML on the Discourse origin without sanitization, enabling stored cross-site scripting when a feed is malicious or compromised.
</details>
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| app/models/topic_embed.rb | Adds remote article import and URL normalization, but persists externally sourced content using an unsanitized raw-HTML cooking mode. |
| app/models/post.rb | Adds cook-method selection and a raw-HTML branch that bypasses the normal post processing pipeline. |
| app/jobs/scheduled/poll_feed.rb | Adds hourly RSS/Atom importing and passes feed-controlled item content directly into topic creation. |
| lib/topic_retriever.rb | Adds throttled retrieval for URLs on the configured embeddable host. |
| app/controllers/embed_controller.rb | Adds the embed endpoint, referer-host gating, asynchronous retrieval, and TopicView rendering. |
| app/views/embed/best.html.erb | Renders selected replies in the iframe, including persisted cooked HTML without escaping. |
</details>
<details open><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Configured RSS feed or embedded page] --> B[PollFeed / TopicRetriever]
B --> C[TopicEmbed.import]
C --> D[PostCreator with raw_html]
D --> E[(Post raw and cooked HTML)]
E --> F[EmbedController and TopicView]
F --> G[embed/best renders raw post.cooked]
G --> H[Browser on Discourse origin]
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update Gemfile and 27 more files"](https://github.com/drape-io/crbench-greptile-2026-09/commit/cf628f23afdbd61c01d7ea72dd6b8427f0a2a34e) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284377)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✗ | — |
| d5 | high | ✓ | off by one |
| d7 | medium | ✓ | exact |
| d8 | high | ✓ | exact |
A protocol-relative URL such as `//cdn.example.com/x.png` also starts with '/'. The code strips the leading slashes and puts the source host in front, which produces the wrong URL `http://host/cdn.example.com/x.png`. [grounded: diff] [consensus 3/3: valid=3]
The diff deletes the `--category` option and swaps the PostCreator call, which passed `created_at` and `category`, for `import_remote`. `import_remote` accepts neither value. [grounded: diff] [consensus 3/3: valid=3]
The importer now fetches each thread URL over the network with no rescue. One failed fetch raises an error and stops the whole import loop. The old code made no network calls. [grounded: diff] [consensus 3/3: valid=3]
SimpleRSS fills `content` only from a `<content>` tag. RSS 2.0 items that carry only `description` or `content:encoded` leave it nil, so `.scrub` raises NoMethodError and the whole poll stops. [grounded: tree app/jobs/scheduled/poll_feed.rb] [consensus 3/3: valid=3]
The category option and the original topic `created_at` are dropped. Replies still use `Date.parse(p[:created_at])`, so they end up dated earlier than their topic. [grounded: diff] [consensus 3/3: valid=3]
raw comments (8)
[P1] Raw HTML posts skip all sanitization. Path
When `cook_method` is `raw_html`, `cook` returns `raw` as-is. It never goes through PrettyText's sanitizer, and the views then print it unescaped (`raw post.cooked` in embed/best.html.erb, plus the normal topic view). Feed content (`CGI.unescapeHTML(i.content)` in PollFeed) and remotely fetched pages (`import_remote`) are written straight into Discourse posts. Readability only filters tag names, so an `href` such as `javascript:...` gets through, and feed items are not filtered at all. So any `‹script›`, `‹iframe›`, `onerror=` or `javascript:` link in the feed or source page runs in the forum's origin for every reader. This happens whenever feed polling or the embed retriever is enabled and the source HTML contains active content
[P2] Feed polling crashes on RSS 2.0 items that have no `‹content›` element. Path
SimpleRSS sets `item.content` only from an Atom-style `‹content›` tag. Typical RSS 2.0 feeds, such as WordPress's, put the body in `‹description›` or `‹content:encoded›` (`content_encoded`), so `i.content` is `nil`. `i.content.scrub` then raises NoMethodError. The whole poll job aborts and nothing from that feed is imported. TopicRetriever also calls this job synchronously, so its HTTP fallback is never reached either
[P2] Protocol-relative URLs are rewritten to the wrong host. Path
absolutize_urls` treats every `href`/`src` that starts with `/` as host-relative. A protocol-relative URL such as `//cdn.example.com/img.png` also starts with `/`, so it becomes `http://blog.example.com/cdn.example.com/img.png` after the `sub(/^\/+/, '')`. Images and links served from CDNs this way are broken in every imported post
[P2] The Disqus importer loses its `--category` option and the original topic dates. Path
This change deletes the existing `method_option :category` and the code that resolved the category. It also replaces the `PostCreator` call that passed `category:` and `created_at: Date.parse(t[:created_at])` with `TopicEmbed.import_remote`, which accepts neither. Imports that used `-c` now fail on the unknown option, or silently put topics in the default category. Every imported topic is also dated at import time instead of the original thread date. This looks like an accidental regression from re-applying the old embed commit over newer importer changes
[P2] One unreachable thread URL aborts the whole Disqus import. Path
The importer now calls `TopicEmbed.import_remote` for each thread, which does `open(url).read` with no rescue. Old Disqus exports often contain links that now 404, time out, or point at hosts that no longer exist. The first such link raises `OpenURI::HTTPError` or a socket error and stops the whole task partway through. Previously the importer made no network calls
[P2] RSS 2.0 feeds crash the poller because `i.content` is nil
app/jobs/scheduled/poll_feed.rb:36 SimpleRSS sets `content` only for Atom `‹content›`. RSS 2.0 feeds (such as WordPress) put the body in `‹description›`, or in `‹content:encoded›`, which SimpleRSS exposes as `content_encoded`. For those items, `i.content` is nil, so `i.content.scrub` raises NoMethodError. Because the job loops over all items, the error ends the whole poll and nothing is imported. `TopicRetriever#perform_retrieve` calls `Jobs::PollFeed.new.execute({})` inline, so the same error also breaks `RetrieveTopic` whenever feed polling is on. In practice feed polling only works for Atom feeds. Use `content_encoded` or `description` as a fallback, and skip items that have no body.
[P2] Feed content goes into posts as unsanitized raw HTML
app/models/topic_embed.rb:13-22 Posts imported with `cook_method: raw_html` skip the cooking/sanitizing pipeline (`Post#cook` returns `raw` unchanged). For feed imports, `contents` is the unescaped feed HTML with no tag or attribute filtering. The "imported from" footer also places `url` inside `href='…'` without escaping it. So any `‹script›`, `onerror=`, or `javascript:` link in a feed item, or a `'` in an item link, ends up as HTML on the Discourse origin: in the topic and in `embed/best`, which renders it with `raw post.cooked`. This is a risk whenever the feed includes third-party content or the blog is compromised. The content should be sanitized (or at least go through the Readability whitelist) before it is stored as raw HTML, and the URL should be escaped.
[P3] Disqus import drops the `--category` option and original topic dates
lib/tasks/disqus.thor:148 This change deletes the `--category` method_option and the `category_id` lookup. It also replaces `PostCreator.new(..., created_at: ..., category: category_id)` with `TopicEmbed.import_remote(user, t[:link], title: t[:title])`. Disqus imports can no longer be put into a category (passing `-c` now fails as an unknown option), and every imported topic gets the current time instead of the thread's `created_at`. The replies keep their original dates, so they end up older than their topic. This looks like an accidental regression from merging over the newer task, not an intended change.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✗ | — |
| d5 | high | ✓ | exact |
| d7 | medium | ✓ | exact |
| d8 | high | ✓ | exact |
A protocol-relative href like //cdn.example.com/x starts with '/' and gets leading slashes stripped and the site prefix prepended, producing http://host/cdn.example.com/x. [grounded: diff] [consensus 3/3: valid=3]
Same protocol-relative mis-rewrite as finding 1; relative paths without a leading slash are also left unresolved. [grounded: diff] [consensus 3/3: valid=3]
Plain RSS items that only have a description leave content nil, so nil.scrub raises NoMethodError and aborts the poll and the retriever that calls it. [grounded: diff] [consensus 3/3: valid=3]
The diff removes the --category option and the created_at that was passed to PostCreator, and replaces them with a live HTTP fetch whose exceptions are not rescued. [grounded: diff] [consensus 3/3: valid=3]
Gemfile.lock and Gemfile_rails_master.lock exist in the repo, and grep finds neither new gem in them; only Gemfile_rails4.lock was updated. [grounded: tree Gemfile] [consensus 3/3: valid=3]
raw comments (8)
[P1] Unsanitized feed HTML stored as cooked and rendered raw (stored XSS)
`Post#cook` now returns `raw` unchanged for `raw_html` posts. `Jobs::PollFeed` feeds the RSS/Atom `content` (after only `CGI.unescapeHTML`) into `TopicEmbed.import`, which creates a `raw_html` post. Nothing strips `‹script›`, event-handler attributes or `javascript:` links on this path. Only the `import_remote` path goes through Readability's tag whitelist. A feed item containing script (a compromised or untrusted feed, or one with user-supplied content) is saved verbatim as `cooked`. It then runs in the forum origin when the topic page is viewed, and also in `embed/best` via `raw post.cooked`. Sanitize the HTML before storing or rendering it.
[P2] Protocol-relative URLs are rewritten into broken paths
`absolutize_urls` treats any `href` or `src` starting with `/` as site-relative and strips all leading slashes. A protocol-relative URL such as `//cdn.example.com/img.png` becomes `http://host/cdn.example.com/img.png`. This breaks images and links in imported content from feeds or pages that use `//` URLs.
[P2] A single item with no `content` aborts the whole feed poll
`i.content.scrub` is called without a nil check. SimpleRSS returns nil `content` for items that only have `‹description›` or `‹summary›`, which is common in RSS 2.0. That raises `NoMethodError`, and the exception aborts the loop, so later items are never imported. `String#scrub` also exists only on Ruby 2.1 and later, and the Gemfile still carries 1.9-era comments. Fall back to `description`, skip empty items, and avoid `scrub` on older Rubies.
[P1] Imported HTML is stored and served unsanitized (stored XSS)
With `cook_method == raw_html`, `Post#cook` returns `raw` verbatim, bypassing the sanitizer used by the normal cooking pipeline. The raw comes from the RSS feed (`PollFeed` does `CGI.unescapeHTML(i.content)`) or from a remote page fetched by `import_remote`, where readability's tag whitelist is not a security sanitizer, and `TopicEmbed.import` also interpolates `url` unescaped into an `‹a href='...'›`. That HTML is then stored in `cooked` and rendered on the main Discourse origin in normal topic pages and in `embed/best` (`raw post.cooked`). Any `‹script›`, `onerror=` or `javascript:` content in a feed item or embedded page therefore executes for every viewer. Severity depends on the feed or embeddable host being attacker-influenced, which is realistic for third-party feeds and comment-bearing pages. The HTML should be run through a sanitizer (for example `Sanitize`) before it is stored, and the URL should be escaped.
[P2] Protocol-relative URLs are rewritten into broken links
`absolutize_urls` treats any `href` or `src` that starts with `/` as site-relative. A protocol-relative URL such as `//cdn.example.com/img.png` has its leading slashes stripped and the host prefix prepended, giving `http://site/cdn.example.com/img.png`. Images and links that use `//host/...` in imported feeds or pages are therefore broken. Values starting with `//` should be skipped or given the scheme instead. Relative paths without a leading slash (`foo/bar`) are also left unresolved.
[P2] `PollFeed` crashes when a feed item has no `content`
`i.content.scrub` raises NoMethodError if an item has no `content` element. SimpleRSS only sets `content` for Atom `‹content›` or RSS `content:encoded`, so plain RSS items that carry only `‹description›` have `content == nil`. The exception aborts the whole hourly poll, and also aborts `TopicRetriever#perform_retrieve` when `feed_polling_enabled` is on. A fallback to `i.description` or a nil guard is needed.
[P2] `disqus import` loses its category option and each thread's creation date
The `--category` option is removed, so existing invocations that pass `-c` now fail as an unknown option. The `PostCreator` call that set `created_at` is also replaced by `TopicEmbed.import_remote`, so the topic no longer gets the Disqus thread's `created_at`. Each thread now also makes a live HTTP fetch of `t[:link]`. A fetch failure raises and aborts the whole import, and dead links on archived sites would break it. These are unrelated behavior regressions in the importer.
[P3] Lockfiles for the other Gemfile variants were not updated — Gemfile:209-211
`simple-rss` and `ruby-readability` (plus `guess_html_encoding`) were added to `Gemfile_rails4.lock` only. `Gemfile.lock`, which is used with `RAILS3=1`, and `Gemfile_rails_master.lock` still lack them. Frozen or deployment bundles in those modes will fail to resolve, and the `require 'simple-rss'` and `require 'ruby-readability'` calls will raise LoadError.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | low | ✗ | — |
| d5 | high | ✗ | — |
| d7 | medium | ✗ | — |
| d8 | high | ✗ | — |
The only guard in `import` is a scheme regex (`return unless url =~ /^https?\:\/\//`). A link such as `http://host/a b` or one with unencoded non-ASCII characters passes that check, but `URI(url)` in `absolutize_urls` then raises `URI::InvalidURIError`. Nothing rescues the error inside the `rss.items.each` loop in `poll_feed`, so the whole job aborts and later items are not imported. The job also sets `sidekiq_options retry: false`, so it is not retried. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
<h3>Qodo is busy working</h3>
Check back in a few minutes. Qodo's code review agents are on it.
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<img src="https://www.qodo.ai/wp-content/uploads/2026/01/anteater-looking-at-ants-01-transparent-bg-croped-ezgif.com-optimize-1.gif" width="30%">
<h3>PR Summary by Qodo</h3>
Add embeddable discussions with feed-backed topic importing
<code>✨ Enhancement</code> <code>🧪 Tests</code> <code>⚙️ Configuration changes</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Add host-authorized iframe discussions with automatic resizing and loading states.
>• Import and refresh topics from RSS/Atom feeds or remote articles.
>• Persist source mappings and support raw HTML cooking for imported posts.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
sequenceDiagram
actor Reader
participant Host as Host Page
participant Embed as Embed Controller
participant Store as Topic Embed Store
participant Job as Retrieve Job
participant Retriever as Topic Retriever
participant Source as Feed or Article
Reader->>Host: View article
Host->>Embed: Request embedded comments
Embed->>Store: Find source mapping
alt Topic exists
Store-->>Embed: Topic identifier
Embed-->>Host: Discussion highlights
else Topic missing
Embed->>Job: Enqueue retrieval
Job->>Retriever: Retrieve source
Retriever->>Source: Fetch content
Retriever->>Store: Import topic and post
Embed-->>Host: Loading response
end
Host-->>Reader: Render resized iframe
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Sanitize imported HTML before raw storage</b></summary>
<dl>
<dd>
- ➕ Reduces cross-site scripting risk from feeds and remote pages
- ➕ Creates a consistent trust boundary for all imported content
- ➖ May remove article formatting or supported embedded elements
- ➖ Adds normalization work to both creation and revision paths
</dd>
</dl>
</details>
<details>
<summary><b>2. Push articles through webhooks or an API</b></summary>
<dl>
<dd>
- ➕ Imports content immediately instead of hourly polling
- ➕ Avoids repeatedly downloading and parsing complete feeds
- ➖ Requires integration work on every publishing platform
- ➖ Cannot automatically support arbitrary sites with only a feed URL
</dd>
</dl>
</details>
<details>
<summary><b>3. Convert imported articles to normal cooked markup</b></summary>
<dl>
<dd>
- ➕ Reuses the established post rendering and plugin pipeline
- ➕ Avoids introducing a persistent raw HTML cooking mode
- ➖ HTML-to-markup conversion can lose formatting
- ➖ Relative links and complex article structures need additional handling
</dd>
</dl>
</details>
>**Recommendation:** Retain the hybrid feed and on-demand retrieval architecture because it supports both proactive imports and self-healing embed requests. However, imported content should pass through an explicit HTML sanitizer before using raw HTML cooking; webhook ingestion can remain an optional future optimization.
</dd>
</dl>
</details>
<details>
<summary> Files changed (28) <code> +653 / -13 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (14) <code> +407 / -10 </code></summary>
<dl>
<dd>
<details>
<summary>embed.js<code>Create and resize the discussion iframe</code> <code>+27/-0</code></summary>
<br/>
>Create and resize the discussion iframe
>
><pre>
>• Injects the Discourse embed iframe into host pages and updates its height from validated postMessage events.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-6eec5a05dedd579c98aef27a2b9e8d6da54db8db70717080d3fd85940742373e'>app/assets/javascripts/embed.js</a>
</details>
<details>
<summary>embed.css.scss<code>Style embedded discussion highlights</code> <code>+69/-0</code></summary>
<br/>
>Style embedded discussion highlights
>
><pre>
>• Defines the standalone embed presentation for headers, posts, authors, dates, logos, and discussion links.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-ddce204d6e3cc8be078ee40afb51270cbde2bc26cbb766b13e0b39be014e375b'>app/assets/stylesheets/embed.css.scss</a>
</details>
<details>
<summary>embed_controller.rb<code>Serve authorized embedded discussion highlights</code> <code>+34/-0</code></summary>
<br/>
>Serve authorized embedded discussion highlights
>
><pre>
>• Adds the embed endpoint, validates the configured referrer host, permits framing, and returns either the best five posts or a loading page while retrieval is queued.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-595b525906799e0daab45625514da7ffa4536c3091aee28f712120deaeec4490'>app/controllers/embed_controller.rb</a>
</details>
<details>
<summary>retrieve_topic.rb<code>Retrieve missing embedded topics asynchronously</code> <code>+24/-0</code></summary>
<br/>
>Retrieve missing embedded topics asynchronously
>
><pre>
>• Adds a background job that resolves the requesting user and invokes TopicRetriever, bypassing throttling for staff users.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-2eed3d2eed8d469b20e07110112792e1dd119eb39c9a393ffd6ad20ddc0e8bf7'>app/jobs/regular/retrieve_topic.rb</a>
</details>
<details>
<summary>poll_feed.rb<code>Import configured feeds every hour</code> <code>+41/-0</code></summary>
<br/>
>Import configured feeds every hour
>
><pre>
>• Adds an hourly job that parses a configured RSS/Atom feed and imports each item under the configured Discourse user.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-f4e338f0abee3cc5a39a52b79cbb582288322c59d8fa4ece454e3685da910595'>app/jobs/scheduled/poll_feed.rb</a>
</details>
<details>
<summary>post.rb<code>Support raw HTML post cooking</code> <code>+9/-0</code></summary>
<br/>
>Support raw HTML post cooking
>
><pre>
>• Introduces regular and raw HTML cooking modes. Imported posts using raw HTML bypass the normal post cooking pipeline.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-fd0046e2ea37f7ce3e91c417c57233c4b71a3324c477b5070196305ba363835c'>app/models/post.rb</a>
</details>
<details>
<summary>topic_embed.rb<code>Map external articles to imported topics</code> <code>+82/-0</code></summary>
<br/>
>Map external articles to imported topics
>
><pre>
>• Adds creation and revision of source-backed topics, content hash change detection, remote readability extraction, and relative URL normalization. Each source URL is associated with its topic and first post.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-a9aa56fcefb13804a057905bdd06a402290431de865469884df64a9585b4206e'>app/models/topic_embed.rb</a>
</details>
<details>
<summary>best.html.erb<code>Render embedded discussion highlights</code> <code>+30/-0</code></summary>
<br/>
>Render embedded discussion highlights
>
><pre>
>• Displays up to five selected posts with author details, dates, forum branding, and links to start or continue the discussion.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-8fca7a508540685561933435e645ee60f67f7268fd073cdad3e0d6ae437e7a1b'>app/views/embed/best.html.erb</a>
</details>
<details>
<summary>loading.html.erb<code>Render asynchronous import loading state</code> <code>+12/-0</code></summary>
<br/>
>Render asynchronous import loading state
>
><pre>
>• Shows a branded loading message and reloads after 30 seconds while the source article is imported.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-4feca7467a68f435c62d2a5d29e3f209342f29056f97cf5ec7422aac7369fc94'>app/views/embed/loading.html.erb</a>
</details>
<details>
<summary>embed.html.erb<code>Add standalone iframe layout</code> <code>+20/-0</code></summary>
<br/>
>Add standalone iframe layout
>
><pre>
>• Loads the embed stylesheet and reports the rendered body height to the referring parent page through postMessage.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-bd72bcdfa55a0afa2b9c8173e7666d9551c71355111a981a81d0ca80ff9dfa0c'>app/views/layouts/embed.html.erb</a>
</details>
<details>
<summary>post_creator.rb<code>Apply cooking mode during post creation</code> <code>+1/-0</code></summary>
<br/>
>Apply cooking mode during post creation
>
><pre>
>• Allows callers such as TopicEmbed to assign a post's cook method from PostCreator options.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-d924ad6f9d70fcd482109a4dbc011ad16908562f833282f1fe31955df20d31cc'>lib/post_creator.rb</a>
</details>
<details>
<summary>post_revisor.rb<code>Allow revisions to skip model validation</code> <code>+2/-2</code></summary>
<br/>
>Allow revisions to skip model validation
>
><pre>
>• Honors the skip_validations revision option when saving posts, enabling imported article content to be refreshed through PostRevisor.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-b46267c4a3d1637d146d74fec628dc6997f1bb58e580bb4eaa03de66a7947bf1'>lib/post_revisor.rb</a>
</details>
<details>
<summary>disqus.thor<code>Import Disqus source articles as embedded topics</code> <code>+1/-8</code></summary>
<br/>
>Import Disqus source articles as embedded topics
>
><pre>
>• Replaces permalink-only topic creation with remote article extraction through TopicEmbed. The importer no longer accepts or assigns a category option.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-3477d4318ae6e535deba4524cd70fa98134ce280861bfe9fdff0dc0d6bffdcda'>lib/tasks/disqus.thor</a>
</details>
<details>
<summary>topic_retriever.rb<code>Coordinate throttled source retrieval</code> <code>+55/-0</code></summary>
<br/>
>Coordinate throttled source retrieval
>
><pre>
>• Validates source hosts, throttles repeated requests through Redis, checks configured feeds first, and falls back to remote article extraction.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-9673cf0c0ab86eae9fb20c50f479aca5807c92d698e5f9d2e24f29a26d673c1f'>lib/topic_retriever.rb</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (1) <code> +2 / -2 </code></summary>
<dl>
<dd>
<details>
<summary>20131210181901_migrate_word_counts.rb<code>Normalize word-count migration whitespace</code> <code>+2/-2</code></summary>
<br/>
>Normalize word-count migration whitespace
>
><pre>
>• Removes trailing whitespace without changing migration behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-70e8c8a7990aaa044d98d1f008c7e4b6a29682bcac65539a17f64c99f8ed81fa'>db/migrate/20131210181901_migrate_word_counts.rb</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (4) <code> +192 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>topic_retriever_spec.rb<code>Test host validation and retrieval throttling</code> <code>+46/-0</code></summary>
<br/>
>Test host validation and retrieval throttling
>
><pre>
>• Covers missing, mismatched, and malformed hosts along with recent-retrieval suppression for valid sources.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-b8e644675794d0f9bac60dcd8981c4643cbf7dc78d3fb1a583adee24cc13105b'>spec/components/topic_retriever_spec.rb</a>
</details>
<details>
<summary>embed_controller_spec.rb<code>Test embed endpoint authorization and lookup</code> <code>+58/-0</code></summary>
<br/>
>Test embed endpoint authorization and lookup
>
><pre>
>• Covers required URLs, configured referrers, framing headers, existing-topic rendering, and missing-topic retrieval behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-ae3cad89fa5c6a2640229505997ffa6da382b6afdfb7b62c24831abd9a7c48d4'>spec/controllers/embed_controller_spec.rb</a>
</details>
<details>
<summary>poll_feed_spec.rb<code>Test feed polling prerequisites</code> <code>+40/-0</code></summary>
<br/>
>Test feed polling prerequisites
>
><pre>
>• Verifies polling only runs when enabled and supplied with both a feed URL and an importing username.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-0c49744338584acdb9e6ce8682057198f754f5dd39665cf1915fcf437e183f57'>spec/jobs/poll_feed_spec.rb</a>
</details>
<details>
<summary>topic_embed_spec.rb<code>Test external topic import behavior</code> <code>+48/-0</code></summary>
<br/>
>Test external topic import behavior
>
><pre>
>• Covers associations, validations, malformed URLs, raw HTML cooking, relative URL conversion, mapping creation, and content updates.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-02a8c03adb3939df5cc5c9ae225f5b4b2a9ff9e5f5246949b37c7af2a6ffb293'>spec/models/topic_embed_spec.rb</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Documentation (2) <code> +14 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>client.en.yml<code>Label the embedding settings section</code> <code>+1/-0</code></summary>
<br/>
>Label the embedding settings section
>
><pre>
>• Adds the English client-side title for the new embedding administration category.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-d311cd526428b83a1ebb9ed9b457fb210800cc5f0e8188af7de7b5ce86aa5315'>config/locales/client.en.yml</a>
</details>
<details>
<summary>server.en.yml<code>Add embedding messages and setting descriptions</code> <code>+13/-0</code></summary>
<br/>
>Add embedding messages and setting descriptions
>
><pre>
>• Defines English embed interface text and administrator descriptions for host authorization, feed polling, and import ownership.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-333c4c8cacc2f84633d4894f2aaddb130a6d74f42dd63199462b3d66278f6ce8'>config/locales/server.en.yml</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Other (7) <code> +38 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>Gemfile<code>Add feed parsing and article extraction dependencies</code> <code>+4/-0</code></summary>
<br/>
>Add feed parsing and article extraction dependencies
>
><pre>
>• Adds ruby-readability for extracting remote article content and simple-rss for parsing RSS/Atom feeds.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-d09ea66f8227784ff4393d88a19836f321c915ae10031d16c93d67e6283ab55f'>Gemfile</a>
</details>
<details>
<summary>Gemfile_rails4.lock<code>Lock embedding and feed import dependencies</code> <code>+7/-0</code></summary>
<br/>
>Lock embedding and feed import dependencies
>
><pre>
>• Records ruby-readability, simple-rss, guess_html_encoding, and their dependency relationships for the Rails 4 bundle.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-26d8b13e2ff7b19d798cad42bab91cc9b142a0c0fa252eaaae7c5cb903765030'>Gemfile_rails4.lock</a>
</details>
<details>
<summary>routes.rb<code>Expose the embed highlights endpoint</code> <code>+2/-0</code></summary>
<br/>
>Expose the embed highlights endpoint
>
><pre>
>• Routes GET requests for embed/best to the new embed controller action.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-959bc9abc46a55332bb64d5155a79323afa75a50ec1a2137ddd22d926f62c6c5'>config/routes.rb</a>
</details>
<details>
<summary>site_settings.yml<code>Configure embedding and feed imports</code> <code>+6/-0</code></summary>
<br/>
>Configure embedding and feed imports
>
><pre>
>• Adds settings for the authorized embedding host, feed polling toggle and URL, and the username assigned to imported topics.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-bff2842c9891df212adcbe8eb22a4a17c9644c676260a0cfa6e7a3953852c5e8'>config/site_settings.yml</a>
</details>
<details>
<summary>20131217174004_create_topic_embeds.rb<code>Create external topic mapping storage</code> <code>+13/-0</code></summary>
<br/>
>Create external topic mapping storage
>
><pre>
>• Creates topic_embeds with topic, post, source URL, and content hash fields. A unique URL index prevents duplicate source mappings.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-42edef46a1f67c231576aa5cb0bb391fb528f6270288c52f98ed1b506640f7ef'>db/migrate/20131217174004_create_topic_embeds.rb</a>
</details>
<details>
<summary>20131219203905_add_cook_method_to_posts.rb<code>Persist each post cooking method</code> <code>+5/-0</code></summary>
<br/>
>Persist each post cooking method
>
><pre>
>• Adds a required cook_method column to posts with regular cooking as the default.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-ce8c019c559056989d371cec6bcbd9573208faebc29045c634d8dd31f66decc8'>db/migrate/20131219203905_add_cook_method_to_posts.rb</a>
</details>
<details>
<summary>20131223171005_create_top_topics.rb<code>Make top-topic table creation replace existing tables</code> <code>+1/-1</code></summary>
<br/>
>Make top-topic table creation replace existing tables
>
><pre>
>• Adds the force option when creating top_topics, making the migration recreate an existing table.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-ab047d416a5a64c08a187b2adb90e59a1b1b531d596099126e9e8186e3985e75'>db/migrate/20131223171005_create_top_topics.rb</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (8)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Other sites can frame cached comments <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>EmbedController#best</i></b> enables anonymous caching even though <b><i>ensure_embeddable</i></b> authorizes each
>request from its referer host. After an allowed page warms a URL, the anonymous-cache middleware
>serves that response to another origin before the controller filter runs, including the permissive
>framing header.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/controllers/embed_controller.rb[19]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-595b525906799e0daab45625514da7ffa4536c3091aee28f712120deaeec4490R19-R19)</code>
>
>```diff
>+ discourse_expires_in 1.minute
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The new controller validates <b><i>request.referer</i></b>, sets <b><i>X-Frame-Options</i></b>, and then enables the
>anonymous cache. That middleware keys entries only by request host and URI and returns a hit without
>invoking the Rails application, so no referer validation occurs on cached requests.
></pre>
>
> <code>[app/controllers/embed_controller.rb[19-30]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/controllers/embed_controller.rb/#L19-L30)</code>
> <code>[app/controllers/application_controller.rb[163-171]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/controllers/application_controller.rb/#L163-L171)</code>
> <code>[lib/middleware/anonymous_cache.rb[13-15]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/lib/middleware/anonymous_cache.rb/#L13-L15)</code>
> <code>[lib/middleware/anonymous_cache.rb[29-39]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/lib/middleware/anonymous_cache.rb/#L29-L39)</code>
> <code>[lib/middleware/anonymous_cache.rb[79-85]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/lib/middleware/anonymous_cache.rb/#L79-L85)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The anonymous embed response cache is keyed without the referer, so cached responses bypass the controller's embedding-host validation and can be framed by unauthorized sites.
>
>## Fix Focus Areas
>- app/controllers/embed_controller.rb[19-30]
>- lib/middleware/anonymous_cache.rb[13-15]
>- lib/middleware/anonymous_cache.rb[79-85]
>
>## Recommended Fix
>Do not enable the shared anonymous cache for this referer-authorized endpoint. If caching is required, redesign it so authorization is performed before every cache hit and the validated embedding origin participates in cache isolation.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. Imported feed content runs as forum code <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TopicEmbed.import</i></b> creates imported posts with <b><i>cook_method: raw_html</i></b>, causing <b><i>Post#cook</i></b> to
>return externally supplied feed or remote-article markup unchanged instead of passing it through
>normal cooking and sanitization. Active markup and the interpolated source URL can then reach both
>topic and <b><i>embed/best</i></b> rendering as trusted HTML, including execution in the forum-origin iframe.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/models/topic_embed.rb[22]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-a9aa56fcefb13804a057905bdd06a402290431de865469884df64a9585b4206eR22-R22)</code>
>
>```diff
>+ creator = PostCreator.new(user, title: title, raw: absolutize_urls(url, contents), skip_validations: true, cook_method: Post.cook_methods[:raw_html])
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The feed poller passes decoded, externally controlled content directly to <b><i>TopicEmbed.import</i></b>, which
>explicitly selects the raw-HTML cooking path; the corresponding <b><i>Post#cook</i></b> branch returns <b><i>raw</i></b>
>unchanged. Both normal topics and the embed view render the resulting cooked value as trusted HTML,
>with <b><i>embed/best</i></b> explicitly marking it safe, while <b><i>absolutize_urls</i></b> only rewrites selected links
>and images and does not sanitize the fragment.
></pre>
>
> <code>[app/jobs/scheduled/poll_feed.rb[31-36]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/scheduled/poll_feed.rb/#L31-L36)</code>
> <code>[app/models/topic_embed.rb[10-23]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L10-L23)</code>
> <code>[app/models/post.rb[130-136]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/post.rb/#L130-L136)</code>
> <code>[lib/pretty_text.rb[165-172]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/lib/pretty_text.rb/#L165-L172)</code>
> <code>[app/views/topics/show.html.erb[6-14]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/views/topics/show.html.erb/#L6-L14)</code>
> <code>[app/views/embed/best.html.erb[11-21]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/views/embed/best.html.erb/#L11-L21)</code>
> <code>[app/models/topic_embed.rb[10-22]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L10-L22)</code>
> <code>[app/models/topic_embed.rb[61-75]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L61-L75)</code>
> <code>[app/views/embed/best.html.erb[11-22]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/views/embed/best.html.erb/#L11-L22)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Imported RSS and remote-article HTML bypasses Discourse's normal post sanitization because it is stored using the raw-HTML cooking method and later rendered as trusted HTML on topic and embed pages. The imported-source URL is also interpolated into that trusted fragment.
>
>## Fix Focus Areas
>- app/models/topic_embed.rb[10-23]
>- app/models/post.rb[130-136]
>- app/jobs/scheduled/poll_feed.rb[31-36]
>- app/views/embed/best.html.erb[11-22]
>
>## Recommended Fix
>Sanitize imported content with the approved HTML policy or an explicit allowlist before assigning it to a raw-HTML post, or route it through the normal cooking pipeline. Preserve required relative-URL normalization while removing scripts, event-handler attributes, unsafe URL schemes, and other executable markup; construct the imported-source link with escaped attributes rather than string interpolation. Add coverage proving that script tags, event attributes, and crafted source URLs cannot survive post creation or revision.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 3. Embedded frames never resize on articles <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The embed layout passes the complete <b><i>request.referer</i></b> URL to <b><i>parent.postMessage</i></b> as its target
>origin instead of passing a serialized origin. Accepted referrers normally include an article path,
>so the browser rejects the resize delivery and the parent listener never updates the iframe height.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/views/layouts/embed.html.erb[R9-12]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-bd72bcdfa55a0afa2b9c8173e7666d9551c71355111a981a81d0ca80ff9dfa0cR9-R12)</code>
>
>```diff
>+ if (parent) {
>+ // Send a post message with our loaded height
>+ parent.postMessage({type: 'discourse-resize', height: document['body'].offsetHeight}, '<%= request.referer %>');
>+ }
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The controller validates only the referrer's host and supplies the unmodified referrer to the
>layout. The only parent-side resize implementation depends on receipt of this message, and the
>controller spec demonstrates an accepted referrer with a path.
></pre>
>
> <code>[app/controllers/embed_controller.rb[24-30]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/controllers/embed_controller.rb/#L24-L30)</code>
> <code>[app/views/layouts/embed.html.erb[7-14]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/views/layouts/embed.html.erb/#L7-L14)</code>
> <code>[app/assets/javascripts/embed.js[15-25]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/assets/javascripts/embed.js/#L15-L25)</code>
> <code>[spec/controllers/embed_controller_spec.rb[5-6]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/spec/controllers/embed_controller_spec.rb/#L5-L6)</code>
> <code>[spec/controllers/embed_controller_spec.rb[29-45]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/spec/controllers/embed_controller_spec.rb/#L29-L45)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The resize message uses the full referring page URL as `postMessage`'s target origin. A target origin must contain only scheme, host, and optional port, so ordinary referring URLs with paths prevent delivery.
>
>## Fix Focus Areas
>- app/views/layouts/embed.html.erb[7-14]
>- app/controllers/embed_controller.rb[24-30]
>- app/assets/javascripts/embed.js[15-22]
>
>## Recommended Fix
>Parse the already validated referrer server-side and pass only its serialized origin (`scheme://host[:port]`) as the `postMessage` target. Keep the strict host validation and verify that the parent receives the resize message for a referrer containing an article path.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View high (1)</strong></ins></summary><br/>
<details>
<summary> 4. The embedding controller spec cannot pass <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The new no-embed controller example expects <b><i>TopicRetriever.new</i></b> and <b><i>retrieve</i></b> to be called, but
><b><i>EmbedController#best</i></b> instead enqueues <b><i>:retrieve_topic</i></b>. When this example executes its request,
>its required mock invocation is never made, so the test fails even though the asynchronous
>implementation is used.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/controllers/embed_controller.rb[R14-16]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-595b525906799e0daab45625514da7ffa4536c3091aee28f712120deaeec4490R14-R16)</code>
>
>```diff
>+ else
>+ Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url)
>+ render 'loading'
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The controller's no-embed branch contains only job enqueueing, while the newly added example sets
>mandatory expectations on a different synchronous call chain.
></pre>
>
> <code>[app/controllers/embed_controller.rb[8-19]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/controllers/embed_controller.rb/#L8-L19)</code>
> <code>[spec/controllers/embed_controller_spec.rb[40-46]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/spec/controllers/embed_controller_spec.rb/#L40-L46)</code>
> <code>[app/jobs/regular/retrieve_topic.rb[9-18]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/regular/retrieve_topic.rb/#L9-L18)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The controller's newly added asynchronous retrieval implementation does not match the newly added controller spec, which still expects synchronous `TopicRetriever` construction and invocation.
>
>## Fix Focus Areas
>- app/controllers/embed_controller.rb[8-19]
>- spec/controllers/embed_controller_spec.rb[40-46]
>- app/jobs/regular/retrieve_topic.rb[9-18]
>
>## Recommended Fix
>Update the controller spec to expect `Jobs.enqueue(:retrieve_topic, user_id: ..., embed_url: ...)`, or change the controller deliberately back to the synchronous contract. Keep a separate job spec to verify that the enqueued job invokes `TopicRetriever`.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 5. One empty feed item stops every import <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>PollFeed#poll_feed</i></b> calls <b><i>scrub</i></b> unconditionally on each item's <b><i>content</i></b> value. An item without
>that field raises before <b><i>TopicEmbed.import</i></b>, aborting the remaining feed items while this scheduled
>job has retries disabled.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/jobs/scheduled/poll_feed.rb[R31-35]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-f4e338f0abee3cc5a39a52b79cbb582288322c59d8fa4ece454e3685da910595R31-R35)</code>
>
>```diff
>+ rss.items.each do |i|
>+ url = i.link
>+ url = i.id if url.blank? || url !~ /^https?\:\/\//
>+
>+ content = CGI.unescapeHTML(i.content.scrub)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The polling loop performs no presence check or per-item error handling before invoking
><b><i>i.content.scrub</i></b>. The job explicitly disables retries, so an exception prevents all subsequent
>entries in that run from being imported.
></pre>
>
> <code>[app/jobs/scheduled/poll_feed.rb[10-12]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/scheduled/poll_feed.rb/#L10-L12)</code>
> <code>[app/jobs/scheduled/poll_feed.rb[24-37]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/scheduled/poll_feed.rb/#L24-L37)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Feed polling dereferences optional item content without validation, allowing one incomplete item to abort the entire non-retrying polling run.
>
>## Fix Focus Areas
>- app/jobs/scheduled/poll_feed.rb[24-37]
>
>## Recommended Fix
>Validate each item's URL, title, and content before processing it, use an appropriate description fallback where supported, and skip invalid items without terminating the loop. Record enough context to identify skipped entries and add tests for missing content and missing links.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 6. Disqus imports lose category selection <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>Disqus#import</i></b> removes the declared category option and replaces category-aware post creation with
><b><i>TopicEmbed.import_remote</i></b>, which receives no category. Existing importer invocations can no longer
>use <b><i>--category</i></b> or <b><i>-c</i></b>, and administrators lose the ability to place imported discussions in their
>selected category.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[lib/tasks/disqus.thor[117]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-3477d4318ae6e535deba4524cd70fa98134ce280861bfe9fdff0dc0d6bffdcdaL117-L117)</code>
>
>```diff
>- method_option :category, aliases: '-c', desc: "The category to post in"
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The diff deletes both the public category option and the lookup that produced <b><i>category_id</i></b>. The
>replacement call only supplies the user, URL, and title, while <b><i>TopicEmbed.import</i></b> constructs
><b><i>PostCreator</i></b> without any category argument.
></pre>
>
> <code>[lib/tasks/disqus.thor[114-148]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/lib/tasks/disqus.thor/#L114-L148)</code>
> <code>[app/models/topic_embed.rb[10-23]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L10-L23)</code>
> <code>[app/models/topic_embed.rb[44-53]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L44-L53)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The Disqus importer removes its category command option and no longer passes a selected category through the new remote-import path.
>
>## Fix Focus Areas
>- lib/tasks/disqus.thor[114-153]
>- app/models/topic_embed.rb[10-22]
>- app/models/topic_embed.rb[44-53]
>
>## Recommended Fix
>Restore the category option and lookup, extend `TopicEmbed.import_remote` and `TopicEmbed.import` to accept the selected category, and pass it to `PostCreator`. Preserve the previous behavior for both the long and short command options and add importer coverage.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 7. Other sites can resize embedded frames <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>postMessageReceived</i></b> accepts an event whenever its origin is merely a substring of <b><i>discourseUrl</i></b>,
>rather than requiring it to equal the Discourse origin. A separately controlled origin that is a
>prefix of the configured URL can send a <b><i>discourse-resize</i></b> payload and set the embedded iframe to an
>arbitrary height.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/assets/javascripts/embed.js[R15-21]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-6eec5a05dedd579c98aef27a2b9e8d6da54db8db70717080d3fd85940742373eR15-R21)</code>
>
>```diff
>+ function postMessageReceived(e) {
>+ if (!e) { return; }
>+ if (discourseUrl.indexOf(e.origin) === -1) { return; }
>+
>+ if (e.data) {
>+ if (e.data.type === 'discourse-resize' && e.data.height) {
>+ iframe.height = e.data.height + "px";
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The listener changes the iframe height solely based on a message payload after its substring
>authorization check; it does not verify that the message comes from the iframe it created or from an
>exact Discourse origin.
></pre>
>
> <code>[app/assets/javascripts/embed.js[5-12]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/assets/javascripts/embed.js/#L5-L12)</code>
> <code>[app/assets/javascripts/embed.js[15-25]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/assets/javascripts/embed.js/#L15-L25)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The parent embed script authorizes resize messages through substring matching. This treats origins that happen to be textual prefixes of the configured Discourse URL as trusted senders.
>
>## Fix Focus Areas
>- app/assets/javascripts/embed.js[15-25]
>
>## Recommended Fix
>Parse `discourseUrl` once and compare `e.origin` for exact equality with its origin. Retain the existing message type check after authenticating the sender.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View medium (1)</strong></ins></summary><br/>
<details>
<summary> 8. One bad feed item blocks later imports <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TopicEmbed.import</i></b> accepts any HTTP-prefixed string but subsequently calls <b><i>URI(url)</i></b> without
>handling an invalid URI. A malformed link or fallback item ID causes that exception to escape
><b><i>PollFeed</i></b>'s item loop, preventing all subsequent items from importing and leaving the no-retry
>scheduled run failed.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[app/models/topic_embed.rb[R56-61]](https://github.com/drape-io/crbench-qodo-2026-09/pull/33/files#diff-a9aa56fcefb13804a057905bdd06a402290431de865469884df64a9585b4206eR56-R61)</code>
>
>```diff
>+ def self.absolutize_urls(url, contents)
>+ uri = URI(url)
>+ prefix = "#{uri.scheme}://#{uri.host}"
>+ prefix << ":#{uri.port}" if uri.port != 80 && uri.port != 443
>+
>+ fragment = Nokogiri::HTML.fragment(contents)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The poller can pass either <b><i>link</i></b> or <b><i>id</i></b> from each feed item into the importer, while the importer
>only performs a prefix check before parsing the URL. There is no rescue around the loop and retries
>are explicitly disabled.
></pre>
>
> <code>[app/jobs/scheduled/poll_feed.rb[10-12]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/scheduled/poll_feed.rb/#L10-L12)</code>
> <code>[app/jobs/scheduled/poll_feed.rb[29-37]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/jobs/scheduled/poll_feed.rb/#L29-L37)</code>
> <code>[app/models/topic_embed.rb[10-13]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L10-L13)</code>
> <code>[app/models/topic_embed.rb[55-75]](https://github.com/drape-io/crbench-qodo-2026-09/blob/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d/app/models/topic_embed.rb/#L55-L75)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>A feed item URL is checked only for an HTTP prefix before it reaches `URI(url)`, which can raise for malformed URLs. The per-feed loop has no item-level error isolation and job retries are disabled.
>
>## Fix Focus Areas
>- app/models/topic_embed.rb[10-13]
>- app/models/topic_embed.rb[55-75]
>- app/jobs/scheduled/poll_feed.rb[29-37]
>
>## Recommended Fix
>Parse and validate each item URL before importing it, returning or logging a skipped item when parsing fails. Add item-level exception handling around import so a malformed item cannot abort processing of later feed entries.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>🧠 Deep</code>: This broad, behavior-heavy change spans embedding security, remote content fetching, background jobs, persistence, migrations, rendering, and multiple integration paths, creating many independent opportunities for subtle defects.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/7f9afd0d35c434b5290c51a5f42b3cc593c2aa2d -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>