GLM-5.3 Flash · 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
5 of 10
Comments published
7
Comments matching a bug
5
Comments not matching
2
Cost of this PR
$0.086

Published comments (7)

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

Migration crashes when embed_category setting is missing or invalid — Any site without a stored `embed_category` value gets a crash in `db:migrate` and a blocked upgrade, even though the empty case was meant to fall through to `uncategorized_category_id`. Nil-check the row before reading `['id']`, and guard the fallback lookup the same way.

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

Migrated hosts stored without stripping scheme/path break record_for_host matching — Hosts stored with a scheme or path, like `http://discourse.org`, never match the `uri.host` comparison in `record_for_host`, so previously-working embedding silently stops. Apply the same scheme/path stripping to `h` before inserting.

mediumsecuritydb/migrate/20150818190757_create_embeddable_hosts.rb:25

Migration interpolates unquoted host value into SQL, allowing injection — A single quote in any stored host value breaks or hijacks the insert run during migrate. Build the `VALUES` clause with `ActiveRecord::Base.connection.quote(h)` or a parameterized insert instead of interpolating `h` raw.

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

update and destroy raise NoMethodError on missing host instead of 404 — A stale or double-deleted id makes `host` nil, so `save_host(host)` and `host.destroy` raise NoMethodError and return a 500 instead of a 404. Raise `Discourse::NotFound` when the lookup misses.

mediumbugapp/models/embeddable_host.rb:5-8

NoMethodError in before_validation when host is nil — Saving a record without a `host` crashes in the `before_validation` hook before `validates_format_of` can reject it, yielding a 500 instead of a 422. Guard both `sub!` calls with a presence check on `self.host`.

mediumbugapp/models/embeddable_host.rb:10-18

record_for_host ignores ports on stored hosts, so ported hosts never match — The validation regex accepts `example.com:8080`, but `record_for_host` compares it against the portless `uri.host`, so such records can never match a referer. Strip the port when comparing, or match host and port explicitly.

mediumbugapp/assets/javascripts/admin/components/embeddable-host.js.es6:43-51

Delete action swallows destroyRecord failures (no .catch) — A failed deletion leaves the row stuck in the table with an unhandled rejection and no error shown, unlike `save()` in this component. Chain `.catch(popupAjaxError)` onto the `destroyRecord()` promise.

Gold bugs found (5)

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

Gold bugs missed (5)

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