Claude Sonnet 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
- 4 of 12
- Comments published
- 8
- Comments matching a bug
- 4
- Comments not matching
- 4
- Cost of this PR
- $2.306
Published comments (8)
Raw HTML posts skip sanitization in Post#cook, enabling stored XSS — `Post#cook` returns `raw` unsanitized, so HTML from an external feed or fetched page is stored in `cooked` and rendered on the forum's origin, enabling stored XSS against users and staff. Sanitize the HTML with a whitelist-based tool in the raw_html branch of `cook` or in `TopicEmbed.import`.
Adding NOT NULL column with default rewrites large posts table under exclusive lock — On the Postgres versions this app targets, this rewrites the whole `posts` table under an ACCESS EXCLUSIVE lock, blocking all reads and writes during the deploy. Add `cook_method` as nullable, set the default, backfill in batches, then add the `NOT NULL` constraint.
Unescaped URL interpolated into anchor HTML allows HTML injection — A feed-supplied `url` containing `'` or `<` can break out of the `href` attribute and inject HTML or script into the post. Escape `url` with `ERB::Util.html_escape`, or build the anchor with `link_to`, before interpolating it.
Concurrent imports of same URL race and raise RecordNotUnique — The check-then-create on `embed_url` is not atomic, so concurrent imports from `PollFeed` and `RetrieveTopic` both create a topic and the loser hits the unique index with an unhandled `ActiveRecord::RecordNotUnique`. Rescue `ActiveRecord::RecordNotUnique` and return the existing embed's post, or lock on the URL.
NoMethodError on feed items without content aborts the polling loop — `i.content.scrub` raises `NoMethodError` for items lacking `content`, which aborts the `rss.items.each` loop and skips every later item. Fall back with `(i.content || i.description || '')` and skip items with a blank body or `url`.
absolutize_urls corrupts protocol-relative URLs like //cdn.example.com/x.png — Skip values starting with `//` so only genuinely site-relative paths get the prefix.
Origin check uses substring match, allowing spoofed postMessage origins — The `discourseUrl.indexOf(e.origin) === -1` check is a substring match, so any origin that is a prefix of `discourseUrl` passes and can spoof messages. Parse `discourseUrl` into its origin and require `e.origin` to equal it exactly.
feed_polling_url test doesn't enable polling so it can't fail on the URL check — This test never enables `feed_polling_enabled?`, which defaults to false, so `execute` skips `poll_feed` regardless of the URL and the test passes even without the `feed_polling_url.present?` check. Stub `feed_polling_enabled?` to true and set `embed_by_username` so only the missing URL blocks the call. **Also found in:** - `spec/jobs/poll_feed_spec.rb:24-28`