GPT-6.1 Sol · 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
- 5 of 12
- Comments published
- 10
- Comments matching a bug
- 5
- Comments not matching
- 5
- Cost of this PR
- $2.473
Published comments (10)
Unescaped imported URLs allow HTML injection into posts — Quotes or markup in `url` can inject attributes or elements into imported posts because the prefix check allows them and `raw_html` preserves them. HTML-escape `url` in both the link attribute and text before interpolating it into `I18n.t`.
Unsanitized feed HTML becomes executable content in imported posts — Malicious feed HTML can execute on the forum's origin because `TopicEmbed.import` selects `raw_html` and `Post.cook` bypasses sanitization; `CGI.unescapeHTML` does not remove scripts or event handlers. Sanitize feed content before passing it to `TopicEmbed.import`, including on updates. **Also found in:** - `app/models/post.rb:131-133`
Invalid Ruby in embed template prevents comments from rendering — Rails cannot compile `<%- end if %>`, so the existing-topic branch of `EmbedController.best` fails instead of displaying comments. Replace it with `<%- end %>`.
Concurrent imports can fail on duplicate embed URLs — Concurrent imports can both pass `embed.blank?`, then collide on `embed_url`, raising `ActiveRecord::RecordNotUnique` and aborting a feed run. Rescue the conflict outside the rolled-back transaction and retrieve the winning `TopicEmbed` and post, or serialize imports per URL.
RSS items without content abort the polling run — Description-only RSS items make `i.content.scrub` raise `NoMethodError`, aborting the entire polling run with retries disabled. Fall back to `i.description` and explicitly handle items with neither field before calling `scrub`.
Per-article throttling causes repeated full-feed imports — Each distinct missing `@embed_url` triggers a synchronous full-feed import through `Jobs::PollFeed`, multiplying network requests and database work across article visits. Throttle polling with a shared feed-level key and let individual retrievals reuse the result.
Embedded post dates ignore the active locale — Readers on non-English forums still see English-style dates because `post.created_at.strftime` fixes the ordering and month abbreviation. Use `l` with a locale-defined date format.
Missing embed_url example fails at host validation instead — This test still passes if `params.require(:embed_url)` is removed because `ensure_embeddable` rejects the default blank `embeddable_host` first. Configure an allowed host and matching referer, then assert the intended missing-parameter status rather than any unsuccessful response.
Negative prerequisite tests short-circuit because polling is disabled — These tests can miss regressions because `execute` exits on the default false `feed_polling_enabled?` before checking `feed_polling_url` or `embed_by_username`. Enable polling and make every other prerequisite valid so each example isolates its named requirement.
Protocol-relative links and images are rewritten to the article host — Resolve both link and image URLs against the source URI with `URI.join`, or handle double-slash prefixes separately.