DeepSeek V4.1 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 Haiku 5.5.

Gold bugs found
1 of 4
Comments published
5
Comments matching a bug
1
Comments not matching
4
Cost of this PR
$0.130

Published comments (5)

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

Migration dereferences nil PG rows for missing site settings — The migration aborts with `NoMethodError` whenever no matching row exists, which is the normal case for `embed_category` and blocks the upgrade. Guard both lookups with a `cmd_tuples` check like the block below already does.

highsecuritydb/migrate/20150818190757_create_embeddable_hosts.rb:25

SQL injection in embeddable_hosts migration via string interpolation — A stored host containing an apostrophe crashes the migration, and other SQL fragments are executed with migration privileges. Pass the value through `connection.quote` instead of interpolating it.

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

Migrated embeddable hosts keep URL scheme and never match — Values stored with `http://` bypass the model's `before_validation` normalization, so `EmbeddableHost.record_for_host` never matches the scheme-free `uri.host` and embedding silently stops working. Strip the scheme and path before inserting, or route the insert through the model.

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

Missing embeddable host causes NoMethodError in update and destroy — A stale or crafted id raises `NoMethodError` and returns a 500 instead of a JSON error. Raise `Discourse::NotFound` unless the `EmbeddableHost` lookup returns a record before calling `save_host` or `destroy`.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation raises NoMethodError when host is nil — A request that omits `host` raises `NoMethodError` in this callback and 500s before `validates_format_of` can report the field error. Skip the `sub!` calls when `host` is blank so validation handles it.

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.