Skip to content
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

Sending an empty body will bypass the validation #10

Closed
Alexandre-Fernandez opened this issue Feb 21, 2023 · 6 comments
Closed

Sending an empty body will bypass the validation #10

Alexandre-Fernandez opened this issue Feb 21, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Alexandre-Fernandez
Copy link

Sending a POST request with an empty body will bypass the validation and still call the controller, even if your DTO has #[Assert\NotBlank] decorators. This is counter intuitive and can lead to bugs since the controller is expecting a filled DTO.

@sfmok sfmok added the bug Something isn't working label Feb 21, 2023
@sfmok
Copy link
Owner

sfmok commented Feb 21, 2023

I'm going to reproduce and push a fix soon. Thanks, @Alexandre-Fernandez to report it.

@sfmok
Copy link
Owner

sfmok commented Feb 21, 2023

@Alexandre-Fernandez I couldn't reproduce this issue. If you could provide me with these details that would be great

PHP version
RequestInputBundle version
Request ContentType
A snippet code of invocable or action controller

Meanwhile, I can see 4 ways to bypass resolving and validating the input argument:
RequestInputBundle is disabled (it's enabled by default)
skip_validation config option is enabled (it's disabled by default)
the input DTO class not implemented the interface "InputInterface"
the request content type is not one of the supported formats "application/json, application/xml, multipart/form-data"

@sfmok sfmok added On hold and removed bug Something isn't working labels Feb 22, 2023
@Alexandre-Fernandez
Copy link
Author

Alexandre-Fernandez commented Feb 22, 2023

I tried making a reproduction repository and after further testing it seems that this only happens when the Content-Type header is missing.
If possible it would be nice to still have an error for this such as ["title" => "Deserialization Failed", "detail" => "Wrong format"].
Atleast that's the behaviour I was expecting, if the DTO could not be parsed, be it because of wrong headers or something else, then the controller shouldn't be called.

@sfmok
Copy link
Owner

sfmok commented Feb 23, 2023

Thanks @Alexandre-Fernandez, You're right this is actually a bug. I will fix it and release a patch soon

@sfmok sfmok added bug Something isn't working and removed On hold labels Feb 23, 2023
@sfmok sfmok linked a pull request Feb 24, 2023 that will close this issue
@sfmok sfmok mentioned this issue Feb 24, 2023
sfmok pushed a commit that referenced this issue Feb 26, 2023
sfmok pushed a commit that referenced this issue Feb 26, 2023
sfmok pushed a commit that referenced this issue Feb 26, 2023
@sfmok
Copy link
Owner

sfmok commented Feb 26, 2023

Issue fixed.

throw UnsupportedMediaTypeHttpException in case Content-Type header is missing or unsupported.

@sfmok sfmok closed this as completed Feb 26, 2023
@Alexandre-Fernandez
Copy link
Author

great thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants