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