Claude Opus 5.5 · Heavy
enhance-embed-url-handling-and-validation-system-discourse-cursor
Discourse · Ruby · M · 100–299 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 6 of 12
- Comments published
- 12
- Comments matching a bug
- 6
- Comments not matching
- 6
- Cost of this PR
- $3.623
Published comments (12)
Raw HTML posts are returned unsanitized, allowing stored XSS — `PollFeed` stores feed HTML after `CGI.unescapeHTML`, so `<script>`, `on*` handlers or `javascript:` links reach the forum and the embed view through `raw post.cooked`. Run `raw` through a sanitizer, such as the cooked-post whitelist, before returning it.
`Kernel#open` on `SiteSetting.feed_polling_url` allows shell commands — A value starting with `|` spawns a subprocess, so anyone who can change site settings can run commands on the job server. Parse it with `URI.parse`, require an http/https scheme, and fetch with `URI#open` or `Net::HTTP`.
Unescaped URL in 'Imported from' footer allows HTML injection — These raw_html posts render via `raw post.cooked`, so a `url` containing a quote or angle bracket breaks out of the `href` attribute. Escape `url` with `ERB::Util.html_escape` in both the `href` and the link text.
NoMethodError on RSS items without `content:encoded` aborts feed import — Items with only `description` make `i.content` nil, so `.scrub` raises and the rest of the feed isn't imported. Fall back to `i.description` and skip items without content.
Concurrent imports of the same URL raise RecordNotUnique and abort the feed — When hourly `PollFeed` and a `RetrieveTopic` job import the same URL, both see `embed.blank?` and the loser's `TopicEmbed.create!` raises uncaught, stopping the `rss.items.each` loop. Rescue `ActiveRecord::RecordNotUnique` and fall back to the existing embed, or lock on the URL.
Deleted embedded post makes `embed.post` nil and `revise!` raise — `PostRevisor.new(nil).revise!` raises, so every later feed poll for this URL fails. Return early or recreate the topic when `post` is nil.
Each embed miss synchronously polls and re-parses the whole feed — Staff bypass the throttle and each distinct URL has its own throttle key, so every embed miss runs `Jobs::PollFeed` synchronously and refetches the full feed. Look up only the requested item, or rate-limit the full poll with a global key.
Loading page is cached for 1 minute, so its reload can get stale content — The 'loading' page reloads itself after 30 seconds, but `discourse_expires_in 1.minute` caches it too, so the reload may return it instead of the new topic. Set the cache header only when `topic_id` is present.
Origin check uses substring match, so prefix-matching origins pass — With `discourseUrl.indexOf(e.origin)`, an origin like `https://forum.example.co` passes for `https://forum.example.com/` and can send resize messages. Compare `e.origin` exactly against the origin parsed from `discourseUrl`.
raw_html `cook` returns stored `raw` instead of the text passed in — Callers passing new text, such as `p.cook(new_raw, ...)` in lib/tasks/add_topic_to_quotes.rake, get the old `raw` back and store a cooked value that no longer matches. Return `args.first` for raw_html posts.
Protocol-relative URLs are wrongly rewritten as host-relative paths — Values like `//cdn.example.com/a.png` pass the `start_with?('/')` check and become `http://host/cdn.example.com/a.png`, breaking external images and links. Skip values starting with `//` before prefixing.
embed_by_username test passes even without the guard it is meant to test — `feed_polling_enabled?` and `feed_polling_url` default to values that already block `poll_feed`, so deleting the `embed_by_username.present?` guard wouldn't fail this test. Stub both to valid values so only this guard is tested. **Also found in:** - `spec/jobs/poll_feed_spec.rb:18-22` - `spec/jobs/poll_feed_spec.rb:12-16`