validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Incomplete validation of the MediaType in isDataURI function

Open qmisslin opened this issue 3 years ago • 3 comments

Description of the problem

The isDataURI function is used to check a Data URI in base64, including the MediaType, Attribute and Data.

The regular expression validating the MediaType is the following:

/^[a-z]+\/[a-z0-9\-\+]+$/i;

However, the latter does not include the "." character which is sometimes present in MediaType, for example in the MIME of Excels files: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Proposed solution

To correct this problem, we would have to correct this regular expression to include the dot, here is a proposed solution that works for my use case:

/^[a-z]+\/[a-z0-9\-\+\.]+$/i

It is then enough to modify the code of the file "\node_modules\validator\lib\isDataURI.js" as follows:

validMediaType = /^[a-z]+\/[a-z0-9\-\+\.]+$/i;

Additional context Validator.js version: v13.7.0 Node.js version: v16.13.1

qmisslin avatar May 18 '22 14:05 qmisslin

Can i work on this?

samilieberman avatar Jul 05 '22 22:07 samilieberman

For sure!

WikiRik avatar Jul 05 '22 22:07 WikiRik

Hi @WikiRik,

Ended up working on another issue and just put up the PR: https://github.com/validatorjs/validator.js/pull/1998

Thank you, Sami

samilieberman avatar Jul 05 '22 23:07 samilieberman

I am working on this issue. Will be raising a PR soon.

meeraj257 avatar Sep 27 '22 17:09 meeraj257

Hi all,

this has been fixed with PR #1916 already, which has been merged into master since April.

pano9000 avatar Dec 06 '22 13:12 pano9000

Thank you all for your contribution and for the fix !

qmisslin avatar Dec 07 '22 12:12 qmisslin