{}&& JSON Prefix and firebug

474 views
Skip to first unread message

pehm...@gmail.com

unread,
Aug 31, 2014, 4:25:19 PM8/31/14
to fir...@googlegroups.com
Prefixing the JSON string in this manner is used to help prevent JSON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. However firebug does not seem to be able to evaluate it as JSON neither because firebug isn't creating the JSON tab for these kind of responses. Is this a bug, a feature or a defect?

Would it be possible that when the returned JSON has {}&& prefix it would work the same way like it doesn't have it, just cutting it out?

Simon Lindholm

unread,
Sep 1, 2014, 2:43:35 PM9/1/14
to fir...@googlegroups.com
We do some forms of such JSON prefix stripping, but not for {}&&. See https://github.com/firebug/firebug/blob/master/extension/content/firebug/lib/json.js. Is "{}&&" a common standard?

pehm...@gmail.com

unread,
Sep 2, 2014, 5:01:32 PM9/2/14
to fir...@googlegroups.com

Alexandre Morgaut

unread,
Sep 3, 2014, 9:22:52 AM9/3/14
to fir...@googlegroups.com
It looks to be a weird standard then as prefixing a JSON message with "{}&&" will make it invalid regarding the JSON specification

"&&" isn't accepted in neither:
- the original JSON spec (http://json.org/
- the proposed IETF RFC version (http://tools.ietf.org/html/rfc7159)

The fact such invalid JSON message may work with some JSON parse implementations give absolutely no guaranty it will work in everyones, nor it will still work in future editions of those parsers

The safer way to protect JSON messages from JSON hijacking is to never send raw Arrays but embed them into an object

//wrong
["foo","bar","baz"]

//right
{"data":["foo","bar","baz"]}

Alexandre Morgaut

unread,
Sep 3, 2014, 9:26:11 AM9/3/14
to fir...@googlegroups.com
A simple test on http://jsonlint.com shows an error

{}&&["foo","bar,"baz"]

=>
Parse error on line 3:
{    }&&[    "foo",    "
------^
Expecting 'EOF', '}', ',', ']'

Le mardi 2 septembre 2014 23:01:32 UTC+2, pehm...@gmail.com a écrit :

pehm...@gmail.com

unread,
Sep 3, 2014, 10:36:22 AM9/3/14
to fir...@googlegroups.com
It's not really _a JSON_ standard, it's more of securing the JSON, as it says "The prefix renders the string syntactically invalid as a script so that it cannot be hijacked". IBM is also using this in some of its products. Support for it would be pretty simple. Just adding these lines:
   if (jsonString.length > 4 && jsonString.substring(0, 4) == "{}&&") {
       jsonString
= jsonString.substring(4);
   
}
in https://github.com/firebug/firebug/blob/master/extension/content/firebug/lib/json.js line 24

Alexandre Morgaut

unread,
Sep 3, 2014, 12:00:45 PM9/3/14
to fir...@googlegroups.com
Sure in this regard, Firebug code looks to already filter JSON strings before parsing it, so adding a filter if widely used may make sense.

Note that in your spring documentation, "{}&&" is a default prefix that may be customized. Maybe the additional filter should be based on a configurable list of prefix that would include "{}&&" by default

Alexandre Morgaut

unread,
Sep 3, 2014, 12:03:09 PM9/3/14
to fir...@googlegroups.com


Le mercredi 3 septembre 2014 18:00:45 UTC+2, Alexandre Morgaut a écrit :
Note that in your spring documentation, "{}&&" is a default prefix that may be customized. Maybe the additional filter should be based on a configurable list of prefix that would include "{}&&" by default


Sorry I misread it
The parameter is a boolean so there is only one prefix value possible in this framework 
Reply all
Reply to author
Forward
0 new messages