nativescript-community / https

Secure HTTP client with SSL pinning for Nativescript - iOS/Android
https://nativescript-community.github.io/https/
Other
50 stars 42 forks source link

Different JSON array format on iOS response #11

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi! when my request return response, JSON arrays format is different that I expect, this is the format I want: JSON: {array:["one", "two", "three"]}

Response I have:

JSON: {array:("one", "two", "three")}

brackets for array are normal brackets instead of square brackets... what's wrong?

roblav96 commented 7 years ago

@dgma was this on iOS?

davidpronk commented 7 years ago

The same issues occurs when I run on iOS < 10. The JSON data is supposed to be an array but on iOS 8 and 9 it is within parenthesis. @dgma have you managed to solve this, or @roblav96 do you have more info on this?

ghost commented 7 years ago

@davidpronk yes I found that something was wrong when parsing JSON, that was solved on this github repo but I don't know why when you install this plugin, all the code its so different, so I replace all code found here on my plugin installed, hope can help https://github.com/gethuman/nativescript-https/blob/master/https.ios.ts

davidpronk commented 7 years ago

In turns out my issue was caused by the JSON being returned by the API. iOS < 10 improperly handles [{"foo": "bar"}] where it does know how to handle {"data": [{"foo": "bar"}]} even though an array is valid JSON.

bguijt commented 7 years ago

The fork by @cbellone seems to have fixed this problem - see https://github.com/cbellone/nativescript-https/compare/89443e50d51c9aac51e3b7914921a1ed92b1480a...cbellone:004f2bfb414fa6cb9914db45dd817acbbc2cd7fb

Johanneke commented 6 years ago

Actually, turns out this is a 'feature'. JSON Arrays are prone to a specific attack - see https://haacked.com/archive/2009/06/25/json-hijacking.aspx/