Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6.1.6.1 with Ruby 2.5 throws ArgumentError: unknown keywords: permitted_classes, aliases #45590

Closed
ofedoren opened this issue Jul 13, 2022 · 13 comments

Comments

@ofedoren
Copy link

Due to latest security update [1] backported to 6.1-stable Rails can no longer load on Ruby 2.5.

[1] - f05ac78

I guess it's due to simple overlook at the safe_load method version between different Rubies:

Ruby 2.5.9: https://ruby-doc.org/stdlib-2.5.9/libdoc/psych/rdoc/Psych.html#method-c-safe_load
Ruby 2.6.0: https://ruby-doc.org/stdlib-2.6/libdoc/psych/rdoc/Psych.html#method-c-safe_load

Steps to reproduce

Have Rails 6.1.6.1 application running on Ruby 2.5.x.

Expected behavior

Rails works as before.

Actual behavior

Trying to load application throws [/usr/local/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/psych.rb:313]: ArgumentError: unknown keywords: permitted_classes, aliases.

System configuration

Rails version: 6.1.6.1

Ruby version: 2.5.1

@eileencodes
Copy link
Member

eileencodes commented Jul 13, 2022

Assigning to @skipkayhil since he's already noticed this and is working on a fix. Will let you know when it's merged.

While not a short term fix, it's recommended you upgrade your Ruby version ASAP. It has been EOL since March 2021 and could be vulnerable to other security issues.

@lanej
Copy link

lanej commented Jul 13, 2022

In case anyone can't wait:

module Psych
  module_function

  class << self
    alias original_safe_load safe_load
  end

  def safe_load(yaml,
                whitelist_classes = [],
                whitelist_symbols = [],
                arg_aliases = false,
                filename = nil,
                symbolize_names: false,
                permitted_classes: whitelist_classes,
                aliases: false)
    original_safe_load(
      yaml, permitted_classes, whitelist_symbols, aliases || arg_aliases, filename,
      symbolize_names: symbolize_names,
    )
  end
end

@skipkayhil
Copy link
Member

In case anyone can't wait:

You can also try adding gem "psych", "~> 3.1" to your Gemfile, this is only an issue with Psych 3.0.x

@eileencodes
Copy link
Member

Closed by #45593

@danmun
Copy link

danmun commented Jul 19, 2022

I am getting something similar after moving from Rails 5.2.7 to 5.2.8.1. Using Ruby 2.5.7.

The error is thrown when trying to prepare the DB for tests, at first by running rake db:seed.

Screenshot 2022-07-19 at 13 42 25

@eileencodes
Copy link
Member

eileencodes commented Jul 19, 2022

@danmun This was fixed in the closed PR. I've quoted below what I wrote there. Point your gemfile at the 5-2-stable branch and this will be fixed. However, I highly recommend upgrading to 6.x ASAP, 5.2 is no longer supported. It will not receive anymore releases.

I backported this to 6-0-stable and 5-2-stable. Both required backports of other changes.

For anyone who ends up here, I'm not sure when we're going to do bugfix releases but it's highly unlikely 5-2-stable will get one. It's been EOL since June, this was the last security release of 5.2. If you need these changes, please point your gemfile at the 5-2-stable branch.

@danmun
Copy link

danmun commented Jul 20, 2022

@eileencodes Noted, thank you! I will use 5-2-stable.

@baraidrissa
Copy link

In case anyone can't wait:

module Psych
  module_function

  class << self
    alias original_safe_load safe_load
  end

  def safe_load(yaml,
                whitelist_classes = [],
                whitelist_symbols = [],
                arg_aliases = false,
                filename = nil,
                symbolize_names: false,
                permitted_classes: whitelist_classes,
                aliases: false)
    original_safe_load(
      yaml, permitted_classes, whitelist_symbols, aliases || arg_aliases, filename,
      symbolize_names: symbolize_names,
    )
  end
end

If your application uses Symbol and Time in serialized data, you can add Symbol and Time to the allowed list as follows:
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]

https://github.com/rails/rails/blob/v5.2.8.1/activerecord/CHANGELOG.md

@fjorba
Copy link

fjorba commented Sep 5, 2022

In case anyone can't wait:

module Psych
  module_function
[etc]

For those less familarized with Ruby or Rails, and have found this problem with Debian-packaged verison of Redmine, to apply @lanej solution (thanks so much!), add his lines at the end of /usr/lib/ruby/2.5.0/psych.rb (Ruby allows to redefine a piece of software). Also add @baraidrissa (again, thanks!) line at /usr/share/redmine/config/application.rb. Add also ActiveSupport::HashWithIndifferentAccess, so it reads:

config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time, ActiveSupport::HashWithIndifferentAccess]

@Vebryn
Copy link

Vebryn commented Sep 6, 2022

Hi,

Also encounting this error, I added module Psych to psych.rb and application.rb.

Add also ActiveSupport::HashWithIndifferentAccess

Where to add this ?

@fjorba
Copy link

fjorba commented Sep 6, 2022

Hi,

Also encounting this error, I added module Psych to psych.rb and application.rb.

