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

Fix up validation of marshaled data when fields is given.#18324

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

Draft
dereuromark wants to merge3 commits into5.next
base:5.next
Choose a base branch
Loading
from5.x-validate-fields

Conversation

dereuromark
Copy link
Member

@dereuromarkdereuromark commentedApr 13, 2025
edited
Loading

One idea on how to solve the issue of#18232

Reasoning:
When fields are given, one usually does that for security reasons, so not to allow other fields to be touched (e.g. role_id by injecting that into the post data).
Now when that field then gets validated along with it, it undermines the idea behind using the fields config, and as such people stop using it, making the application overall less secure.
So it is vital that we only allow patching (and that includes validation) of fields that are in that list if passed along.

Also, if you are not setting those other fields (into the entity), having them in the payload should just ignore them instead of acting on them as well.

That said:
It would break existing code, e.g. fields you want to validated but not stored in entity (e.g. checkbox for "accept terms and conditions").
So to keep things safe, thestrictFields bool flag would have to be switched on for this behavior.

Alternative names maybe:

  • validateOnlyFields
  • validateFieldList

@dereuromarkdereuromark added this to the5.2.2 milestoneApr 13, 2025
@dereuromark
Copy link
MemberAuthor

I cannot reproduce the fails locally, not sure whats going on here.

@markstory
Copy link
Member

When fields are given, one usually does that for security reasons, so not to allow other fields to be touched (e.g. role_id by injecting that into the post data).
Now when that field then gets validated along with it, it undermines the idea behind using the fields config, and as such people stop using it, making the application overall less secure.
So it is vital that we only allow patching (and that includes validation) of fields that are in that list if passed along.

Is the scenario here that a patch/save operation has afieldList but the request data contains field outside of the allowed field list, and the additional fields also contain invalid data?

dereuromark reacted with thumbs up emoji

@dereuromark
Copy link
MemberAuthor

It is mainly also the requirePresence rule that fires too harshly, so even if you don't provide them they could invalidate I guess.

markstory reacted with thumbs up emoji

@markstorymarkstory modified the milestones:5.2.2,5.2.3Apr 18, 2025
@dereuromarkdereuromark changed the titleFix up validation of marshalled data when fields is given.Fix up validation of marshaled data when fields is given.Apr 19, 2025
* @return array<array> Array of failed fields
*/
public function validate(array $data, bool $newRecord = true): array
public function validate(array $data, bool $newRecord = true, array $fields = []): array
Copy link
Member

Choose a reason for hiding this comment

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

The public API can't be changed in 5.x

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We can go 5.next

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

For now this is just to get the feel if there is a better way to do this, what strategy to use and naming for the feature flag / config.

Copy link
Member

Choose a reason for hiding this comment

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

We can go 5.next

We can't do breaking changes even in a new minor. Changing the public method would cause an error if it's overridden. We don't give BC guarantee for only protected overridden methods in minors.

markstory reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Any other ideas we can do to mitigate in 5.x? Until a solution can be found for 6.x?

@markstorymarkstory modified the milestones:5.2.3,5.2.4Apr 24, 2025
@markstorymarkstory modified the milestones:5.2.4,5.2.5May 17, 2025
@dereuromarkdereuromark marked this pull request as draftMay 31, 2025 18:20
@markstorymarkstory modified the milestones:5.2.5,5.2.6Jun 21, 2025
@dereuromark
Copy link
MemberAuthor

I didnt get any feedback on this since April.
How can we proceed here, is the general consensus that we want to fix this for 5.next?

We can't do breaking changes even in a new minor. Changing the public method would cause an error if it's overridden. We don't give BC guarantee for only protected overridden methods in minors.

I dont think this is how it worked so far.
When it is about internal functionality, then the benefit of adding optional arguments outweighs any theoretical risks of overwriting probably.

So
a) Is this approach OK in general? or is there an alternative
b) If so, is this somehow possible to target 5.next or should this be addressing 6.0 then?

@dereuromark
Copy link
MemberAuthor

I propose context (#18769 ) of being merged (first).
And thenfields could just be another key on that context to be used down the line.
Same with any other topic that comes up in the future.

A clear migration guide will minimize issue with extensions.

It should also be easy to rework by adding the additional things into that existing context then on userland side.

@dereuromarkdereuromark changed the base branch from5.x to5.nextJuly 18, 2025 14:56
@dereuromarkdereuromark modified the milestones:5.2.6,5.3.0Jul 18, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ADmadADmadADmad left review comments

Assignees
No one assigned
Labels
Projects
None yet
Milestone
5.3.0
Development

Successfully merging this pull request may close these issues.

3 participants
@dereuromark@markstory@ADmad

[8]ページ先頭

©2009-2025 Movatter.jp