jsonlint (@mapbox/jsonlint-lines-primitives
) overwrites parsed objects' prototypes, confusing getType()
#1029
Labels
bug
Something isn't working
From #1025
Describe the bug
The
@mapbox/jsonlint-lines-primitives
package's parser performs an assignment when populating object's values, instead of callingObject.defineProperty
as per the ECMAScript standard'sJSON.parse()
spec. As a result, an object can change its own prototype (note: it can NOT pollute the global object prototype!), after which e.g.instanceof String
can returntrue
for object values.The most visible effect is that validation returns a validation error for objects that would be valid, but are miscategorized as e.g.
number
s. If used in a field which is only validated to be a specific type. e.g. urls and other strings, this allows objects of the wrong type to pass to validation, for example thissource
:An example of an object failing validation due to type confusion:
causes
To Reproduce
Steps to reproduce the behavior:
Try validating the source JSON above, or launch Node's REPL in the repo and try:
Expected behavior
Parsing the style JSON should not allow objects to alter their own prototypes.
Additional context
I opened this issue here, because the package appears abandoned.
We could:
The issue stems from these additional lines in the parser's grammar:
https://github.com/mapbox/jsonlint/blob/e31b7289baedf3e1000d7ae7edd42268212c9954/src/jsonlint.y#L84-L89
As you can see, it assigns directly to the produced object instead of using
Object.defineProperty
, and thus__proto__
can be modified (as couldconstructor
). This could be fixed with the following patch:The text was updated successfully, but these errors were encountered: