Amazon Ergo 1.0 · 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
$3.382

Published comments (5)

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

Nil dereference when embed_category matches no category — The upgrade aborts before the `category_id == 0` fallback can run: an unmatched `embed_category` makes `execute(...)[0]['id']` raise `NoMethodError`. Check `cmd_tuples` or `first` and fall back to `uncategorized_category_id` instead of indexing `[0]` directly.

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

Legacy embeddable_hosts values migrated without scheme/path normalization — Embedding silently stops for migrated hosts because scheme/path values never match the bare hostname from `URI#host` in `EmbeddableHost.record_for_host`. Normalize each value with the same stripping as `before_validation`, and insert it using `quote` rather than SQL interpolation.

highbugapp/models/embeddable_host.rb:2-18

Validated host ports can never match in record_for_host — A saved `example.com:3000` passes validation and appears in the admin UI, yet `host_allowed?` can never return true because `record_for_host` compares against `URI#host`, which omits the port. Reject ports in validation or compare host and port consistently.

mediumbugapp/assets/javascripts/discourse/models/store.js.es6:192-201

Generic *_ids hydration can discard valid payload fields — Consumers lose `muted_category_ids` and `tracked_category_ids` to bogus `muted_categorys`/`tracked_categorys` arrays because no category pluralization is registered, and null `*_ids` values make `obj[k].map` throw. Only hydrate known sideloaded keys when `Array.isArray(obj[k])` and every `_lookupSubType` lookup succeeds, leaving the original key untouched otherwise.

mediumbugapp/models/topic_embed.rb:36-43

Imports without an EmbeddableHost lose their category — Feed-polled topics can end up uncategorized because `TopicEmbed.import` relies solely on `EmbeddableHost.record_for_host(url)`, and arbitrary feed-item URLs often have no matching `EmbeddableHost` row. Preserve a default-category fallback, such as `SiteSetting.embed_category`, for those imports.

Gold bugs found (3)

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.

Gold bugs missed (7)

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