Skip to content

Commit fe633dd

Browse files
vojtajinaIgorMinar
authored andcommitted
fix($http): allow multiple json vulnerability prefixes
We strip out both: )]}', )]}'
1 parent fdcc2db commit fe633dd

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/service/http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function $HttpProvider() {
6565
// transform in-coming reponse data
6666
transformResponse: function(data) {
6767
if (isString(data)) {
68-
if (/^\)\]\}',\n/.test(data)) data = data.substr(6);
68+
// strip json vulnerability protection prefix
69+
data = data.replace(/^\)\]\}',?\n/, '');
6970
if (/^\s*[\[\{]/.test(data) && /[\}\]]\s*$/.test(data))
7071
data = fromJson(data, true);
7172
}

test/service/httpSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,16 @@ describe('$http', function() {
743743
expect(callback).toHaveBeenCalledOnce();
744744
expect(callback.mostRecentCall.args[0]).toEqual([1, 'abc', {foo:'bar'}]);
745745
});
746+
747+
748+
it('should deserialize json with security prefix ")]}\'"', function() {
749+
$httpBackend.expect('GET', '/url').respond(')]}\'\n\n[1, "abc", {"foo":"bar"}]');
750+
$http({method: 'GET', url: '/url'}).on('200', callback);
751+
$httpBackend.flush();
752+
753+
expect(callback).toHaveBeenCalledOnce();
754+
expect(callback.mostRecentCall.args[0]).toEqual([1, 'abc', {foo:'bar'}]);
755+
});
746756
});
747757

748758

0 commit comments

Comments
 (0)