Closed (fixed)
Project:
Drupal core
Version:
10.5.x-dev
Component:
configuration system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 May 2025 at 01:57 UTC
Updated:
10 Jul 2025 at 04:34 UTC
Jump to comment: Most recent
Comments
Comment #6
benjifisherComment #8
benjifisherI think it is all right to allow
stClass, but tests are passing with['allowed_classes' => FALSE], so let's at least consider that.Does this issue need a change record? If there are any contrib or custom modules that extend the
DatabaseStorageclass, and they need to allow other classes inunserialize(), then the good news is that they can easily override thedecode()method, which is nowComment #9
benjifisherComment #10
smustgrave commentedI see there is one more @unserialize is that impacted?
Comment #11
benjifisherThis issue is scoped to the Config system, and I think there is only one:
Did I miss something or are you thinking of something outside the Config system?
Comment #12
smustgrave commentedNo just saw this other instance and didn't know if it had the same problem.
Comment #13
benjifisherThen I guess you mean the usage in the
dblogmodule:The
@just tells PHP to ignore errors fromserialize(): see Error Control Operators in the PHP docs. There are many other calls toserialize()in Drupal core.In the long run, we should switch to using
json_encode()andjson_decode()(or the equivalent methods inDrupal\Component\Serialization\Json) whenever possible instead ofserialize()andunserialize(). In the short run, it is less disruptive to specifyallowed_classes.Comment #14
benjifisherComment #15
smustgrave commentedNot 100% how else to test so am relying on tests, which are green. Locally nothing seems broken so going to go on a limb
Comment #16
alexpottConfig explicitly errors if you try to add an object. See \Drupal\Core\Config\StorableConfigBase::validateValue - any non scalar value we cause an exception.
Comment #19
alexpottCommitted and pushed 4cfe1582b8b to 11.x and e6a220a7ebd to 11.2.x and b5eb5d74aab to 10.6.x and 45ca12eacc1 to 10.5.x. Thanks!
Backported to 11.2.x and 10.5.x and 10.6.x as a very low risk security improvement given the code in
\Drupal\Core\Config\StorableConfigBase::validateValue().Comment #22
benjifisherJust to be sure I understand the comments:
Drupal\Core\Config\Config::save()callsvalidateValue()(both directly and indirectly, viacastValue()). That ensures that proper use of the config system protects against serializing anything other than nested arrays of scalar types.By "proper use", I mean that
save()is not called with the optional$has_trusted_dataparameter set toTRUE.I am a little worried that some custom or contrib code might use
$config_object->save(TRUE)in order to bypass this validation. Am I being too pessimistic?Comment #23
alexpott@benjifisher it still wouldn't work because not all config saves are made via their own API - eg. config import / module install / ConfigFormBase - you'd have an awful lot to override... and then you could not export your config because our yaml export does not support objects.
Comment #24
alexpott@benjifisher that said I think it would be more consistent to do:
Do you want to open an issue and implement?
Comment #25
benjifisher@alexpott:
I created the child issue #3532506: Never bypass basic validation when saving a config object.