Skip to content

Commit cb449fa

Browse files
Update file-upload.md for secured FileTypeValidator
New version of the FileTypeValidator implemented in nestjs/nest#14881 no longer has a limitation that the file contents are removed. This updates the documentation to match.
1 parent db63134 commit cb449fa

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

content/techniques/file-upload.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ export abstract class FileValidator<TValidationOptions = Record<string, any>> {
131131
`FileValidator` is a regular class that has access to the file object and validates it according to the options provided by the client. Nest has two built-in `FileValidator` implementations you can use in your project:
132132

133133
- `MaxFileSizeValidator` - Checks if a given file's size is less than the provided value (measured in `bytes`)
134-
- `FileTypeValidator` - Checks if a given file's mime-type matches the given value.
135-
136-
> warning **Warning** To verify file type, [FileTypeValidator](https://github.com/nestjs/nest/blob/master/packages/common/pipes/file/file-type.validator.ts) class uses the type as detected by multer. By default, multer derives file type from file extension on user's device. However, it does not check actual file contents. As files can be renamed to arbitrary extensions, consider using a custom implementation (like checking the file's [magic number](https://www.ibm.com/support/pages/what-magic-number)) if your app requires a safer solution.
134+
- `FileTypeValidator` - Checks if a given file's mime-type matches a given string or RegExp. By default, validates the mime-type using file content [magic number](https://www.ibm.com/support/pages/what-magic-number)
137135

138136
To understand how these can be used in conjunction with the aforementioned `FileParsePipe`, we'll use an altered snippet of the last presented example:
139137

0 commit comments

Comments
 (0)