From 8ce4bd1be83c08c30c34af4d0f1a726066128176 Mon Sep 17 00:00:00 2001 From: Zack Date: Fri, 22 Apr 2022 15:21:40 -0400 Subject: [PATCH 1/1] Change ActiveRecord::Coders::YAMLColumn default to safe_load In Psych >= 4.0.0, load defaults to safe_load. This commit makes the ActiveRecord::Coders::YAMLColum class use Psych safe_load as the Rails default. This default is configurable via ActiveRecord::Base.use_yaml_unsafe_load We conditionally fallback to the correct unsafe load if use_yaml_unsafe_load is set to true. unsafe_load was introduced in Psych >= 4.0.0 The list of safe_load permitted classes is configurable via ActiveRecord::Base.yaml_column_permitted_classes [CVE-2022-32224] --- activerecord/lib/active_record/core.rb | 8 ++ 1 files changed, 337 insertions(+), 36 deletions(-) diff --git a/activerecord-6.1.4.1/lib/active_record/core.rb b/activerecord-6.1.4.1/lib/active_record/core.rb index 3fb15f9531..379cae1830 100644 --- a/activerecord-6.1.4.1/lib/active_record/core.rb +++ b/activerecord-6.1.4.1/lib/active_record/core.rb @@ -155,6 +155,14 @@ def self.configurations mattr_accessor :legacy_connection_handling, instance_writer: false, default: true + # Application configurable boolean that instructs the YAML Coder to use + # an unsafe load if set to true. + mattr_accessor :use_yaml_unsafe_load, instance_writer: false, default: false + + # Application configurable array that provides additional permitted classes + # to Psych safe_load in the YAML Coder + mattr_accessor :yaml_column_permitted_classes, instance_writer: false, default: [] + self.filter_attributes = [] def self.connection_handler -- 2.33.0