Add also ActiveSupport::HashWithIndifferentAccess

Where to add this ?

As said in my previous message, in /usr/share/redmine/config/application.rb. But module Psych just in psch.rb, not in application.rb.

@mhsmith
Copy link

mhsmith commented Sep 16, 2022

After applying the above workarounds, my Redmine server was broken again by the next Debian update:

Log started: 2022-09-15  06:49:15
apt-listchanges: Reading changelogs...
Preparing to unpack .../00-ruby-rails_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-rails (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../01-ruby-activestorage_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-activestorage (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../02-ruby-activerecord_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-activerecord (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../03-ruby-activemodel_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-activemodel (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../04-ruby-actionmailer_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-actionmailer (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../05-ruby-activejob_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-activejob (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../06-ruby-actioncable_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-actioncable (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../07-ruby-railties_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-railties (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../08-ruby-actionpack_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-actionpack (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../09-ruby-actionview_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-actionview (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Preparing to unpack .../10-ruby-activesupport_2%3a5.2.2.1+dfsg-1+deb10u5_all.deb ...
Unpacking ruby-activesupport (2:5.2.2.1+dfsg-1+deb10u5) over (2:5.2.2.1+dfsg-1+deb10u4) ...
Setting up ruby-activesupport (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-actionview (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-activemodel (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-activejob (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-actionpack (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-activerecord (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-actioncable (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-actionmailer (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-activestorage (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-railties (2:5.2.2.1+dfsg-1+deb10u5) ...
Setting up ruby-rails (2:5.2.2.1+dfsg-1+deb10u5) ...
Processing triggers for redmine (4.0.7-1~bpo10+1) ...
Determining localhost credentials from /etc/mysql/debian.cnf: succeeded.
dbconfig-common: flushing administrative password
 [33m`/var/www` is not writable.
Bundler will use `/tmp/bundler-20220915-18555-1yz06sb' as your home directory temporarily.
 [0mrake aborted!
NoMethodError: undefined method `yaml_column_permitted_classes=' for ActiveRecord::Base:Class
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/railtie.rb:124:in `block (3 levels) in <class:Railtie>'
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/railtie.rb:123:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/railtie.rb:123:in `block (2 levels) in <class:Railtie>'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
/usr/share/rubygems-integration/all/gems/activerecord-5.2.2.1/lib/active_record/base.rb:27:in `<top (required)>'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `block in load'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:285:in `load'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/engine.rb](http://5.2.2.1/lib/rails/engine.rb):657:in `block in load_config_initializer'
/usr/share/rubygems-integration/all/gems/activesupport-5.2.2.1/lib/active_support/notifications.rb:170:in `instrument'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/engine.rb](http://5.2.2.1/lib/rails/engine.rb):656:in `load_config_initializer'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/engine.rb](http://5.2.2.1/lib/rails/engine.rb):614:in `block (2 levels) in <class:Engine>'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/engine.rb](http://5.2.2.1/lib/rails/engine.rb):613:in `each'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/engine.rb](http://5.2.2.1/lib/rails/engine.rb):613:in `block in <class:Engine>'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:32:in `instance_exec'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:32:in `run'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:61:in `block in run_initializers'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:50:in `each'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:50:in `tsort_each_child'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/](http://5.2.2.1/lib/rails/)initializable.rb:60:in `run_initializers'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/application](http://5.2.2.1/lib/rails/application).rb:361:in `initialize!'
/usr/share/redmine/config/environment.rb:14:in `<top (required)>'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/application](http://5.2.2.1/lib/rails/application).rb:337:in `require'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/application](http://5.2.2.1/lib/rails/application).rb:337:in `require_environment!'
/usr/share/rubygems-integration/all/gems/railties-[5.2.2.1/lib/rails/application](http://5.2.2.1/lib/rails/application).rb:520:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
dpkg: error processing package redmine (--configure):
 installed redmine package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 redmine
Log ended: 2022-09-15  06:49:25

I think the culprit is this entry in /usr/share/doc/ruby-activerecord/changelog.Debian.gz:

rails (2:5.2.2.1+dfsg-1+deb10u5) buster-security; urgency=medium

  * Non-maintainer upload by the Debian LTS Team.
  * Regression on last upload. Disable patch for CVE-2022-32224

 -- Abhijith PA <abhijith@debian.org>  Tue, 13 Sep 2022 13:57:41 +0000

I was able to fix the problem by commenting out the yaml_column_permitted_classes line mentioned above.

@fjorba
Copy link

fjorba commented Sep 16, 2022

Exacty, that's what I've done today myself.

rjpaskin added a commit to CreatekIO/report_generator that referenced this issue Oct 18, 2022
Rails 5.2.8 (or thereabouts) has an option for using `YAML.safe_load`
for serialized ActiveRecord fields, but assumes the Ruby 2.6/Psych 3.1
interface for that method (using keyword arguments).

Since we're still on Ruby 2.5, and can't confidently whitelist classes
for `safe_load` (since that's down to downstreaming consuming code), we
disable this feature for the test suite.

See rails/rails#45590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants