default to true in JSON.decode to avoid eval()#2562
Conversation
|
This would break BC. I suppose the sensible option is to put secure on, and allow them to turn it off when they trust the source. You'll need to supply, though, an entry in the 1.4compat layer, and spec coverage that checks:
|
Source/Utilities/JSON.js
Outdated
There was a problem hiding this comment.
if (secure == undefined) secure = true;
There was a problem hiding this comment.
Actually:
if (secure == null) secure = true;|
Very nice input! Thanks, will fix. @ibolmo: about Will make some specs for this also following your suggestions. |
|
|
|
Right I meant the following:
But since we'll add a
|
|
@ibolmo the So if we add I'm ok with adding it. Also ok with leaving it out (i.e not adding |
|
If you do On Fri, Feb 21, 2014 at 4:18 PM, Sergio Crisostomo <notifications@github.com
|
|
@ibolmo , thanks for your time checking this! 1- Adding both 2- Adding just 3- Using as it is now, in the PR. ( and the right one in my logic) JSON.secure seems to be kind of a backdoor/alternative, not documented. |
Even if it's undocumented, we've had people use undocumented interfaces and On Sat, Feb 22, 2014 at 1:19 AM, Sergio Crisostomo <notifications@github.com
|
|
@ibolmo I think I figured it out now with the compat layer. I added a compat layer, and with that I also removed future reference to JSON.secure without the compat. Let me know if it looks ok. |
Source/Utilities/JSON.js
Outdated
There was a problem hiding this comment.
if (secure == null) secure = JSON.secure;
You need to define JSON.secure = true; outside JSON.decode
There was a problem hiding this comment.
and document JSON.secure as a global option.
There was a problem hiding this comment.
@ibolmo I like the idea to have a documented global JSON.secure, didn't think of that option actually.
We could just keep the code as current PR and document the possibility to use a global JSON.secure.
Your last suggestion would make JSON.secure be ignored if secure is false, because if (secure == null) will turn false and we have a new L78 just looking for secure.
As it is it defaults to secure. If we add extra JSON.secure = true; as global, then the old code that followed the docs using secure = false will be forced to secure.
If we keep this PR, there is no break of BC in the code that active defined secure or JSON.secure.
|
@ibolmo I was misunderstanding the compat layer's behaviour. I updated the PR code and docs now. |
Specs/1.5base/Utilities/JSON.js
Outdated
There was a problem hiding this comment.
Could you check the spacing. Looks like you have spaces at the beginning of the lines.
Also can you add a spec for JSON.secure global option.
|
This PR has to be refactored after Olmo's new Specs PR is merged. |
|
Do a git rebase -i ibolmo/master On Tue, Feb 25, 2014 at 1:42 AM, Sergio Crisostomo <notifications@github.com
|
|
@ibolmo will do that. I see also a new directory structure without I run the specs adding my new JSON.js specs to the one on JSON.js specs file from your repo and they worked good with grunt. |
|
Yeah you have the right idea. On Tue, Feb 25, 2014 at 8:59 AM, Sergio Crisostomo <notifications@github.com
|
|
@ibolmo updated the PR with new master. |
|
@ibolmo could you merge or give your 👍 on this? would be nice to get this into 1.5 also to avoid |
Docs/Utilities/JSON.md
Outdated
There was a problem hiding this comment.
(*boolean*, optional: defaults to true)
|
One little gotcha, but yep it's 👍 |
Make the secure parameter default to true, to avoid using eval() as
default.
I supose this is better than having eval() as the default parser
This was commented both on Stackoverflow and mootools.net/comments
http://mootools.net/docs/core/Utilities/JSON#comment-1157192420