Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] Add SanitizeDenormalizer for automatic sanitization#62117

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
momito69 wants to merge9 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
frommomito69:sanitize-denormalizer

Conversation

@momito69
Copy link
Contributor

@momito69momito69 commentedOct 20, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix ##61967
LicenseMIT

This pull request introduces a new feature to the SymfonySerializer component:Automatic sanitization of string and array of string properties during deserialization, using the newSanitizeDenormalizer.

As it is already done in the Form Component, for a property to be sanitized, you must add thesanitize_html option in the#[Context] attribute of that specific property. Without this option, the property will not be sanitized.
On the top of this if you need to sanitize with a particular sanitizer you can use the second optionsanitizer to set the sanitizer you want to use, by default we use the default sanitizer.

Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

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

This PR misses the integration of this feature in FrameworkBundle.

…g and update usage across denormalizer and tests
@momito69momito69 changed the title[Serializer] Add Sanitize attribute and SanitizeDenormalizer for auto…[Serializer] Add SanitizeDenormalizer for automatic sanitizationOct 25, 2025
Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

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

Note that support for scalar normalizers is currently broken in ObjectNormalizer, so you should probably wait for#58473 to be merged first.

Anyway, this PR will be for 8.1, not for 7.4 (as the feature freeze for 7.4 and 8.0 was beginning of October)

momito69 reacted with thumbs up emoji
->tag('serializer.normalizer', ['built_in' =>true,'priority' => -915])

->set('serializer.denormalizer.sanitize', SanitizeDenormalizer::class)
->args([service('service_container')])
Copy link
Member

Choose a reason for hiding this comment

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

injecting the main DI container is a no-go. It should inject a service locator with the html sanitizer services instead (the main DI container won't be able to get those services anyway as they are not public)

->set('serializer.normalizer.number', NumberNormalizer::class)
->tag('serializer.normalizer', ['built_in' =>true,'priority' => -915])

->set('serializer.denormalizer.sanitize', SanitizeDenormalizer::class)
Copy link
Member

Choose a reason for hiding this comment

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

this denormalizer needs to be removed from the config when the html-sanitizer component is not enabled (see how we handle other cross-component features in FrameworkExtension).

continue;
}

foreach ($property->getAttributes(Context::class)as$attribute) {
Copy link
Member

Choose a reason for hiding this comment

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

This does not make any sense. You should read$context, not read attributes again on your own (this defeats all the benefits I listed in my previous review related to caching metadata or supporting all metadata formats)

returnfalse;
}

if (!class_exists($type)) {
Copy link
Member

Choose a reason for hiding this comment

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

In my previous review, I asked for this serializer to be a serializer applied on the string, not applied at the object level.


foreach ($reflection->getProperties()as$property) {
$name =$property->getName();
if (!isset($data[$name])) {
Copy link
Member

Choose a reason for hiding this comment

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

this is broken as it forgets about the support of many advanced features of the ObjectNormalizer (name converters, serialized names, etc...).
This is again something that would be solved automatically once you stop processing the object-level data in that normalizer in favor of making it a proper scalar normalizer.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

3 participants

@momito69@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp