aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2011-10-18 17:03:48 -0700
committerIgor Minar2011-11-30 11:17:22 -0500
commitfe633dd0cf3d52f84ce73f486bcbd4e1d3058857 (patch)
tree14e432c43b01305cf8dffeb87f3614e3207e373e
parentfdcc2dbfd37d14ca5f3c830b589c091611ab54bd (diff)
downloadangular.js-fe633dd0cf3d52f84ce73f486bcbd4e1d3058857.tar.bz2
fix($http): allow multiple json vulnerability prefixes
We strip out both: )]}', )]}'
-rw-r--r--src/service/http.js3
-rw-r--r--test/service/httpSpec.js10
2 files changed, 12 insertions, 1 deletions
diff --git a/src/service/http.js b/src/service/http.js
index f06b88fd..3b207a13 100644
--- a/src/service/http.js
+++ b/src/service/http.js
@@ -65,7 +65,8 @@ function $HttpProvider() {
// transform in-coming reponse data
transformResponse: function(data) {
if (isString(data)) {
- if (/^\)\]\}',\n/.test(data)) data = data.substr(6);
+ // strip json vulnerability protection prefix
+ data = data.replace(/^\)\]\}',?\n/, '');
if (/^\s*[\[\{]/.test(data) && /[\}\]]\s*$/.test(data))
data = fromJson(data, true);
}
diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js
index ad83bdf8..b39ac3d7 100644
--- a/test/service/httpSpec.js
+++ b/test/service/httpSpec.js
@@ -743,6 +743,16 @@ describe('$http', function() {
expect(callback).toHaveBeenCalledOnce();
expect(callback.mostRecentCall.args[0]).toEqual([1, 'abc', {foo:'bar'}]);
});
+
+
+ it('should deserialize json with security prefix ")]}\'"', function() {
+ $httpBackend.expect('GET', '/url').respond(')]}\'\n\n[1, "abc", {"foo":"bar"}]');
+ $http({method: 'GET', url: '/url'}).on('200', callback);
+ $httpBackend.flush();
+
+ expect(callback).toHaveBeenCalledOnce();
+ expect(callback.mostRecentCall.args[0]).toEqual([1, 'abc', {foo:'bar'}]);
+ });
});