Skip to content

Commit e63d0a5

Browse files
committed
Fixed issue with double encoding urls
1 parent 5f32770 commit e63d0a5

File tree

10 files changed

+168
-30
lines changed

10 files changed

+168
-30
lines changed

.jshintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"noarg": true,
66
"noempty": true,
77
"nonew": true,
8-
"trailing": true,
8+
"trailing": false,
99
"maxlen": 512,
1010
"boss": true,
1111
"eqnull": false,
@@ -30,4 +30,4 @@
3030
"it": true,
3131
"should": true
3232
}
33-
}
33+
}

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-http-batcher",
3-
"version": "1.11.3",
3+
"version": "1.12.0",
44
"description": "Enables transparent HTTP batch requests with Angular",
55
"main": "dist/angular-http-batch.js",
66
"keywords": [

dist/ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
12/10/2015 V1.12.0
2+
Now handles multiple JSON Vulnerability Prefixes in same response
3+
Add unique request part names to Content-Disposition header for use with tomcat servlet 3.1
4+
Fix to stop multiple url encoding of query string parameters in http batch adapter
5+
16
27/08/2015 V1.11.3
27
Fixed error when trimming response to protect against JSON vulnerability error (pr by @magarcia https://github.com/magarcia)
38
Use encodeURI to process query strings with spaces and other such characters in default http adapter. (pr by https://github.com/tiwariarvin)

dist/angular-http-batch.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* angular-http-batcher - v1.11.3 - 2015-08-27
2+
* angular-http-batcher - v1.12.0 - 2015-10-12
33
* https://github.com/jonsamwell/angular-http-batcher
44
* Copyright (c) 2015 Jon Samwell
55
*/
@@ -29,7 +29,8 @@ function HttpBatchConfigFn() {
2929
ignoredVerbs: ['head'],
3030
sendCookies: false,
3131
enabled: true,
32-
adapter: defaultBatchAdapter
32+
adapter: defaultBatchAdapter,
33+
uniqueRequestName: null
3334
};
3435

3536
/**
@@ -203,7 +204,9 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) {
203204
singleSpace: ' ',
204205
forwardSlash: '/',
205206
doubleDash: '--',
206-
colon: ':'
207+
colon: ':',
208+
semiColon: ';',
209+
requestName: 'name='
207210
};
208211

209212
self.key = 'httpBatchAdapter';
@@ -231,7 +234,7 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) {
231234
headers: config.batchRequestHeaders || {}
232235
},
233236
batchBody = [],
234-
urlInfo, i, request, header;
237+
urlInfo, i, request, header, relativeUrlParts, encodedRelativeUrl;
235238

236239
httpConfig.headers[constants.contentType] = 'multipart/mixed; boundary=' + boundary;
237240

@@ -242,13 +245,24 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) {
242245
batchBody.push(constants.doubleDash + boundary);
243246
if (config.batchPartRequestHeaders) {
244247
for (header in config.batchPartRequestHeaders) {
245-
batchBody.push(header + constants.colon + constants.singleSpace + config.batchPartRequestHeaders[header]);
248+
if (config.batchPartRequestHeaders.hasOwnProperty(header)) {
249+
var currHeader = header + constants.colon + constants.singleSpace + config.batchPartRequestHeaders[header];
250+
if (header.toLowerCase() === "content-disposition" && config.uniqueRequestName !== null && config.uniqueRequestName !== undefined) {
251+
currHeader += constants.semiColon + constants.singleSpace + constants.requestName + config.uniqueRequestName + i;
252+
}
253+
batchBody.push(currHeader);
254+
}
246255
}
247256
}
248257

249258
batchBody.push('Content-Type: application/http; msgtype=request', constants.emptyString);
250259

251-
batchBody.push(request.method + ' ' + encodeURI(urlInfo.relativeUrl) + ' ' + constants.httpVersion);
260+
// angular would have already encoded the parameters *if* the dev passed them in via the params parameter to $http
261+
// so we only need to url encode the url not the query string part
262+
relativeUrlParts = urlInfo.relativeUrl.split('?');
263+
encodedRelativeUrl = encodeURI(relativeUrlParts[0]) + (relativeUrlParts.length > 1 ? '?' + relativeUrlParts[1] : '');
264+
265+
batchBody.push(request.method + ' ' + encodedRelativeUrl + ' ' + constants.httpVersion);
252266
batchBody.push('Host: ' + urlInfo.host);
253267

254268
for (header in request.headers) {
@@ -365,18 +379,30 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) {
365379
function findResponseBoundary(contentType) {
366380
var boundaryText = 'boundary=',
367381
startIndex = contentType.indexOf(boundaryText),
368-
boundary = contentType.substring(startIndex + boundaryText.length);
382+
endIndex = contentType.indexOf(';', startIndex),
383+
boundary = contentType.substring(startIndex + boundaryText.length, endIndex > 0 ? endIndex : contentType.length);
369384

370385
// the boundary might be quoted so remove the quotes
371386
boundary = boundary.replace(/"/g, constants.emptyString);
372387
return boundary;
373388
}
374389

390+
/**
391+
* see https://docs.angularjs.org/api/ng/service/$http#json-vulnerability-protection
392+
* @param data
393+
* @returns {*|void|string}
394+
*/
395+
function trimJsonProtectionVulnerability(data) {
396+
return typeof (data) === 'string' ? data.replace(')]}\',\n', '') : data;
397+
}
398+
375399
function convertDataToCorrectType(contentType, dataStr) {
376400
var data = dataStr;
377401
contentType = contentType.toLowerCase();
378402

379403
if (contentType.indexOf('json') > -1) {
404+
// only remove json vulnerability prefix if we're parsing json
405+
dataStr = trimJsonProtectionVulnerability(dataStr);
380406
data = angular.fromJson(dataStr);
381407
}
382408

@@ -559,27 +585,14 @@ function addRequestFn(request) {
559585
return true;
560586
}
561587

562-
/**
563-
* see https://docs.angularjs.org/api/ng/service/$http#json-vulnerability-protection
564-
* @param data
565-
* @returns {*|void|string}
566-
*/
567-
function trimJsonProtectionVulnerability(data) {
568-
return typeof (data) === 'string' ? data.replace(')]}\',\n', '') : data;
569-
}
570-
571588
function sendFn() {
572589
var self = this,
573590
adapter = self.getAdapter(),
574591
httpBatchConfig = adapter.buildRequest(self.requests, self.config);
575592

576593
self.sendCallback();
577594
self.$injector.get('$http')(httpBatchConfig).then(function (response) {
578-
var batchResponses;
579-
580-
response.data = trimJsonProtectionVulnerability(response.data);
581-
582-
batchResponses = adapter.parseResponse(self.requests, response, self.config);
595+
var batchResponses = adapter.parseResponse(self.requests, response, self.config);
583596

584597
angular.forEach(batchResponses, function (batchResponse) {
585598
batchResponse.request.callback(

0 commit comments

Comments
 (0)