Claude Opus 5.5 · Balanced
enhance-embed-url-handling-and-validation-system-discourse-cursor
Discourse · Ruby · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 4 of 12
- Comments published
- 7
- Comments matching a bug
- 4
- Comments not matching
- 3
- Cost of this PR
- $1.099
Published comments (7)
Raw HTML posts skip sanitization, allowing stored XSS — Feed content (unescaped in `poll_feed`) and remote pages reach `cooked` unsanitized, and `best.html.erb` renders it via `raw post.cooked`, so a compromised source can inject scripts. Sanitize `raw` with a whitelist before storing or while cooking.
Unescaped embed URL interpolated into raw HTML link allows markup injection — `url` comes from the `embed_url` param or the feed, and the post renders raw, so a `'` or `<` can break out of the attribute and inject markup. Escape `url` with `ERB::Util.html_escape` before interpolating.
Feed import crashes on items with no `content` field — SimpleRSS returns nil `content` for description-only RSS 2.0 items, so `i.content.scrub` raises `NoMethodError` and aborts the import, including `TopicRetriever`'s synchronous call. Fall back to `i.description` and skip items where both are nil.
Stray `if` after `end` makes header buttons conditional on the next output — Ruby treats the next output expression as an `if` modifier on the whole block, so header buttons render only when the logo link's return value is truthy. Replace `<%- end if %>` with `<%- end %>`.
Inline RSS feed poll on every unknown embed URL lacks a global throttle — The throttle is per-URL and the referer is spoofable, so distinct paths can trigger unbounded feed polls and outbound fetches. Drop the inline `Jobs::PollFeed` call in favor of the hourly poll, or add a global throttle.
absolutize_urls mangles protocol-relative URLs starting with // — Values like `//cdn.example.com/img.png` get rewritten to `http://host/cdn.example.com/img.png`, breaking external links and images. In `absolutize_urls`, skip values starting with `//`.
Substring origin check lets prefix-matching origins send resize messages — `indexOf` is a substring test, so any origin that prefixes `discourseUrl` (e.g. `https://forum.example.co`) can send resize messages. Compare `e.origin` exactly against the origin parsed from `discourseUrl`.