8000 Fix up validation of marshaled data when fields is given. by dereuromark · Pull Request #18324 · cakephp/cakephp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 5.x
Choose a base branch
from

Conversation

dereuromark
Copy link
Member
@dereuromark dereuromark commented Apr 13, 2025

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, the strictFields bool flag would have to be switched on for this behavior.

Alternative names maybe:

  • validateOnlyFields
  • validateFieldList

@dereuromark dereuromark added this to the 5.2.2 milestone Apr 13, 2025
@dereuromark
Copy link
Member Author

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 a fieldList but the request data contains field outside of the allowed field list, and the additional fields also contain invalid data?

@dereuromark
Copy link
Member Author

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 markstory modified the milestones: 5.2.2, 5.2.3 Apr 18, 2025
@dereuromark dereuromark changed the title Fix 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
Member Author

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
Member Author

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.

Copy link
Member Author

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?

@markstory markstory modified the milestones: 5.2.3, 5.2.4 Apr 24, 2025
@markstory markstory modified the milestones: 5.2.4, 5.2.5 May 17, 2025
@dereuromark dereuromark marked this pull request as draft May 31, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0