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

Fix issues loading serialized logs #4376

Merged

Conversation

waiting-for-dev
Copy link
Contributor

@waiting-for-dev waiting-for-dev commented May 17, 2022

Spree::LogEntry loads details from a YAML string that can potentially
contain any serialized Ruby object if users have overridden some part of
the codebase.

New Psych (YAML parser) version packed with Ruby 3.1 requires that, by
default, users are explicit about which type of classes are allowed to
be loaded (see ruby/psych@cb50aa8 and ruby/psych@1764942).

On 008168c, we updated our code to allow instances of
ActiveMerchant::Billing::Response. However, as noted in a
comment
,
it seems we're missing, at least, instances of
ActiveSupport::TimeWithZone.

We need to add all classes used internally and leave a door open for
users to add their own classes (via a new log_entry_permitted_classes
preference).

On top of that, by default, YAML.safe_load won't allow YAML aliases to be parsed.
However, we need them at least for older versions of serialized
ActiveSupport::TimeWithZone.

We add a configuration option so that users can still disable it.
Depending on the source of the YAML, parsing aliases could open gates to
entity expansion attacks (a DoS created by nesting self-references).

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

waiting-for-dev referenced this pull request May 17, 2022
The new Psych version required by Ruby 3.1 no longer allows the loading
of arbitrary classes into YAML by default. We switch to `#safe_load` and
enable the class we're currently using.

See:

ruby/psych@cb50aa8
ruby/psych@1764942

[skip ci]
@waiting-for-dev waiting-for-dev marked this pull request as draft May 17, 2022 10:15
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/psych_allowed branch from 9169af9 to 5d86c11 Compare May 18, 2022 04:15
@waiting-for-dev waiting-for-dev marked this pull request as ready for review May 18, 2022 04:43
@waiting-for-dev waiting-for-dev changed the title Add missing class and allow extending serializable classes on logs Fix issues loading serialized logs May 18, 2022
@aldesantis aldesantis requested a review from a team May 18, 2022 09:29
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waiting-for-dev waiting-for-dev added the release:major Breaking change on hold until next major release label May 18, 2022
@waiting-for-dev
Copy link
Contributor Author

We are putting it on hold, as we'll rescue from Psych exception about unknown classes and print a message redirecting to the new preference.

@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/psych_allowed branch from 5d86c11 to f3a5a62 Compare May 19, 2022 03:21
@waiting-for-dev waiting-for-dev removed the release:major Breaking change on hold until next major release label May 19, 2022
@waiting-for-dev
Copy link
Contributor Author

We are putting it on hold, as we'll rescue from Psych exception about unknown classes and print a message redirecting to the new preference.

Done. @albertoalmagro, @aldesantis, do you want to take a final look?

Copy link
Member

@aldesantis aldesantis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waiting-for-dev the implementation looks good, but I've left a couple of suggestions. Let me know your thoughts!

core/app/models/spree/log_entry.rb Outdated Show resolved Hide resolved
core/app/models/spree/log_entry.rb Show resolved Hide resolved
`Spree::LogEntry` loads details from a YAML string that can potentially
contain any serialized Ruby object if users have overridden some part of
the codebase.

New Psych (YAML parser) version packed with Ruby 3.1 requires that, by
default, users are explicit about which type of classes are allowed to
be loaded (see ruby/psych@cb50aa8 and ruby/psych@1764942).

On 008168c, we updated our code to allow instances of
`ActiveMerchant::Billing::Response`. However, as [noted in a
comment](solidusio@008168c#r73483078),
it seems we're missing, at least, instances of
`ActiveSupport::TimeWithZone`.

We need to add all classes used internally and leave a door open for
users to add their own classes (via a new `log_entry_permitted_classes`
preference).
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/psych_allowed branch from f3a5a62 to c8e274f Compare May 19, 2022 10:10
By default, `YAML.safe_load` won't allow YAML aliases to be parsed.
However, we need them at least for older versions of serialized
`ActiveSupport::TimeWithZone`.

We add a configuration option so that users can still disable it.
Depending on the source of the YAML, parsing aliases could open gates to
entity expansion attacks (a DoS created by nesting self-references).
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/psych_allowed branch from c8e274f to 256bf7c Compare May 20, 2022 03:09
@waiting-for-dev waiting-for-dev merged commit 455754b into solidusio:master May 20, 2022
@waiting-for-dev waiting-for-dev deleted the waiting-for-dev/psych_allowed branch May 20, 2022 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants