Skip to content

Release 1.13

Choose a tag to compare

@igorpocta igorpocta released this 27 Oct 21:55
· 47 commits to main since this release

What's Changed

Security Fixes

  • #[OutputOnly] / #[Ignore] bypass via constructor — a plain (non-promoted) constructor parameter assigned to
    a property in the constructor body was hydrated from input even when the property carried #[OutputOnly] or
    #[Ignore]:
    class UserDto {
        #[OutputOnly] public string $role;
        public function __construct(public string $name, string $role = 'user') { $this->role = $role; }
    }
    // {"name": "x", "role": "admin"} → $dto->role === 'admin'
    A constructor parameter is now excluded from input when the same-named property carries #[Ignore] or
    #[OutputOnly].
  • PHP 8.4 asymmetric visibility bypassed publicPropertiesOnly — public private(set) and
    public protected(set) properties (including promoted constructor parameters) were hydrated from input, because
    ReflectionProperty::isPublic() reports only read visibility. In public-only mode they are now treated as
    non-public for input (opt-in with #[MapProperty] still works) and remain in output. public readonly properties
    are hydrated as before.
  • publicPropertiesOnly and symmetricPropertyPaths did not apply to nested objects (introduced in 1.12) —
    nested objects and arrays of objects are (de)normalized by type handlers with their own Normalizer /
    shared Denormalizer, which never received the new options. With publicPropertiesOnly: true, private properties
    of nested DTOs still leaked to output and were hydrated from input
    ({"inner": {"secret": "HACKED"}}). Options are now propagated through TypeResolver to all nesting levels,
    including strict-mode unknown-key detection (inner.secret).

Bug Fixes

  • symmetricPropertyPaths silently dropped fields on key collisions — a plain property and a path sharing the
    same output location ($meta and #[MapProperty(path: 'meta.source')]), or two properties with the same path,
    overwrote each other depending on declaration order. Now throws LogicException naming the property and the
    output location (configuration error).
  • Index paths produced JSON objects instead of lists — #[MapProperty(path: 'items[1].name')] normalized to
    {"items": {"1": {...}}}. Missing lower indexes are now filled with null, so the output is a JSON list
    ({"items": [null, {...}]}), also when indexes are written out of order.
  • toCsv() with symmetricPropertyPaths wrote nested arrays into cells (Array to string conversion,
    literal Array). CSV output now always uses flat columns.
  • PropertyPathResolver::set() no longer overwrites an existing scalar when descending into it — throws
    InvalidArgumentException instead.

Behaviour Changes

  • Strict mode accepts #[OutputOnly] keys — they are part of the public contract, so posting a fetched
    resource back (PUT round-trip) no longer fails with Unknown key 'id'. The value is discarded, never hydrated.
    #[Ignore] and non-public keys (in public-only mode) are still reported as unknown. Applies to merge() too.
  • List input to fromArray() is rejected after PreDenormalizeEvent — listeners can now reshape list input
    (e.g. wrap it into an object) before validation, and the rejection dispatches DenormalizationErrorEvent like any
    other mapping error. PreDenormalizeEvent::$data and DenormalizationErrorEvent::$data are documented as
    array<mixed> (input is untrusted).
  • Excluded variadic constructor parameter (#[Ignore] string ...$tags) threw LogicException / received null.
    It now receives no arguments.

Performance

  • Visibility/direction decisions (PropertyVisibilityResolver) are memoized per class member instead of re-reading
    attributes via reflection on every mapping call: ~9 % faster normalization, ~20 % faster denormalization
    (20k objects, public-only + strict mode).
    Remaining overhead: Normalizer / Denormalizer still re-run reflection per object instead of using
    ClassMetadataFactory metadata — candidate for a follow-up refactor.