GLM-5.3 · 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 Haiku 5.5.

Gold bugs found
2 of 4
Comments published
6
Comments matching a bug
2
Comments not matching
4
Cost of this PR
$1.544

Published comments (6)

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

Migration crashes with NoMethodError when no 'embed_category' setting row exists — On any site without an `embed_category` row, `[0]` returns nil and `nil['id']` aborts `db:migrate` before the `uncategorized_category_id` fallback can run. Guard the query result as migration 20140929204155 does, checking `cmd_tuples > 0` before indexing.

highbugdb/migrate/20150818190757_create_embeddable_hosts.rb:22-26

Migration inserts unnormalized hosts, breaking exact-host matching for scheme/path-qualified entries — Migrated rows like `https://example.com/1234` are stored verbatim, so `record_for_host`'s exact `lower(host) = uri.host` match fails and previously-allowed hosts get `Discourse::InvalidAccess` on `/embed/comments`. Apply the model's normalization, stripping the scheme and path, to each line before inserting.

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

Unescaped host value interpolated into INSERT breaks migration on quotes — A single quote in an old setting value produces invalid SQL and aborts `db:migrate` mid-run. Escape `h` with `PG::Connection.escape_string` as sibling migration 20140929204155 does, or use bound `exec_insert`.

highbugapp/models/embeddable_host.rb:2-8

Hosts saved with a port never match in record_for_host, rejecting valid embed requests — A host saved as `example.com:8080` passes the validation regex but is stored with the port, which `uri.host` never includes, so `record_for_host` rejects every embed request from it. Strip the port in `before_validation` with `sub!(/:\d+$/, '')` or compare including it in `record_for_host`.

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

Update and destroy raise NoMethodError on stale embeddable host id — A stale id makes `save_host(nil)` call `nil.host=` and `destroy` call `nil.destroy`, returning a 500 instead of a 404. Add `raise Discourse::NotFound` when the `EmbeddableHost.where(id: params[:id]).first` lookup is nil.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation callback raises NoMethodError when host is nil — Guard with `self.host = (self.host || '').sub(...)`.

Gold bugs found (2)

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.
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.

Gold bugs missed (2)

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.
highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.