Uh oh!
There was an error while loading. Please reload this page.
querystring: allow querystring parse to handle __proto__ - #6044
Conversation
f9b4060 to
e0fb8ddComparemscdex
commented
Apr 4, 2016
If this change is going to be made, wouldn't it be simpler to just use |
jasnell
commented
Apr 4, 2016
Interesting... using 'use strict';varcommon=require('../common.js');varquerystring=require('querystring');varv8=require('v8');varbench=common.createBenchmark(main,{n: [1e6],});functionmain(conf){varn=conf.n|0;constinput='a=b&__proto__=1';v8.setFlagsFromString('--allow_natives_syntax');querystring.parse(input);eval('%OptimizeFunctionOnNextCall(querystring.parse)');querystring.parse(input);vari;bench.start();for(i=0;i<n;i+=1)querystring.parse(input);bench.end(n);} |
jasnell
commented
Apr 4, 2016
@mscdex ... updated to use Object.create(null). |
There was a problem hiding this comment.
Are we comfortable with this inconsistency?
mscdex
commented
Apr 4, 2016
FWIW using |
Fishrock123
commented
Apr 5, 2016
👎 Unless we can see that |
mscdex
commented
Apr 5, 2016
@Fishrock123 It still is. @jasnell I think I may have found a solution that doesn't cause a performance regression and may even provide somewhat of a performance boost. |
jasnell
commented
Apr 5, 2016
Sigh, every time I benchmark this I'm getting different results. I'll switch it back to {} for now. What's the alternative you found @mscdex ? |
Per nodejs#5642, using querystring.parse to parse 'a=b&__proto__=1' causes the `__proto__` to be swallowed and ignored. This works around the limitation by temporarily setting the prototype of the parsed obj to null during the parse, then setting it back before returning. Fixes: nodejs#5642
WebReflection
commented
Apr 5, 2016
since you never know how much optimization could be done, I'd go for: // beginvarobj=Object.setPrototypeOf({},null);// ... rest of the code ...// endreturnObject.setPrototypeOf(obj,Object.prototype);at least it couldn't go more compact than that, and the returned value from |
| return {}; | ||
| } | ||
| var obj = {}; |
There was a problem hiding this comment.
Sorry, had this open for a while and GH refreshed so I just now noticed this was already discussed.
Sinewyk
commented
Apr 5, 2016
Related: #6055 |
Pull Request check-list
make -j8 test(UNIX) orvcbuild test nosign(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
Affected core subsystem(s)
querystring
Description of change
Per #5642, using querystring.parse to parse
'a=b&__proto__=1'causes the__proto__to be swallowed and ignored. This works around the limitation by temporarily setting the prototype of the parsed obj to null during the parse, then setting it back before returning.The rest of the existing implementation remains the same.
Fixes: #5642
/cc @mscdex@WebReflection