MiniMax M3 · 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
4
Comments matching a bug
1
Comments not matching
3
Cost of this PR
$0.118

Published comments (4)

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

SQL injection via unsanitized embeddable_hosts interpolation — The `execute` call interpolates `embeddable_hosts` setting values into raw SQL, so any host containing a quote, backslash, or `'),'` either crashes the migration or injects unintended statements. Switch to `sanitize_sql_array` with placeholders so values are bound, not concatenated.

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

Migration crashes when embed_category site_setting is missing — The first `execute("... WHERE s.name = 'embed_category'")[0]['id'].to_i` dereferences `[0]` with no guard, so a missing `embed_category` site_setting raises NoMethodError before the `uncategorized_category_id` fallback runs. Stash the row in a local, check `cmd_tuples > 0`, and default to 0 when absent.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation crashes when host is nil — `before_validation` chains two `self.host.sub!` calls, so a nil `host` raises NoMethodError before `validates_format_of` ever runs. Guard with `return unless host.is_a?(String)` so the callback is a safe no-op when the attribute hasn't been assigned.

mediumbugapp/controllers/admin/embedding_controller.rb:9-11

Admin::EmbeddingController#update does no persistence, just re-renders — `Admin::EmbeddingController#update` re-renders the `OpenStruct` without persisting, so any PUT to `/admin/customize/embedding` returns 200 while changing nothing. Drop the route and the action, or make it perform the work the API expects.

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.