Skip to content

Prevent SQL Injection #142

@alencarandre

Description

@alencarandre

Please, help me.

I'm searching a way to prevent SQL Injection using Smart Listing.

For instance:

In my view:

<th><%= smart_listing.sortable ScheduledService.human_attribute_name("customer"), :customer_id %></th>

Params generated by Smart Listing:

?scheduled_service_smart_listing[page]=&scheduled_service_smart_listing[per_page]=10&scheduled_service_smart_listing[sort][customer_id]=asc

If I change scheduled_service_smart_listing[sort][customer_id]=asc for scheduled_service_smart_listing[sort][customer_id; delete from schedule_services where id = 1; --]=asc

Give me this error

PG::SyntaxError: ERROR:  cannot insert multiple commands into a prepared statement
: SELECT  "scheduled_services".* FROM "scheduled_services" ORDER BY customer_id; delete from schedule_services where id = 1; -- asc LIMIT $1 OFFSET $2

See that the DELETE instruction was delivered to database. Not executed, but, delivered and it's a problem. Has a way to avoid that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions