Skip to content

Commit 02c3c69

Browse files
fix: backport allowAbsoluteUrls vuln fix to v0.x (#6829)
* allowAbsoluteUrls * fix logic - copied from v1.x * update string * undo changes to dist/axios.js * chore: use strict equal in lib/core/buildFullPath.js --------- Co-authored-by: Jay <[email protected]>
1 parent 8603e67 commit 02c3c69

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

lib/adapters/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = function httpAdapter(config) {
109109
var method = config.method.toUpperCase();
110110

111111
// Parse url
112-
var fullPath = buildFullPath(config.baseURL, config.url);
112+
var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
113113
var parsed = url.parse(fullPath);
114114
var protocol = parsed.protocol || supportedProtocols[0];
115115

lib/adapters/xhr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = function xhrAdapter(config) {
4343
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
4444
}
4545

46-
var fullPath = buildFullPath(config.baseURL, config.url);
46+
var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
4747

4848
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
4949

lib/core/Axios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Axios.prototype.request = function request(configOrUrl, config) {
136136

137137
Axios.prototype.getUri = function getUri(config) {
138138
config = mergeConfig(this.defaults, config);
139-
var fullPath = buildFullPath(config.baseURL, config.url);
139+
var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
140140
return buildURL(fullPath, config.params, config.paramsSerializer);
141141
};
142142

lib/core/buildFullPath.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ var combineURLs = require('../helpers/combineURLs');
1010
*
1111
* @param {string} baseURL The base URL
1212
* @param {string} requestedURL Absolute or relative URL to combine
13+
* @param {boolean} allowAbsoluteUrls Set to true to allow absolute URLs
14+
*
1315
* @returns {string} The combined full path
1416
*/
15-
module.exports = function buildFullPath(baseURL, requestedURL) {
16-
if (baseURL && !isAbsoluteURL(requestedURL)) {
17+
module.exports = function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
18+
var isRelativeURL = !isAbsoluteURL(requestedURL);
19+
if (baseURL && (isRelativeURL || allowAbsoluteUrls === false)) {
1720
return combineURLs(baseURL, requestedURL);
1821
}
1922
return requestedURL;

test/specs/core/buildFullPath.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ describe('helpers::buildFullPath', function () {
1616
it('should combine URLs when the baseURL and requestedURL are relative', function () {
1717
expect(buildFullPath('/api', '/users')).toBe('/api/users');
1818
});
19-
19+
it('should not combine the URLs when the requestedURL is absolute, allowAbsoluteUrls is false, and the baseURL is not configured', function () {
20+
expect(buildFullPath(undefined, 'https://api.example.com/users', false)).toBe('https://api.example.com/users');
21+
});
2022
});

0 commit comments

Comments
 (0)