Skip to content

Conversation

@akshayutture-augment
Copy link

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 0/5

  • This PR has critical issues that will break tests and create security vulnerabilities
  • Score of 0 due to fabricator files being completely swapped (breaking all category tests), SQL injection vulnerability in migration, and multiple missing nil checks that will cause runtime errors in production
  • Critical attention needed on spec/fabricators/category_fabricator.rb and spec/fabricators/embeddable_host_fabricator.rb (swapped content), db/migrate/20150818190757_create_embeddable_hosts.rb (SQL injection), and app/models/embeddable_host.rb + app/controllers/admin/embeddable_hosts_controller.rb (nil handling)

Important Files Changed

File Analysis

Filename Score Overview
spec/fabricators/category_fabricator.rb 0/5 Critical: Category fabricators completely removed and replaced with embeddable_host fabricator
spec/fabricators/embeddable_host_fabricator.rb 0/5 Critical: Contains category fabricators instead of embeddable_host fabricator
db/migrate/20150818190757_create_embeddable_hosts.rb 1/5 SQL injection vulnerability in migration using unescaped string interpolation
app/models/embeddable_host.rb 2/5 Missing nil check before calling sub! may cause runtime errors
app/controllers/admin/embeddable_hosts_controller.rb 2/5 Missing nil checks and strong parameters may cause errors

Sequence Diagram

sequenceDiagram
    participant Admin as Admin User
    participant UI as Admin UI
    participant Controller as EmbeddableHostsController
    participant Model as EmbeddableHost
    participant DB as Database
    participant Embed as EmbedController
    participant External as External Site

    Note over Admin,DB: Admin Management Flow
    Admin->>UI: Navigate to /admin/embedding
    UI->>Controller: GET /admin/customize/embedding
    Controller->>Model: EmbeddableHost.all
    Model->>DB: SELECT * FROM embeddable_hosts
    DB-->>Model: Return hosts
    Model-->>Controller: Return hosts with categories
    Controller-->>UI: Render embedding page
    UI-->>Admin: Display hosts with categories

    Admin->>UI: Add/Edit host + category
    UI->>Controller: POST/PUT /admin/embeddable_hosts
    Controller->>Model: Save host + category_id
    Model->>DB: INSERT/UPDATE embeddable_hosts
    DB-->>Model: Success
    Model-->>Controller: Return saved host
    Controller-->>UI: Return serialized host
    UI-->>Admin: Update display

    Note over Embed,External: Embedding Flow
    External->>Embed: Request embed with referer
    Embed->>Model: EmbeddableHost.host_allowed?(referer)
    Model->>DB: SELECT WHERE host = ?
    DB-->>Model: Return matching host
    Model-->>Embed: Host allowed + category
    Embed->>Embed: Create/retrieve topic in category
    Embed-->>External: Return embedded content
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

36 files reviewed, 7 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +1 to 4
Fabricator(:embeddable_host) do
host "eviltrout.com"
category
end
Copy link

Choose a reason for hiding this comment

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

logic: all category fabricators removed and replaced with embeddable_host - this will break all tests using category fabricators

Suggested change
Fabricator(:embeddable_host) do
host "eviltrout.com"
category
end
Fabricator(:category) do
name { sequence(:name) { |n| "Amazing Category #{n}" } }
user
end
Prompt To Fix With AI
This is a comment left during a code review.
Path: spec/fabricators/category_fabricator.rb
Line: 1:4

Comment:
**logic:** all category fabricators removed and replaced with embeddable_host - this will break all tests using category fabricators

