Kimi K3.1 Pro · 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
- 5 of 12
- Comments published
- 15
- Comments matching a bug
- 5
- Comments not matching
- 10
- Cost of this PR
- $4.906
Published comments (15)
Invalid `end if` terminator prevents the embed template from compiling — Compiling this template fails because `end if` is not a valid standalone ERB/Ruby block terminator, preventing `embed/best` from rendering. Replace it with `end`.
Feed-supplied scripts and event handlers are stored unchanged and later rendered by… — Sanitize imported HTML with an allowlist before saving it or before returning it from `Post#cook`.
embed.css is missing from the asset precompile list — Production disables runtime asset compilation, but `embed.css` is absent from `config.assets.precompile`, so this layout references an unavailable stylesheet and can raise an asset-not-precompiled error. Register `embed.css` for precompilation.
Description-only feed items crash polling when content is nil — Valid RSS items that provide only `description` and no `content:encoded` can make `i.content` nil, so `.scrub` raises and aborts the entire polling run. Fall back to `i.description` and handle blank content before scrubbing.
Rolled-back posts pass the presence check and abort embed imports — `PostCreator#create` returns an unsaved Post after a host-spam rollback, so `post.present?` still succeeds and `TopicEmbed.create!` receives `post_id=nil`, raising and aborting the import. Require `post.persisted?` or no creator errors before creating the embed record.
Relative links and image sources are not resolved against the article URL — References such as `href="article.html"` and `src="images/a.png"` remain relative and resolve against Discourse instead of the source article, producing broken links and images. Resolve every relative reference with `URI.join(url, value)` rather than handling only strings beginning with `/`.
Substring origin check permits unauthorized postMessage resizing — A different origin whose serialized origin is a substring of `discourseUrl`—for example `https://example.co` against `https://example.com/`—passes this check and can arbitrarily resize the host page's iframe. Compare `e.origin` with the parsed Discourse origin exactly and validate `e.source`.
Unauthenticated embed requests can enqueue unbounded retrieval work — Every distinct missing `embed_url` queues work before any throttle runs, and varying query strings or fragments bypasses the worker's full-URL key, allowing unauthenticated requests with a forged allowed Referer to grow Sidekiq and outbound-fetch work without bound. Rate-limit this endpoint and atomically deduplicate pending retrieval before enqueueing.
Unbounded remote response reads can exhaust worker memory — `open(url).read` buffers the entire remote response before Readability parses it, so a sufficiently large response from an allowed-host URL can exhaust a worker's memory. Read with a strict byte limit and reject oversized responses before parsing.
Automatic redirects bypass SSRF host validation for embed imports — `TopicRetriever#invalid_host?` validates only the initial URL, while `open(url)` follows HTTP redirects without rechecking the destination, allowing an allowed-host redirect to make the worker fetch internal services. Disable automatic redirects or revalidate the scheme, host, and resolved IP at every hop.
On the PostgreSQL versions targeted here, adding a non-null column with a default rewrites… — Add the column nullable without a default, backfill in batches, then apply the default and NOT NULL constraint separately.
Anonymous embed caching bypasses referer validation — AnonymousCache keys entries only by `HTTP_HOST` and `REQUEST_URI`, so after an allowed request is cached, a request for the same `embed_url` with a missing or hostile Referer receives the cached page without `ensure_embeddable` running. Disable `discourse_expires_in` for this action or vary the cache key by the validated referer.
absolutize_urls drops port 80 or 443 regardless of scheme — Only omit the port when it matches `uri.default_port`.
Disqus root topics lose their original creation timestamps — The new `TopicEmbed.import_remote` call no longer passes `created_at: Date.parse(t[:created_at])`, so Disqus root topics are dated at import time while replies keep their original dates, corrupting thread chronology. Thread the original timestamp through `import_remote` and `TopicEmbed.import` to `PostCreator`.
Disqus import drops the selected category — Preserve the CLI option and pass the resolved category through `TopicEmbed.import` to `PostCreator`.