0
0
NestJSframework~5 mins

Whitelist and transform options in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the whitelist option do in NestJS validation?
The whitelist option removes any properties from the input object that are not explicitly defined in the DTO (Data Transfer Object). This helps keep only the allowed data and improves security.
Click to reveal answer
beginner
What is the purpose of the transform option in NestJS validation pipe?
The transform option automatically converts input data types to the types defined in the DTO classes. For example, it can convert a string to a number if the DTO expects a number.
Click to reveal answer
intermediate
How do whitelist and transform options work together in NestJS?
When both options are enabled, NestJS first removes unwanted properties (whitelist) and then converts the remaining data to the correct types (transform). This ensures clean and correctly typed input data.
Click to reveal answer
beginner
How do you enable whitelist and transform options globally in a NestJS app?
You enable them by passing options to the ValidationPipe in the main app file, like this:<br>
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
Click to reveal answer
intermediate
What happens if whitelist is false and extra properties are sent in a request?
If whitelist is false, extra properties not defined in the DTO remain in the input object. This can lead to unexpected data being processed or security risks.
Click to reveal answer
What does setting whitelist: true in NestJS ValidationPipe do?
AConverts input data types automatically
BAllows all properties without filtering
CDisables validation
DRemoves properties not in the DTO from the input
What is the effect of transform: true in NestJS ValidationPipe?
AAutomatically converts input types to DTO types
BBlocks all invalid requests
CRemoves extra properties
DLogs validation errors
How do you enable both whitelist and transform globally in NestJS?
Aapp.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }))
Bapp.useGlobalPipes(new ValidationPipe({ validate: true }))
Capp.useGlobalPipes(new ValidationPipe({ sanitize: true }))
Dapp.useGlobalPipes(new ValidationPipe({ enable: true }))
If whitelist is false, what happens to extra properties in the request?
AThey cause an error
BThey remain in the input object
CThey are removed
DThey are converted to null
Why is using whitelist important for security?
AIt disables validation
BIt speeds up the app
CIt prevents unwanted data from being processed
DIt encrypts the data
Explain how the whitelist and transform options improve data handling in NestJS validation.
Think about filtering and converting input data.
You got /3 concepts.
    Describe how to set up global validation in NestJS to use whitelist and transform options.
    Look at the main app bootstrap file.
    You got /3 concepts.