DeepSeek V4.1 Flash · 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
- 3 of 12
- Comments published
- 7
- Comments matching a bug
- 3
- Comments not matching
- 4
- Cost of this PR
- $0.206
Published comments (7)
Raw HTML cook method bypasses sanitization for imported feed content — Because `cook_methods[:raw_html]` returns `raw` untouched, third-party HTML from `TopicEmbed.import` reaches the page unsanitized, letting `<script>` or `onerror` run in the Discourse origin. Sanitize the imported HTML with a tag, attribute, and scheme allowlist before storing it, rather than relying on the cook bypass.
Invalid `end if` in embed/best template causes SyntaxError — ERB compiles the whole view into one method, so `<%- end if %>` leaves it unbalanced and every render of `embed/best` raises a SyntaxError, including the empty-topic branch. Change it to `<%- end %>`.
nil feed content raises NoMethodError and aborts the poll — `i.content` is nil for items that only carry `<description>`, so `nil.scrub` raises NoMethodError, aborts the `each` loop, and skips all remaining items with no retry. Read the body defensively from `i.content` or `i.description` and skip blank items.
add_column with default rewrites posts and blocks access on PostgreSQL — On PostgreSQL before 11 the default and NOT NULL force a full table rewrite under an ACCESS EXCLUSIVE lock, blocking all reads and writes to posts for the whole migration. Add `cook_method` nullable without a default, backfill in batches, then set the default and NOT NULL afterward.
Unguarded embed.post causes NoMethodError for orphaned topic embeds — A `topic_embeds` row outlives hard-deleted posts, so `PostRevisor.new(nil)` raises NoMethodError, aborting the `rss.items` loop in `Jobs::PollFeed` and leaving all later items unimported. Return early when `post.blank?` or delete the stale embed.
Feed poll runs inline for every distinct embed URL retrieval — `perform_retrieve` pays the full O(feed items) poll inline for every distinct `embed_url`, since the `retrieved:` throttle is per URL and `feed_key` is unused. Enqueue the poll as its own throttled job instead of running it inline per request.
Remote embed fetch lacks timeouts and size cap — A slow remote response blocks the worker indefinitely and an oversized body is loaded entirely into memory by `open(url).read`, reachable from the embed endpoint. Pass explicit `open_timeout` and `read_timeout` and cap the bytes read.