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

Add the option for ignoring the __proto__ property #7

Open
pashoo2 opened this issue Jun 4, 2015 · 7 comments
Open

Add the option for ignoring the __proto__ property #7

pashoo2 opened this issue Jun 4, 2015 · 7 comments

Comments

@pashoo2
Copy link

pashoo2 commented Jun 4, 2015

Can you do this?
It's very bad that JSON parses proto without any errors, it may cause a various bugs

@pashoo2 pashoo2 changed the title Add the option for ignoring a __proto__ property Add the option for ignoring the __proto__ property Jun 4, 2015
@bjouhier
Copy link
Owner

bjouhier commented Jun 4, 2015

How does the native JSON.parse function handle your case?

@pashoo2
Copy link
Author

pashoo2 commented Jun 4, 2015

JSON.parse does not worry about it) It need to handle manually and causes the performance issues. May be some people don't know about the proto property behaviour in the js and not handling this

@bjouhier
Copy link
Owner

bjouhier commented Jun 4, 2015

If JSON.parse does not do anything special then I would not do anything either. I want to stick to standard behavior. It's very unusual to have __proto__ into JSON feeds. It should be stripped by serialization.

Can I close?

@pashoo2
Copy link
Author

pashoo2 commented Jun 6, 2015

It's may used for any hacks. Many peoples use Object.keys for validation objects, that have been parsed by JSON, and as you know Object.keys does not returns properties from the proto

@pashoo2
Copy link
Author

pashoo2 commented Jun 6, 2015

"It's very unusual to have proto into JSON feeds. It should be stripped by serialization"
Yes it should be stripped by serialization, but if a malefactor has made a JSON string manually, a string will be parsed by JSON with the proto

@bjouhier
Copy link
Owner

bjouhier commented Jun 8, 2015

OK, I did a bit of research and I get it: JSON.parse does something special with __proto__ so that __proto__ does not become a magic prototype. The following are not equivalent:

o = JSON.parse('{ "__proto__": null }'); // o instanceof Object === true
o = { "__proto__": null } // o instanceof Object === false

So i-json should do the same.

@pashoo2
Copy link
Author

pashoo2 commented Jun 9, 2015

var oo ='{"prop1":"val1","__proto__" : { "hasOwnProperty":"true", "toString" : "ok" }}'; 
var jsO = JSON.parse(oo);
console.log(jsO.toString);

the result is "ok"

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