javascript - Is there any XSS threat while having JSON encoded in the URL? -


In the context of a URL-friendly application I am saving it, there is a JSON in the URL, Is:

  http://mysite.dev/myapppage/target#?context= {22attr1% 22% 3A {% 22target_id- 0% 22% 3a {% 22value% 22% 3a% 223% 22% 2c% I am serializing my object like this:  
: "" {{"value": "3", "label": "hello"} }}   

JSON.stringify (context)

I am deserializing with it:

  Var hashpairhead elements = window.location.toString (). Partition () '?'; HashParamsEl Ements.shift (); // We just leave the first part of the url var hash para = $ .deparam (hash paraellets.joined ('?')); Var reference string = hashprom.context; var reference = JSON.parse (ContextString);   

The reference is stored only to read the variable, there is no evaluation code, can anyone tell me whether this XML is safe or not?

If there is a danger: how can I avoid it?

This type of threat is caused by various methods of JSON decoding, i.e. eval and < Code> New Function . These execute the JS code directly and therefore allow non-permanent XSS attacks by adding code to the URL (and adding it).

JSON.parse This problem is not and is protected against these types of attacks.



Comments