Skip to content

Commit 50d3d7d

Browse files
committed
Eliminate instance level writers for class accessors
Instance level writers can have an impact on how the Active Model / Record objects are saved. Specifically, they can be used to bypass validations. This is a problem if mass assignment protection is disabled and specific attributes are passed to the constructor. Conflicts: activerecord/lib/active_record/scoping/default.rb activesupport/lib/active_support/callbacks.rb CVE-2016-0753
1 parent be543e8 commit 50d3d7d

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

activemodel/lib/active_model/serializers/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module JSON
1010
included do
1111
extend ActiveModel::Naming
1212

13-
class_attribute :include_root_in_json
13+
class_attribute :include_root_in_json, instance_writer: false
1414
self.include_root_in_json = false
1515
end
1616

activemodel/lib/active_model/validations.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ module Validations
4646
include HelperMethods
4747

4848
attr_accessor :validation_context
49+
private :validation_context=
4950
define_callbacks :validate, scope: :name
5051

51-
class_attribute :_validators
52+
class_attribute :_validators, instance_writer: false
5253
self._validators = Hash.new { |h,k| h[k] = [] }
5354
end
5455

activerecord/lib/active_record/enum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module ActiveRecord
6868
# Where conditions on an enum attribute must use the ordinal value of an enum.
6969
module Enum
7070
def self.extended(base) # :nodoc:
71-
base.class_attribute(:defined_enums)
71+
base.class_attribute(:defined_enums, instance_writer: false)
7272
base.defined_enums = {}
7373
end
7474

activerecord/lib/active_record/reflection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Reflection # :nodoc:
44
extend ActiveSupport::Concern
55

66
included do
7-
class_attribute :_reflections
8-
class_attribute :aggregate_reflections
7+
class_attribute :_reflections, instance_writer: false
8+
class_attribute :aggregate_reflections, instance_writer: false
99
self._reflections = {}
1010
self.aggregate_reflections = {}
1111
end

activesupport/lib/active_support/callbacks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def define_callbacks(*names)
768768
end
769769

770770
names.each do |name|
771-
class_attribute "_#{name}_callbacks"
771+
class_attribute "_#{name}_callbacks", instance_writer: false
772772
set_callbacks name, CallbackChain.new(name, options)
773773
end
774774
end

0 commit comments

Comments
 (0)