Claude Opus 5.5 · 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
- 7
- Comments matching a bug
- 1
- Comments not matching
- 6
- Cost of this PR
- $0.763
Published comments (7)
Migration crashes when no `embed_category` site setting row exists — Default settings have no row, so the query returns nothing and `[0]['id']` raises `NoMethodError`, aborting the migration. Check that the result is non-empty before indexing, and guard the `uncategorized_category_id` lookup the same way.
SQL injection via unescaped host value in embeddable_hosts INSERT — A host containing a quote breaks the migration, and a crafted `embeddable_hosts` value can run arbitrary SQL. Quote `h` with `ActiveRecord::Base.connection.quote(h)` or use a parameterized insert.
Migrated embeddable hosts keep scheme, path and whitespace, so they never match — Entries like `https://example.com/1234` are copied verbatim, so `record_for_host`, which compares against the bare `uri.host`, never matches them and embedding silently stops working. Strip whitespace, scheme and path from each entry (for example, `URI(h).host || h`) before inserting it.
Host lookup is case-sensitive on the incoming host and rejects uppercase URLs — `URI#host` keeps the original case, so a URL like `http://EvilTrout.com` is rejected even though its host is allowed. Pass `host.downcase` as the bind value to match `lower(host)`.
`_ids` hydration crashes on null and leaves undefined entries for unresolved ids — A null `_ids` value crashes on `.map`, and ids `_lookupSubType` cannot resolve become `undefined` entries while the raw ids are deleted, since `hydrated || []` never falls back. Skip non-array values and filter out unresolved lookups, keeping the raw ids when nothing resolves.
before_validation raises NoMethodError when host is nil — Calling `create`/`update` without `embeddable_host[host]` makes `self.host.sub!` raise `NoMethodError`, returning a 500 instead of a validation error. Guard the callback with `if host.present?`.
Unknown embeddable host id raises NoMethodError (500) instead of 404 — For an unknown id, `where(id: params[:id]).first` returns nil and `save_host`/`host.destroy` raise `NoMethodError`, so clients get a 500. Use `EmbeddableHost.find(params[:id])` or raise `Discourse::NotFound` when the record is nil.