mirror of https://github.com/rails/rails
Don't allow `where` with invalid value matches to nil values
That is considered as silently leaking information. If type casting doesn't return any actual value, it should not be matched to any record. Fixes #33624. Closes #33946.
This commit is contained in:
parent
4ea067017a
commit
b09d8f6bb3
|
@ -13,10 +13,6 @@ module ActiveModel
|
|||
:time
|
||||
end
|
||||
|
||||
def serialize(value)
|
||||
super || value
|
||||
end
|
||||
|
||||
def user_input_in_time_zone(value)
|
||||
return unless value.present?
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
* Don't allow `where` with invalid value matches to nil values.
|
||||
|
||||
Fixes #33624.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
||||
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
|
|
@ -18,8 +18,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def nil?
|
||||
!value_before_type_cast.is_a?(StatementCache::Substitute) &&
|
||||
(value_before_type_cast.nil? || value_for_database.nil?)
|
||||
unless value_before_type_cast.is_a?(StatementCache::Substitute)
|
||||
value_before_type_cast.nil? ||
|
||||
type.respond_to?(:subtype, true) && value_for_database.nil?
|
||||
end
|
||||
rescue ::RangeError
|
||||
end
|
||||
|
||||
|
|
|
@ -114,6 +114,12 @@ class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
|
|||
assert_equal "foobar", uuid.guid_before_type_cast
|
||||
end
|
||||
|
||||
def test_invalid_uuid_dont_match_to_nil
|
||||
UUIDType.create!
|
||||
assert_empty UUIDType.where(guid: "")
|
||||
assert_empty UUIDType.where(guid: "foobar")
|
||||
end
|
||||
|
||||
def test_acceptable_uuid_regex
|
||||
# Valid uuids
|
||||
["A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11",
|
||||
|
|
|
@ -50,8 +50,12 @@ module ActiveRecord
|
|||
assert_equal [chef], chefs.to_a
|
||||
end
|
||||
|
||||
def test_where_with_casted_value_is_nil
|
||||
assert_equal 4, Topic.where(last_read: "").count
|
||||
def test_where_with_invalid_value
|
||||
topics(:first).update!(written_on: nil, bonus_time: nil, last_read: nil)
|
||||
assert_empty Topic.where(parent_id: Object.new)
|
||||
assert_empty Topic.where(written_on: "")
|
||||
assert_empty Topic.where(bonus_time: "")
|
||||
assert_empty Topic.where(last_read: "")
|
||||
end
|
||||
|
||||
def test_rewhere_on_root
|
||||
|
|
Loading…
Reference in New Issue