```suggestion
Fabricator(:category) do
  name { sequence(:name) { |n| "Amazing Category #{n}" } }
  user
end
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +1 to +27
Fabricator(:category) do
name { sequence(:name) { |n| "Amazing Category #{n}" } }
user
end

Fabricator(:diff_category, from: :category) do
name "Different Category"
user
end

Fabricator(:happy_category, from: :category) do
name 'Happy Category'
slug 'happy'
user
end

Fabricator(:private_category, from: :category) do
transient :group

name 'Private Category'
slug 'private'
user
after_build do |cat, transients|
cat.update!(read_restricted: true)
cat.category_groups.build(group_id: transients[:group].id, permission_type: CategoryGroup.permission_types[:full])
end
end
Copy link

Choose a reason for hiding this comment

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

logic: embeddable_host fabricator file contains category fabricators - these files appear to be swapped

Suggested change
Fabricator(:category) do
name { sequence(:name) { |n| "Amazing Category #{n}" } }
user
end
Fabricator(:diff_category, from: :category) do
name "Different Category"
user
end
Fabricator(:happy_category, from: :category) do
name 'Happy Category'
slug 'happy'
user
end
Fabricator(:private_category, from: :category) do
transient :group
name 'Private Category'
slug 'private'
user
after_build do |cat, transients|
cat.update!(read_restricted: true)
cat.category_groups.build(group_id: transients[:group].id, permission_type: CategoryGroup.permission_types[:full])
end
end
Fabricator(:embeddable_host) do
host "eviltrout.com"
category
end
Prompt To Fix With AI
This is a comment left during a code review.
Path: spec/fabricators/embeddable_host_fabricator.rb
Line: 1:27

Comment:
**logic:** embeddable_host fabricator file contains category fabricators - these files appear to be swapped

```suggestion
Fabricator(:embeddable_host) do
  host "eviltrout.com"
  category
end
```

How can I resolve this? If you propose a fix, please make it concise.

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.

logic: SQL injection vulnerability - user input h directly interpolated into SQL without escaping

Suggested change
execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES ('#{h}', #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
execute("INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES (?, #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)", h)
Prompt To Fix With AI
This is a comment left during a code review.
Path: db/migrate/20150818190757_create_embeddable_hosts.rb
Line: 25:25

Comment:
**logic:** SQL injection vulnerability - user input `h` directly interpolated into SQL without escaping

```suggestion
            execute("INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES (?, #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)", h)
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +6 to +7
self.host.sub!(/^https?:\/\//, '')
self.host.sub!(/\/.*$/, '')
Copy link

Choose a reason for hiding this comment

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

logic: self.host might be nil - calling sub! on nil will raise NoMethodError

Suggested change
self.host.sub!(/^https?:\/\//, '')
self.host.sub!(/\/.*$/, '')
self.host = host.to_s.sub(/^https?:\/\//, '').sub(/\/.*$/, '') if host.present?
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/models/embeddable_host.rb
Line: 6:7

Comment:
**logic:** `self.host` might be nil - calling `sub!` on nil will raise NoMethodError

```suggestion
    self.host = host.to_s.sub(/^https?:\/\//, '').sub(/\/.*$/, '') if host.present?
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +10 to +11
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.

logic: missing nil check - host will be nil if id not found, causing error on line 11

Suggested change
host = EmbeddableHost.where(id: params[:id]).first
save_host(host)
host = EmbeddableHost.where(id: params[:id]).first
return render json: { errors: ['Host not found'] }, status: 404 unless host
save_host(host)
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/admin/embeddable_hosts_controller.rb
Line: 10:11

Comment:
**logic:** missing nil check - `host` will be nil if id not found, causing error on line 11

```suggestion
    host = EmbeddableHost.where(id: params[:id]).first
    return render json: { errors: ['Host not found'] }, status: 404 unless host
    save_host(host)
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +14 to +15
def destroy
host = EmbeddableHost.where(id: params[:id]).first
Copy link

Choose a reason for hiding this comment

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

logic: missing nil check - host will be nil if id not found

Suggested change
def destroy
host = EmbeddableHost.where(id: params[:id]).first
host = EmbeddableHost.where(id: params[:id]).first
return render json: { errors: ['Host not found'] }, status: 404 unless host
host.destroy
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/admin/embeddable_hosts_controller.rb
Line: 14:15

Comment:
**logic:** missing nil check - `host` will be nil if id not found

```suggestion
    host = EmbeddableHost.where(id: params[:id]).first
    return render json: { errors: ['Host not found'] }, status: 404 unless host
    host.destroy
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +23 to +24
host.host = params[:embeddable_host][:host]
host.category_id = params[:embeddable_host][:category_id]
Copy link

Choose a reason for hiding this comment

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

style: missing strong parameters - direct access to params[:embeddable_host] without filtering

Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/admin/embeddable_hosts_controller.rb
Line: 23:24

Comment:
**style:** missing strong parameters - direct access to `params[:embeddable_host]` without filtering

How can I resolve this? If you propose a fix, please make it concise.

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