GLM-5.3 Flash · Heavy

feature-can-edit-category-host-relationships-for-embedding-discourse-cursor

Discourse · Ruby · M · 100–299 lines · 6 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
6 of 10
Comments published
10
Comments matching a bug
6
Comments not matching
4
Cost of this PR
$0.369

Published comments (10)

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

SQL injection via unquoted host value interpolated into INSERT — The `embeddable_hosts` setting is admin-entered with no format validation, so a crafted value runs as arbitrary SQL during the migration — staff-level settings access escalates to full database execution. Wrap `h` with `connection.quote` instead of interpolating it.

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

Migration inserts unnormalized hosts with scheme/path, breaking host matching — Rows migrated with a scheme or path never match `EmbeddableHost.host_allowed?`, so embedding silently breaks on upgraded sites until each host is re-saved. Strip scheme and path from `h` before the INSERT, mirroring the model's `before_validation` normalization.

highbugapp/serializers/embedding_serializer.rb:3

Serializer emits only embeddable_host ids with no root-level records to hydrate from — The store's `_hydrateEmbedded` resolves the emitted ids against a root-level `embeddable_hosts` collection that no server payload includes, so hosts hydrate to undefined and the admin table cannot render or edit them. Emit the records as a sideloaded root collection with `embed_in_root: true`.

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

Migration crashes indexing empty result when site_settings rows are missing — Discourse only stores `site_settings` rows for non-default values, so on fresh installs these selects return zero rows and indexing `[0]` aborts `db:migrate`. Guard both lookups with `cmd_tuples > 0`, as the `embeddable_hosts` query below already does.

highbugapp/models/embeddable_host.rb:16-18

record_for_host can't match hosts stored with a port suffix — The validation accepts a `:8080`-style port but `before_validation` never strips it, and the comparison targets a port-less URI host, so a saved host can never match and embedded comments stay refused. Strip the port when comparing, or reject ports in the validation. **Also found in:** - `app/models/embeddable_host.rb:2-2`

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

Update/destroy 500 on missing embeddable host instead of 404 — A stale tab or a concurrent delete leaves `host` nil, so both actions raise `NoMethodError` instead of returning a clean 404. Raise `Discourse::NotFound` when the record is missing.

mediumbugapp/models/embeddable_host.rb:5-8

NoMethodError when host is nil in before_validation — An API call omitting `host` makes `self.host.sub!` raise `NoMethodError` — a 500 — instead of letting `validates_format_of` reject it with a 422. Skip the trimming when `host` is nil so validation can run.

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

delete() swallows destroyRecord rejections with no error handler — A failed `destroyRecord` (server error or the 500 the admin controller returns for a concurrently deleted record) is swallowed silently, leaving the row in the table as if it succeeded. Attach `.catch(popupAjaxError)`, as `save()` already does.

mediumbugspec/models/topic_spec.rb:1403-1405

Blank-embeddable-host test no longer discriminates (false && false passes trivially) — With the setup moved into the neighboring test, the assertion reduces to `false && false`, so it passes for any implementation that returns false — even a broken one. Set `SiteSetting.embed_truncate = true` and stub `has_topic_embed?` here so hosts are the only variable.

mediumbugapp/models/embeddable_host.rb:14-17

Case-sensitive bind value fails to match downcased stored hosts — A referer like `http://EvilTrout.com/x` keeps its casing through `URI(...).host`, so it never matches hosts stored lowercased and embedding is denied. Normalize the bind value with `host.downcase` so both sides compare equal.

Gold bugs found (6)

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.
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 (4)

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.