Skip to content

Strip/reject unexpect properties in Validation pipes or class-validator? #314

@VinceOPS

Description

@VinceOPS

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When submitting unexpected properties in the body of an HTTP request (POST/PUT endpoints), the validation pipe (using class-transformer and class-validator) allows it without sending any warning or allowing us to forbid this behavior.
I assume this is linked to typestack/class-validator#118

Expected behavior

When submitting {"name": "Fluffy Cat", "age": 15, "paws": 3} whereas the DTO is {name: string, age: number}, the property paws should be stripped or raise (in some way) a validation error.

What is the motivation / use case for changing the behavior?

Allowing developers to reject payloads with unexpected properties, just like Joi or AJV. This is especially dangerous for MongoDB users, who might store the provided input "as is".

Environment


Nest version: 4.5.1
 
For Tooling issues:
- Node version: 8.9+  
- Platform:  Linux 


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions