DeepSeek V4 Pro · 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
- 6 of 30
- Comments published
- 12
- Comments matching a bug
- 6
- Comments not matching
- 6
- Cost of this PR
- $1.924
Published comments (12)
Imported embed content is stored with raw HTML cook method, bypassing sanitization — Third-party feed or embed content executes in the Discourse-origin iframe because `cook_method: raw_html` bypasses `PrettyText.cook` sanitization and `best.html.erb` renders with `raw`. Route the import through the regular cooking pipeline or sanitize the HTML before storage.
Unescaped URL in imported_from link allows HTML injection — The URL is interpolated into raw HTML without escaping, and raw cooking plus `raw` rendering means a quote or angle bracket in the URL can inject markup or script. Escape the URL with `ERB::Util.html_escape` for both the attribute and link text.
PollFeed raises NoMethodError when feed item has no content element — Standard RSS feeds using `<description>` leave `i.content` nil, so the exception aborts the whole `poll_feed` loop with no retry. Fall back to `i.description` and guard against nil before calling `scrub`.
Remote topic import can abort on bad links or silently drop threads — A dead or malformed permalink aborts the entire import, and non-http(s) links silently drop that thread's posts because `TopicEmbed.import_remote` returns nil. Rescue network errors per URL and skip blank results so one bad link doesn't kill the run.
Invalid ERB tag `<%- end if %>` causes SyntaxError — This invalid ERB tag raises `SyntaxError` and returns a 500 for any already-embedded topic. Change it to a plain `end`.
Throttle key set without TTL can permanently block non-staff retrieval — A crash between `setnx` and `expire` leaves the key without a TTL, permanently blocking non-staff retrieval for that embed URL. Set the value and TTL atomically with `SET ... NX EX`.
Discourse embed postMessage origin check is substring, not exact — This substring check lets an untrusted origin embedded anywhere in the configured URL pass the trust test and send `discourse-resize` messages. Compare `new URL(discourseUrl).origin` exactly against `e.origin`.
PollFeed spec tests do not isolate each required setting — The other two settings default to values that already make the guard condition false, so removing any single check would leave its corresponding test green. Stub all other guards to passing values so only the named setting is tested.
Missing embed_url spec passes due to blank embeddable_host, not missing param — The blank `embeddable_host` causes the `ensure_embeddable` filter to fail first, so `response.should_not be_success` passes even without the `embed_url` require. Put the test in a context with a valid host and referer, then assert the specific 404.
Tests stub private retrieved_recently? guard instead of exercising Redis throttle — Stubbing `retrieved_recently?` directly means the Redis throttle is never exercised, so `retrieve`'s branch can pass with a broken guard. Arrange real Redis state or call the private method through `retrieve` so the throttle behavior is actually tested.
Concurrent TopicEmbed.import creates duplicate topic/post for the same URL — Concurrent imports from `poll_feed` and `retrieve_topic` can both pass the `embed.blank?` check, then the second `create!` raises on the unique index and aborts the job. Guard the create with a unique-constraint rescue or use a concurrency-safe find-or-create.
Update test to expect Jobs.enqueue(:retrieve_topic) instead of TopicRetriever — The controller now enqueues `:retrieve_topic` instead of calling `TopicRetriever` directly, so this mock expectation fails. Assert `Jobs.enqueue` with the job name and arguments.