Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Security vulnerability fixed - it is possible to cause the WHERE clause of a query to be omitted #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/dm-do-adapter/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def comparison_statement(comparison, qualify)
else
return conditions_statement(comparison.foreign_key_mapping, qualify)
end
elsif comparison.slug == :in && !value.any?
elsif comparison.slug == :in && empty_comparison?(value)
return [] # match everything
end

Expand Down Expand Up @@ -752,6 +752,11 @@ def quote_name(name)

end

# @api private
def empty_comparison?(value)
value.respond_to?(:empty?) && value.empty?
end

include SQL

end
Expand Down
17 changes: 17 additions & 0 deletions lib/dm-do-adapter/spec/shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ class ::Author
end
end

describe 'with an inclusion comparison of falsy values' do
before :all do
5.times do |index|
@article_model.create(:name => "Test #{index}", :parent => @article_model.last).should be_saved
end

@parents = [nil]
@query = DataMapper::Query.new(repository, @article_model, :parent => @parents)
@return = @adapter.read(@query)
end

it 'should return records with matching values' do
@return.size.should == 1
@return.to_a.first.should == @article_model.first.attributes(:property)
end
end

end

describe 'with a Query Path' do
Expand Down