Kimi K3.1 Pro · 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
- 4 of 4
- Comments published
- 11
- Comments matching a bug
- 4
- Comments not matching
- 7
- Cost of this PR
- $1.912
Published comments (11)
Missing embed category result is dereferenced before fallback — When `embed_category` was never overridden, is blank, or no longer matches a category name, this query returns no rows and `[0]['id']` raises before the uncategorized fallback can run. Guard the missing result and fall back when it is absent instead of dereferencing it unconditionally.
Legacy embeddable hosts are migrated without host normalization — Legacy values are copied verbatim even though entries such as `http://discourse.org` and `https://example.com/1234` were supported, while `record_for_host` compares only `uri.host` with the stored value. Those previously working hosts stop authorizing embeds after upgrade; normalize schemes and paths with the same rules as `EmbeddableHost` before inserting them.
Stored embeddable host values allow SQL injection during migration — A stored `embeddable_hosts` entry is interpolated directly into executable SQL, so a quote can abort the migration and a crafted value can execute arbitrary SQL with database privileges during the upgrade. Parameterize the insert or escape `h` with the connection's quoting API instead of interpolating it.
Nil host causes NoMethodError in validation callback — Guard nil or assign a normalized `host.to_s` result before applying the substitutions.
Validation accepts values such as `example.com:3000`, but `URI(...).host` returns only… — Compare a consistently normalized host and optional port, or reject/strip ports when writing the record.
Five-character TLD cap rejects valid hostnames — The two-to-five-character TLD restriction rejects valid domains such as `example.museum` and `example.technology`, preventing those sites from being configured for embedding. Remove the five-character cap or validate the hostname without imposing this TLD-length limit.
Embeddable hosts lack case-insensitive uniqueness — The schema permits duplicate case-insensitive hostnames, but `record_for_host` uses only the first matching row, so duplicate entries with different categories make later mappings ineffective and confuse subsequent edits. Enforce case-insensitive host uniqueness in the model and back it with a unique functional database index.
Missing embeddable hosts cause 500s in update and destroy — Both `update` and `destroy` dereference the lookup result without checking it, so a stale or nonexistent ID causes a 500 through `save_host(nil)` or `host.destroy`. Return a 404 when no host is found before calling either operation.
Stale categoryId clears the category badge after saving a new host — Resolve the category from the saved record's `category_id` and synchronize `categoryId` instead of reusing the stale input value.
Unindexed lowercase host lookup scans the host table on embed requests — Every embedded comments/count request now executes `lower(host) = ?` on a table with no host index, replacing the cached site-setting check and requiring a scan of the host table for denied requests. Add an index on `lower(host)` and normalize the query value consistently so this hot-path lookup can use it.
First-post expansion remains enabled without embeddable hosts — With `embed_truncate` enabled, an embedded topic still exposes the first-post expansion UI after the last embeddable host is deleted, whereas the previous behavior and the retained no-host spec require `false`. Restore an `EmbeddableHost.exists?` guard, and make that spec enable truncation and stub `has_topic_embed?` so it exercises the no-host branch.
Gold bugs found (4)
Gold bugs missed (0)
None.