Ahmad Al-kheat
Ahmad Al-kheat

Reputation: 1795

Is this SQL statement vulnerable to SQL injection?

My index action is

def index
  @users = User.without_user(current_user)
end

where without_user is a scope

scope :without_user, lambda {|user| where("id <> :id", :id => user.id) }

I was wondering if this is the most secure way to implement this or is it vulnerable ?

Upvotes: 3

Views: 91

Answers (2)

user3118220
user3118220

Reputation: 1468

It looks good, here sql injection will not work

Note Additional, In Rails 4, you can use not syntax:

scope :without_user, lambda {|user| where.not(id: user.id) }

Upvotes: 2

AshwinKumarS
AshwinKumarS

Reputation: 1313

looks fine. If the data is interpolated then it should be safe which looks like the case here.

Upvotes: 2

Related Questions