Skip to content

Conversation

@akshayutture-augment
Copy link

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Test 10


Replicated from ai-code-review-evaluation/discourse-cursor#10


Note

Adds a DB-backed EmbeddableHost with admin UI to manage host→category mappings, replaces old site settings, and updates embedding logic and client hydration.

  • Embedding management (Admin UI):
    • New routes, controller, adapter, templates, and component to list/edit/delete embeddable_hosts under Customize → Embedding.
  • Backend:
    • Add EmbeddableHost model, serializers, and CRUD (Admin::EmbeddableHostsController).
    • New Admin::EmbeddingController to expose embedding config.
    • Replace site-setting checks with EmbeddableHost.host_allowed? in EmbedController and TopicRetriever.
    • TopicEmbed.import assigns category via EmbeddableHost.record_for_host.
    • Topic#expandable_first_post? no longer depends on embeddable hosts setting.
    • Routes for /admin/customize/embedding and embeddable_hosts resources.
    • Migration to create embeddable_hosts and import from removed settings.
  • Client infrastructure:
    • REST adapter treats embeddable-host as admin model; basePath fix for dashed types.
    • Store hydrates plural relations from _ids arrays (e.g., color_idscolors).
  • Locales/Settings:
    • Add admin i18n for Embedding UI; remove embedding.embeddable_hosts/embed_category settings.
  • Tests/fixtures:
    • Add/adjust specs and fabricators for EmbeddableHost and embedding.
    • Update Pretender fixtures and store tests for plural _ids hydration.

Written by Cursor Bugbot for commit d1c6918. Configure here.

@akshayutture-augment
Copy link
Author

cursor review

records = val.split("\n")
if records.present?
records.each do |h|
execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES ('#{h}', #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unsafe Input Leads to SQL Injection

SQL injection vulnerability in migration: the variable h from user-controlled site settings is directly interpolated into the SQL query without escaping. If embeddable_hosts setting contains malicious input with single quotes, it could execute arbitrary SQL. Use parameterized queries or proper escaping.

Fix in Cursor Fix in Web


category_id = execute("SELECT c.id FROM categories AS c
INNER JOIN site_settings AS s ON s.value = c.name
WHERE s.name = 'embed_category'")[0]['id'].to_i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Migration Failure: Unsafe Data Access

Migration assumes the query for embed_category will return at least one result and accesses [0]['id'] without checking. If the site setting doesn't exist or the category name doesn't match, this will raise a NoMethodError when calling ['id'] on nil, causing the migration to fail.

Fix in Cursor Fix in Web


def update
host = EmbeddableHost.where(id: params[:id]).first
save_host(host)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Handle Missing Records Gracefully

The update action calls save_host(host) where host could be nil if no record with the given id exists. This will cause NoMethodError when save_host tries to set attributes on nil. The method should check if the host exists before proceeding.

Fix in Cursor Fix in Web


def destroy
host = EmbeddableHost.where(id: params[:id]).first
host.destroy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Destroy Fails Gracefully on Missing Resource

The destroy action calls host.destroy where host could be nil if no record with the given id exists. This will raise NoMethodError: undefined method 'destroy' for nil:NilClass instead of returning a proper 404 response.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants