-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Validator::valid() returning unvalidated fields #55755
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
Comments
I also want add why this behaviour might be a problem: class Foobar extends Model
{
protected $fillable = ['metadata'];
protected $casts = ['metadata' => 'array'];
} Then I want to save something to it from my frontend: // FoobarController.php
public function saveMetadata(Request $req, Foobar $foo)
{
$validation = \Validator::make(['metadata' => 'required|array', 'metadata.serial_number' => 'required|string'], $request->all());
// Maybe I have some more custom Validation flow, and want to use my own Exception type
if ($validation->fails()) {
throw new FoobarValidationException($validation);
}
// Validation didn't fail, so we save the data
$foo->update($validation->valid());
return to_route('foo.index');
} Here, the user can now have injected arbitrary data into the nested fields of my |
Does Laravel documentation suggest |
In this section, |
No, you should be using |
I don't necessarily want |
Could you maybe also give some more explanation as to why this behaviour is expected? |
Laravel Version
12.12.0
PHP Version
8.4.7
Database Driver & Version
No response
Description
Expected Behaviour
Validator::valid()
returns all validated valid fields likeValidator::validate()
/Validator::validated()
, without throwing\Illuminate\Validation\ValidationException
Actual Behaviour
Validator::valid()
returns fields that are not explicitly invalid by an existing rule as in:Steps To Reproduce
The text was updated successfully, but these errors were encountered: