Skip to content

data protection improvements#645

Open
unixslayer wants to merge 5 commits intoecotoneframework:mainfrom
unixslayer:data-protection
Open

data protection improvements#645
unixslayer wants to merge 5 commits intoecotoneframework:mainfrom
unixslayer:data-protection

Conversation

@unixslayer
Copy link
Member

@unixslayer unixslayer commented Mar 3, 2026

Why is this change proposed?

  • XML support in data protection
  • configure message protection when only property is annotated
  • handle changing property names with custom converters

Pull Request Contribution Terms

  • I have read and agree to the contribution terms outlined in CONTRIBUTING.


public function convert($source, Type $sourceType, MediaType $sourceMediaType, Type $targetType, MediaType $targetMediaType)
{
$data = XmlHelper::xmlToArray($source);
Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried to use ConversionService here but it does not support serialization between array and xml string loosing parameter names when converting array into xml.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't the #[Sensitive('someCustomName')] solving this?

Copy link
Member

Choose a reason for hiding this comment

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

class Person
{
       #[Sensitive("someName")]
       private string name
}

Or if this is about nesting e.g. <result><person><someName></someName></person></result>, so we do not know how to go into deeper nesting?

Because we could then provide nested structure attribute:

#[Nested(expression: "createArray('result', data)")]
class Person
{
       #[Sensitive("someName")]
       private string name
}

or eventually when we add support for functions (new php feature), that could be modified as needed:

#[Nested(expression: function($data) => ["result" => $data]]
class Person
{
       #[Sensitive("someName")]
       private string name
}

Copy link
Member Author

@unixslayer unixslayer Mar 5, 2026

Choose a reason for hiding this comment

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

DataProtectionConverter works around serialization on root level. Depending on configuration, not all of properties may need protection. Custom name passed with #[Sensitive] does not solve it as it's not for serialization. It only tells DataProtectionConverter that property name in serialization is different than property in actual object.

Also nested data is not a problem here because it does not matter. Data Protection works only for root and nested properties (non scalar) are always serialized to string. Consider following example:

class SomeMessage
{
    public function __construct(
        #[Sensitive] public SomeClass $sensitive,
        public string $property
    ) {
    }
}

class SomeClass
{
    public function __construct(
        public string $argumentA,
        public string $argumentB,
    ) {
    }
}

After serialization it will have nested structure:

[
    "sensitive" => [
        "argumentA" => "foo",
        "argumentB" => "bar",
    ],
    "property" => "baz",
]

Encryption will return following structure:

[
    "sensitive": "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=",
    "property": "baz"
]

Once encrypted, data has to be returned as XML. ConversionService returns following XML (handled by JMSConverter)

<?xml version="1.0"?>
<root>
    <entry>TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=</entry>
    <entry>baz</entry>
</root>

This is the reason why I introduced XMLHelper as JMS was not cooperative.

@unixslayer unixslayer requested a review from dgafka March 3, 2026 12:05
@unixslayer unixslayer changed the title XML support in data protection data protection improvements Mar 3, 2026
dgafka
dgafka previously approved these changes Mar 5, 2026

public function convert($source, Type $sourceType, MediaType $sourceMediaType, Type $targetType, MediaType $targetMediaType)
{
$data = XmlHelper::xmlToArray($source);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the #[Sensitive('someCustomName')] solving this?


public function convert($source, Type $sourceType, MediaType $sourceMediaType, Type $targetType, MediaType $targetMediaType)
{
$data = XmlHelper::xmlToArray($source);
Copy link
Member

Choose a reason for hiding this comment

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

class Person
{
       #[Sensitive("someName")]
       private string name
}

Or if this is about nesting e.g. <result><person><someName></someName></person></result>, so we do not know how to go into deeper nesting?

Because we could then provide nested structure attribute:

#[Nested(expression: "createArray('result', data)")]
class Person
{
       #[Sensitive("someName")]
       private string name
}

or eventually when we add support for functions (new php feature), that could be modified as needed:

#[Nested(expression: function($data) => ["result" => $data]]
class Person
{
       #[Sensitive("someName")]
       private string name
}

- move ext-simplexml into suggested as it is used in XML encryption
- forbid to use `#[Sensitive]` on both class and its properties
- cache classes with annotated properties
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.

2 participants