Claude Opus 5.5 · 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
1 of 4
Comments published
7
Comments matching a bug
1
Comments not matching
6
Cost of this PR
$0.763

Published comments (7)

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

Migration crashes when no `embed_category` site setting row exists — Default settings have no row, so the query returns nothing and `[0]['id']` raises `NoMethodError`, aborting the migration. Check that the result is non-empty before indexing, and guard the `uncategorized_category_id` lookup the same way.

highsecuritydb/migrate/20150818190757_create_embeddable_hosts.rb:25

SQL injection via unescaped host value in embeddable_hosts INSERT — A host containing a quote breaks the migration, and a crafted `embeddable_hosts` value can run arbitrary SQL. Quote `h` with `ActiveRecord::Base.connection.quote(h)` or use a parameterized insert.

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

Migrated embeddable hosts keep scheme, path and whitespace, so they never match — Entries like `https://example.com/1234` are copied verbatim, so `record_for_host`, which compares against the bare `uri.host`, never matches them and embedding silently stops working. Strip whitespace, scheme and path from each entry (for example, `URI(h).host || h`) before inserting it.

highbugapp/models/embeddable_host.rb:17

Host lookup is case-sensitive on the incoming host and rejects uppercase URLs — `URI#host` keeps the original case, so a URL like `http://EvilTrout.com` is rejected even though its host is allowed. Pass `host.downcase` as the bind value to match `lower(host)`.

highbugapp/assets/javascripts/discourse/models/store.js.es6:196-201

`_ids` hydration crashes on null and leaves undefined entries for unresolved ids — A null `_ids` value crashes on `.map`, and ids `_lookupSubType` cannot resolve become `undefined` entries while the raw ids are deleted, since `hydrated || []` never falls back. Skip non-array values and filter out unresolved lookups, keeping the raw ids when nothing resolves.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation raises NoMethodError when host is nil — Calling `create`/`update` without `embeddable_host[host]` makes `self.host.sub!` raise `NoMethodError`, returning a 500 instead of a validation error. Guard the callback with `if host.present?`.

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

Unknown embeddable host id raises NoMethodError (500) instead of 404 — For an unknown id, `where(id: params[:id]).first` returns nil and `save_host`/`host.destroy` raise `NoMethodError`, so clients get a 500. Use `EmbeddableHost.find(params[:id])` or raise `Discourse::NotFound` when the record is nil.

Gold bugs found (1)

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 (3)

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.