GLM-5.3 Flash · 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 Opus 5.5.
- Gold bugs found
- 5 of 30
- Comments published
- 11
- Comments matching a bug
- 5
- Comments not matching
- 6
- Cost of this PR
- $0.261
Published comments (11)
Imported HTML is persisted unsanitized, enabling stored XSS — Untrusted HTML from the feed or article lands in post content as-is, so script and event-handler payloads execute on the forum origin, and the `embed.imported_from` footer interpolates `#{url}` unescaped. Sanitize the fragment with a Nokogiri tag/attribute whitelist before persisting and escape the URL.
Invalid `<%- end if %>` causes syntax error compiling embed/best template — Every `embed/best` request 500s once a topic exists because the compiled template has an unmatched `if`, and controller specs don't render views, so tests stay green. Replace `<%- end if %>` with `<%- end %>`.
Unthrottled enqueue of RetrieveTopic jobs for unknown embed URLs — Since the 60-second throttle lives inside `TopicRetriever#retrieved_recently?`, every unauthenticated request — and each open tab's 30-second reload — enqueues a `Jobs.enqueue` call and runs `topic_id_for_embed` forever when the article can't be imported. Check the throttle before enqueueing or dedupe pending retrievals per embed_url.
NOT NULL column with default rewrites hot posts table under exclusive lock — Adding `cook_method` with a default on PostgreSQL < 11 rewrites every `posts` row under an ACCESS EXCLUSIVE lock, blocking all reads and writes to the site's hottest table for the deploy. Add it nullable, backfill in batches, then apply the NOT NULL constraint.
Non-atomic SETNX+EXPIRE can leave throttle key with no TTL — If the worker dies between `$redis.setnx` and `$redis.expire`, the key `retrieved:<embed_url>` persists forever and that embed URL is never imported again, leaving the widget stuck on 'Loading Discussion...'. Set the TTL atomically with `SET key value EX 60 NX` or a MULTI/EXEC pipeline.
String#scrub unavailable on Ruby 2.0 and i.content may be missing — `i.content.scrub` raises NoMethodError on the pinned Ruby 2.0 (`String#scrub` arrived in 2.1) and when feeds carry only `description`, so with `retry: false` the hourly job dies and imports never work. Use `(i.content || i.description).to_s` instead.
feed_key is dead code; feed modification check never wired into polling — Nothing ever calls `PollFeed#feed_key`, so the feed-modification check was never wired in and the hourly job unconditionally re-imports the whole feed. Either skip re-polling when the digest is unchanged or remove `feed_key` and the now-unused `require 'digest/sha1'`.
Test for feed_polling_enabled? passes even without the guard due to other defaults — This test still passes if the `SiteSetting.feed_polling_enabled?` guard were removed, because unstubbed `feed_polling_url` and `embed_by_username` default to '' and short-circuit execution. Stub both settings so execution actually reaches the condition under test.
Embed layout leaks full referer URL into cacheable response body — The full `request.referer`, including path and query string that can carry tokens or session ids, is echoed into responses `EmbedController#best` marks cacheable, so a shared cache can serve one embedder's URL to another. Send only the referer origin as the postMessage targetOrigin, or skip caching these responses.
Origin check uses substring containment, allowing forged origins — `discourseUrl.indexOf(e.origin)` accepts any origin string contained anywhere in `discourseUrl`, letting a forged frame send resize messages that control the embed iframe's height. Compare origins strictly, e.g. a prefix match, rather than with `indexOf` containment.
Test doesn't enable feed_polling_enabled? so feed_polling_url check is never reached — `Jobs::PollFeed#execute` short-circuits at `SiteSetting.feed_polling_enabled?` (false by default in site_settings.yml) before reading `feed_polling_url`, so this test would pass even without the guard it claims to cover. Stub `feed_polling_enabled?` to true and `embed_by_username` present so the `feed_polling_url` condition is actually exercised. **Also found in:** - `spec/jobs/poll_feed_spec.rb:24-28`