DeepSeek V4.1 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 Haiku 5.5.
- Gold bugs found
- 4 of 12
- Comments published
- 12
- Comments matching a bug
- 4
- Comments not matching
- 8
- Cost of this PR
- $1.307
Published comments (12)
Unescaped feed URL interpolated into imported-from HTML footer — The feed-supplied `url` is interpolated into the href with no escaping, and the `^https?:\/\/` gate lets a quote and markup through. Since these posts render raw, build the anchor with an escaped href.
Unescaped referer injected into embed layout script — `request.referer` is only host-checked, so a crafted path breaks out of the script block and runs attacker script on the forum origin with access to its cookies. Emit only the parsed origin, JSON-escaped.
Embed view renders unsanitized raw_html cooked content (XSS) — Feeds can carry markup that bypasses the cooking pipeline via the `cook_method` shortcut, and `TopicEmbed.absolutize_urls` only rewrites links, so scripts execute on the forum origin. Sanitize `post.cooked` before rendering it raw. **Also found in:** - `app/models/post.rb:130-137`
Referer check allows unauthenticated clients to create unlimited topics — The `Referer` header is client-supplied, so any non-browser client can pass the `ensure_embeddable` check and create unbounded topics by randomizing `embed_url` paths. Gate creation on a non-forgeable token or a per-IP rate limit.
nil feed item content raises NoMethodError and aborts polling — Items that only carry `<description>` leave `i.content` nil, so `nil.scrub` raises and aborts the whole poll; with no retries the run is lost. Fall back to `i.description` and skip blank content.
`end if` without a condition causes a SyntaxError in the embed/best template — `end if` with no condition is a SyntaxError, so the template fails to compile on the branch where a topic was found and `/embed/best` raises instead of rendering. Use a plain `end`.
Throttle key can persist without TTL due to non-atomic setnx and expire — A failure between the two calls leaves `retrieved:<url>` without a TTL, so `setnx` never succeeds again and `perform_retrieve` skips that URL forever. Make the set and TTL a single atomic operation.
Remote embed fetch has no timeout and reads unbounded body — A slow or oversized page pins the `retrieve_topic` worker indefinitely or exhausts memory, since `open(url).read` has no timeout and no size cap. Pass explicit timeout options and limit the bytes read.
postMessage target origin is full referer URL, not an origin — Send the parsed origin instead.
Message origin check uses substring match instead of exact origin — A substring match accepts messages from lookalike origins like `https://discourse.example.co`, letting an attacker drive `iframe.height`. Compare `e.origin` exactly against the forum origin and also check `e.source` is the embed iframe.
TopicEmbed.import races on embed_url and raises RecordNotUnique — Two workers can both see `embed.blank?`, and the unique index on `embed_url` makes the loser's `TopicEmbed.create!` raise `RecordNotUnique`, rolling back its just-created topic and post. Rescue the conflict and reuse the existing embed.
Test for feed_polling_enabled? doesn't isolate the enabled flag — `feed_polling_url` and `embed_by_username` stay at their blank defaults, so `poll_feed` is skipped regardless of the enabled flag and the test would pass even without that guard. Make the other two conditions truthy so only the flag prevents the call. **Also found in:** - `spec/jobs/poll_feed_spec.rb:18-22` - `spec/jobs/poll_feed_spec.rb:24-28`