-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
make returning plain objects and allowing prototype overwriting properties optional #98
Conversation
To me, this seems to make the situation potentially worse, especially for user-confusion, because of the following not being the same:
Can there be an option to use the default prototype and just overwrite properties, even if it's something you have to opt into? |
lol, please ignore my above comment, as it was technically only based off reading the source code. I see there is |
|
So I had made that comment in haste :) Let me really look through it to see what real comments I have :) |
Looks fine to me. Can't make everyone happy and I really don't care about prototype names in payload. This is JS. You are fucked anyway you look at it. |
Ok, so this PR seems fine in general. My only real comment is that I don't think the global environment should affect the functionality of the library:
JSON.parse and the built-in query string does not have this issue, though:
|
That would be resolved by exchanging |
Ok, changed this around so instead of optionally adding a prefix to properties that would overwrite the object prototype it instead optionally lets you shoot yourself in the foot, just like JSON.parse. It's off by default, but it's there. |
make returning plain objects and allowing prototype overwriting properties optional
This is only breaking when using |
this reverts the breaking change made in 3.x, so it's in itself another breaking change, though odds are if you don't use any of the prototype stuff on parsed results you'll never notice. |
ok, thanks for the explanation |
// { a: { hasOwnProperty: 'b' } } | ||
``` | ||
|
||
By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties. *WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth to explicitly note this is a security risk.
this is a short term solution before 5.0.0 which will change everything. Essentially the default behavior will match the 2.x releases, with the difference that you may set the
plainObjects
option totrue
to get the behavior from the 3.x releases.If you don't want plain objects but also don't want to lose keys that would overwrite prototype properties, you can set the
prefixPrototypes
option totrue
and those keys will be prefixed with an underscore'_'
and passed along. It's not perfect, but at least the keys aren't silently ignored.Would appreciate your feedback on this one @hueniverse @dougwilson