DeepSeek V4 Pro · Balanced

feature-can-edit-category-host-relationships-for-embedding-discourse-cursor

Discourse · Ruby · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
3 of 10
Comments published
5
Comments matching a bug
3
Comments not matching
2
Cost of this PR
$0.641

Published comments (5)

highbugdb/migrate/20150818190757_create_embeddable_hosts.rb:9-15

Embeddable hosts migration crashes on empty embed_category lookup — The lookup returns an empty result when `embed_category` is unset or matches no category name, so `[0]['id']` raises and the migration aborts before migrating any hosts. Check for an empty result before dereferencing, for example with `.first` or an explicit branch.

highbugdb/migrate/20150818190757_create_embeddable_hosts.rb:24-25

Embeddable host migration stores scheme/path, breaking record_for_host matching — Legacy values like `http://eviltrout.com` or `https://example.com/1234` keep their scheme and path, while `EmbeddableHost.record_for_host` compares only `uri.host`, so those hosts never match after upgrade. Normalize each `h` by stripping scheme and path before inserting, mirroring the model's `before_validation`.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation host normalization raises NoMethodError on nil host — A missing `host` parameter reaches `self.host.sub!` as nil and raises NoMethodError, turning a validation problem into a 500. Guard with `host.blank?` or return early before the substitutions.

mediumbugapp/controllers/admin/embeddable_hosts_controller.rb:10-16

Nil host raises NoMethodError in update and destroy — A non-existent id makes `EmbeddableHost.where(id: params[:id]).first` nil, and both `update` and `destroy` dereference it, producing NoMethodError instead of a client-visible error. Guard for a missing record and render a 404 or error response.

mediumbugapp/models/topic_embed.rb:36-43

Imported topic loses category when embed host is not allowlisted — When `record_for_host(url)` returns nil, `eh.try(:category_id)` is nil and `PostCreator` falls back to the uncategorized category. Feed-polled topics pass URLs with no host allowlist check, so use `SiteSetting.embed_category` as the fallback to preserve the intended category.

Gold bugs found (3)

mediumupdate and destroy in Admin::EmbeddableHostsController fetch the host with where(id:).first and never check for nil, so an unknown id raises NoMethodError and returns a 500 instead of not-found.
highThe migration copies the legacy embeddable_hosts values into the new table without stripping scheme and path, so hosts stored as http://example.com no longer match the bare-host lookup and previously allowed embeds are rejected after upgrade.
highThe migration reads execute(...)[0]['id'] for embed_category without checking for an empty result, so installs without that setting stored crash the migration instead of falling back to the uncategorized category.

Gold bugs missed (7)

highrecord_for_host compares lower(host) against the un-lowercased URI host, so mixed-case referer hosts fail to match allowed hosts and embedding is rejected.
mediumAfter saving a host, the component overwrites its category with findById(categoryId); when no category was chosen this is null even though the server saved the uncategorized category, so the row shows no category until reload.
highHosts saved with a port (allowed by the validation regex) are stored as host:port, but lookup compares only URI.host, so those configured hosts never match and embedding fails for them.
highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.
mediumEmbeddableHost has no (case-insensitive) uniqueness validation or unique index, so the same host can be saved twice with different categories and record_for_host silently picks whichever row comes first.
mediumThe embeddable-host component's delete action has no .catch(popupAjaxError) on destroyRecord(), so a failed host deletion is silently swallowed and the row stays with no feedback to the admin.
mediumThe 'raises an error with a missing host' spec sends no referer, so the request fails on the nil referer regardless of the empty embeddable_hosts table; the missing-host behaviour is not actually tested.