axios 1.16.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -1
- package/README.md +267 -239
- package/dist/axios.js +454 -146
- package/dist/axios.min.js +3 -3
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +470 -99
- package/dist/esm/axios.js +470 -99
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +638 -201
- package/index.d.cts +10 -3
- package/index.d.ts +6 -1
- package/lib/adapters/fetch.js +190 -35
- package/lib/adapters/http.js +192 -159
- package/lib/core/Axios.js +4 -2
- package/lib/core/AxiosHeaders.js +12 -9
- package/lib/core/buildFullPath.js +29 -1
- package/lib/core/mergeConfig.js +34 -0
- package/lib/defaults/transitional.js +2 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/Http2Sessions.js +119 -0
- package/lib/helpers/buildURL.js +6 -4
- package/lib/helpers/estimateDataURLDecodedBytes.js +16 -11
- package/lib/helpers/formDataToJSON.js +25 -3
- package/lib/helpers/formDataToStream.js +2 -2
- package/lib/helpers/resolveConfig.js +17 -9
- package/lib/helpers/shouldBypassProxy.js +33 -1
- package/lib/helpers/toFormData.js +41 -11
- package/lib/utils.js +97 -12
- package/package.json +29 -13
- package/dist/axios.js.map +0 -1
- package/dist/browser/axios.cjs.map +0 -1
- package/dist/esm/axios.js.map +0 -1
- package/dist/node/axios.cjs.map +0 -1
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
import AxiosError from './AxiosError.js';
|
|
3
4
|
import isAbsoluteURL from '../helpers/isAbsoluteURL.js';
|
|
4
5
|
import combineURLs from '../helpers/combineURLs.js';
|
|
5
6
|
|
|
7
|
+
const malformedHttpProtocol = /^https?:(?!\/\/)/i;
|
|
8
|
+
const httpProtocolControlCharacters = /[\t\n\r]/g;
|
|
9
|
+
|
|
10
|
+
function stripLeadingC0ControlOrSpace(url) {
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (i < url.length && url.charCodeAt(i) <= 0x20) {
|
|
13
|
+
i++;
|
|
14
|
+
}
|
|
15
|
+
return url.slice(i);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeURLForProtocolCheck(url) {
|
|
19
|
+
return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function assertValidHttpProtocolURL(url, config) {
|
|
23
|
+
if (typeof url === 'string' && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
|
|
24
|
+
throw new AxiosError(
|
|
25
|
+
'Invalid URL: missing "//" after protocol',
|
|
26
|
+
AxiosError.ERR_INVALID_URL,
|
|
27
|
+
config
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
6
32
|
/**
|
|
7
33
|
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
8
34
|
* only when the requestedURL is not already an absolute URL.
|
|
@@ -13,9 +39,11 @@ import combineURLs from '../helpers/combineURLs.js';
|
|
|
13
39
|
*
|
|
14
40
|
* @returns {string} The combined full path
|
|
15
41
|
*/
|
|
16
|
-
export default function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
|
|
42
|
+
export default function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config) {
|
|
43
|
+
assertValidHttpProtocolURL(requestedURL, config);
|
|
17
44
|
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
18
45
|
if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
|
|
46
|
+
assertValidHttpProtocolURL(baseURL, config);
|
|
19
47
|
return combineURLs(baseURL, requestedURL);
|
|
20
48
|
}
|
|
21
49
|
return requestedURL;
|
package/lib/core/mergeConfig.js
CHANGED
|
@@ -68,6 +68,28 @@ export default function mergeConfig(config1, config2) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function getMergedTransitionalOption(prop) {
|
|
72
|
+
const transitional2 = utils.hasOwnProp(config2, 'transitional') ? config2.transitional : undefined;
|
|
73
|
+
|
|
74
|
+
if (!utils.isUndefined(transitional2)) {
|
|
75
|
+
if (utils.isPlainObject(transitional2)) {
|
|
76
|
+
if (utils.hasOwnProp(transitional2, prop)) {
|
|
77
|
+
return transitional2[prop];
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const transitional1 = utils.hasOwnProp(config1, 'transitional') ? config1.transitional : undefined;
|
|
85
|
+
|
|
86
|
+
if (utils.isPlainObject(transitional1) && utils.hasOwnProp(transitional1, prop)) {
|
|
87
|
+
return transitional1[prop];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
// eslint-disable-next-line consistent-return
|
|
72
94
|
function mergeDirectKeys(a, b, prop) {
|
|
73
95
|
if (utils.hasOwnProp(config2, prop)) {
|
|
@@ -120,5 +142,17 @@ export default function mergeConfig(config1, config2) {
|
|
|
120
142
|
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
121
143
|
});
|
|
122
144
|
|
|
145
|
+
if (
|
|
146
|
+
utils.hasOwnProp(config2, 'validateStatus') &&
|
|
147
|
+
utils.isUndefined(config2.validateStatus) &&
|
|
148
|
+
getMergedTransitionalOption('validateStatusUndefinedResolves') === false
|
|
149
|
+
) {
|
|
150
|
+
if (utils.hasOwnProp(config1, 'validateStatus')) {
|
|
151
|
+
config.validateStatus = getMergedValue(undefined, config1.validateStatus);
|
|
152
|
+
} else {
|
|
153
|
+
delete config.validateStatus;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
123
157
|
return config;
|
|
124
158
|
}
|
package/lib/env/data.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.18.0";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Node-only: relies on the built-in `http2` module. Browser/react-native
|
|
4
|
+
// builds replace `lib/adapters/http.js` (the sole importer) with `lib/helpers/null.js`
|
|
5
|
+
// via the `browser` package.json field, so this module is never reached in
|
|
6
|
+
// those environments. Do not import it from any browser-reachable code path.
|
|
7
|
+
|
|
8
|
+
import http2 from 'http2';
|
|
9
|
+
import util from 'util';
|
|
10
|
+
|
|
11
|
+
class Http2Sessions {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.sessions = Object.create(null);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getSession(authority, options) {
|
|
17
|
+
options = Object.assign(
|
|
18
|
+
{
|
|
19
|
+
sessionTimeout: 1000,
|
|
20
|
+
},
|
|
21
|
+
options
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
let authoritySessions = this.sessions[authority];
|
|
25
|
+
|
|
26
|
+
if (authoritySessions) {
|
|
27
|
+
let len = authoritySessions.length;
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < len; i++) {
|
|
30
|
+
const [sessionHandle, sessionOptions] = authoritySessions[i];
|
|
31
|
+
if (
|
|
32
|
+
!sessionHandle.destroyed &&
|
|
33
|
+
!sessionHandle.closed &&
|
|
34
|
+
util.isDeepStrictEqual(sessionOptions, options)
|
|
35
|
+
) {
|
|
36
|
+
return sessionHandle;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const session = http2.connect(authority, options);
|
|
42
|
+
|
|
43
|
+
let removed;
|
|
44
|
+
let timer;
|
|
45
|
+
|
|
46
|
+
const removeSession = () => {
|
|
47
|
+
if (removed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
removed = true;
|
|
52
|
+
|
|
53
|
+
if (timer) {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
timer = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let entries = authoritySessions,
|
|
59
|
+
len = entries.length,
|
|
60
|
+
i = len;
|
|
61
|
+
|
|
62
|
+
while (i--) {
|
|
63
|
+
if (entries[i][0] === session) {
|
|
64
|
+
if (len === 1) {
|
|
65
|
+
delete this.sessions[authority];
|
|
66
|
+
} else {
|
|
67
|
+
entries.splice(i, 1);
|
|
68
|
+
}
|
|
69
|
+
if (!session.closed) {
|
|
70
|
+
session.close();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const originalRequestFn = session.request;
|
|
78
|
+
|
|
79
|
+
const { sessionTimeout } = options;
|
|
80
|
+
|
|
81
|
+
if (sessionTimeout != null) {
|
|
82
|
+
let streamsCount = 0;
|
|
83
|
+
|
|
84
|
+
session.request = function () {
|
|
85
|
+
const stream = originalRequestFn.apply(this, arguments);
|
|
86
|
+
|
|
87
|
+
streamsCount++;
|
|
88
|
+
|
|
89
|
+
if (timer) {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
timer = null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
stream.once('close', () => {
|
|
95
|
+
if (!--streamsCount) {
|
|
96
|
+
timer = setTimeout(() => {
|
|
97
|
+
timer = null;
|
|
98
|
+
removeSession();
|
|
99
|
+
}, sessionTimeout);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return stream;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
session.once('close', removeSession);
|
|
108
|
+
|
|
109
|
+
let entry = [session, options];
|
|
110
|
+
|
|
111
|
+
authoritySessions
|
|
112
|
+
? authoritySessions.push(entry)
|
|
113
|
+
: (authoritySessions = this.sessions[authority] = [entry]);
|
|
114
|
+
|
|
115
|
+
return session;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default Http2Sessions;
|
package/lib/helpers/buildURL.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import utils from '../utils.js';
|
|
4
|
-
import AxiosURLSearchParams from '
|
|
4
|
+
import AxiosURLSearchParams from './AxiosURLSearchParams.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
|
|
@@ -33,15 +33,17 @@ export default function buildURL(url, params, options) {
|
|
|
33
33
|
return url;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const _encode = (options && options.encode) || encode;
|
|
37
|
-
|
|
38
36
|
const _options = utils.isFunction(options)
|
|
39
37
|
? {
|
|
40
38
|
serialize: options,
|
|
41
39
|
}
|
|
42
40
|
: options;
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
// Read serializer options pollution-safely: own properties and methods on a
|
|
43
|
+
// class/template prototype are honored, but values injected onto a polluted
|
|
44
|
+
// Object.prototype are ignored.
|
|
45
|
+
const _encode = utils.getSafeProp(_options, 'encode') || encode;
|
|
46
|
+
const serializeFn = utils.getSafeProp(_options, 'serialize');
|
|
45
47
|
|
|
46
48
|
let serializedParams;
|
|
47
49
|
|
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
* Estimate decoded byte length of a data:// URL *without* allocating large buffers.
|
|
3
3
|
* - For base64: compute exact decoded size using length and padding;
|
|
4
4
|
* handle %XX at the character-count level (no string allocation).
|
|
5
|
-
* - For non-base64:
|
|
5
|
+
* - For non-base64: compute the exact percent-decoded UTF-8 byte length.
|
|
6
6
|
*
|
|
7
7
|
* @param {string} url
|
|
8
8
|
* @returns {number}
|
|
9
9
|
*/
|
|
10
|
+
const isHexDigit = (charCode) =>
|
|
11
|
+
(charCode >= 48 && charCode <= 57) ||
|
|
12
|
+
(charCode >= 65 && charCode <= 70) ||
|
|
13
|
+
(charCode >= 97 && charCode <= 102);
|
|
14
|
+
|
|
15
|
+
const isPercentEncodedByte = (str, i, len) =>
|
|
16
|
+
i + 2 < len && isHexDigit(str.charCodeAt(i + 1)) && isHexDigit(str.charCodeAt(i + 2));
|
|
17
|
+
|
|
10
18
|
export default function estimateDataURLDecodedBytes(url) {
|
|
11
19
|
if (!url || typeof url !== 'string') return 0;
|
|
12
20
|
if (!url.startsWith('data:')) return 0;
|
|
@@ -26,9 +34,7 @@ export default function estimateDataURLDecodedBytes(url) {
|
|
|
26
34
|
if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
|
|
27
35
|
const a = body.charCodeAt(i + 1);
|
|
28
36
|
const b = body.charCodeAt(i + 2);
|
|
29
|
-
const isHex =
|
|
30
|
-
((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
|
|
31
|
-
((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
|
|
37
|
+
const isHex = isHexDigit(a) && isHexDigit(b);
|
|
32
38
|
|
|
33
39
|
if (isHex) {
|
|
34
40
|
effectiveLen -= 2;
|
|
@@ -69,18 +75,17 @@ export default function estimateDataURLDecodedBytes(url) {
|
|
|
69
75
|
return bytes > 0 ? bytes : 0;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
|
|
73
|
-
return Buffer.byteLength(body, 'utf8');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
78
|
// Compute UTF-8 byte length directly from UTF-16 code units without allocating
|
|
77
79
|
// a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
+
// Valid %XX triplets count as one decoded byte; this matches the bytes that
|
|
81
|
+
// decodeURIComponent(body) would produce before Buffer re-encodes the string.
|
|
80
82
|
let bytes = 0;
|
|
81
83
|
for (let i = 0, len = body.length; i < len; i++) {
|
|
82
84
|
const c = body.charCodeAt(i);
|
|
83
|
-
if (c
|
|
85
|
+
if (c === 37 /* '%' */ && isPercentEncodedByte(body, i, len)) {
|
|
86
|
+
bytes += 1;
|
|
87
|
+
i += 2;
|
|
88
|
+
} else if (c < 0x80) {
|
|
84
89
|
bytes += 1;
|
|
85
90
|
} else if (c < 0x800) {
|
|
86
91
|
bytes += 2;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import utils from '../utils.js';
|
|
4
|
+
import AxiosError from '../core/AxiosError.js';
|
|
5
|
+
import { DEFAULT_FORM_DATA_MAX_DEPTH } from './toFormData.js';
|
|
6
|
+
|
|
7
|
+
const MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
|
|
8
|
+
|
|
9
|
+
function throwIfDepthExceeded(index) {
|
|
10
|
+
if (index > MAX_DEPTH) {
|
|
11
|
+
throw new AxiosError(
|
|
12
|
+
'FormData field is too deeply nested (' + index + ' levels). Max depth: ' + MAX_DEPTH,
|
|
13
|
+
AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
|
@@ -14,9 +27,16 @@ function parsePropPath(name) {
|
|
|
14
27
|
// foo.x.y.z
|
|
15
28
|
// foo-x-y-z
|
|
16
29
|
// foo x y z
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
const path = [];
|
|
31
|
+
const pattern = /\w+|\[(\w*)]/g;
|
|
32
|
+
let match;
|
|
33
|
+
|
|
34
|
+
while ((match = pattern.exec(name)) !== null) {
|
|
35
|
+
throwIfDepthExceeded(path.length);
|
|
36
|
+
path.push(match[0] === '[]' ? '' : match[1] || match[0]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return path;
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
/**
|
|
@@ -48,6 +68,8 @@ function arrayToObject(arr) {
|
|
|
48
68
|
*/
|
|
49
69
|
function formDataToJSON(formData) {
|
|
50
70
|
function buildPath(path, value, target, index) {
|
|
71
|
+
throwIfDepthExceeded(index);
|
|
72
|
+
|
|
51
73
|
let name = path[index++];
|
|
52
74
|
|
|
53
75
|
if (name === '__proto__') return true;
|
|
@@ -73,11 +73,11 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
73
73
|
} = options || {};
|
|
74
74
|
|
|
75
75
|
if (!utils.isFormData(form)) {
|
|
76
|
-
throw TypeError('FormData instance required');
|
|
76
|
+
throw new TypeError('FormData instance required');
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (boundary.length < 1 || boundary.length > 70) {
|
|
80
|
-
throw Error('boundary must be 1-70 characters long');
|
|
80
|
+
throw new Error('boundary must be 1-70 characters long');
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
|
|
@@ -35,7 +35,7 @@ const encodeUTF8 = (str) =>
|
|
|
35
35
|
String.fromCharCode(parseInt(hex, 16))
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
function resolveConfig(config) {
|
|
39
39
|
const newConfig = mergeConfig({}, config);
|
|
40
40
|
|
|
41
41
|
// Read only own properties to prevent prototype pollution gadgets
|
|
@@ -55,23 +55,29 @@ export default (config) => {
|
|
|
55
55
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
56
56
|
|
|
57
57
|
newConfig.url = buildURL(
|
|
58
|
-
buildFullPath(baseURL, url, allowAbsoluteUrls),
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
|
|
59
|
+
own('params'),
|
|
60
|
+
own('paramsSerializer')
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
// HTTP basic authentication
|
|
64
64
|
if (auth) {
|
|
65
|
+
const username = utils.getSafeProp(auth, 'username') || '';
|
|
66
|
+
const password = utils.getSafeProp(auth, 'password') || '';
|
|
67
|
+
|
|
65
68
|
headers.set(
|
|
66
69
|
'Authorization',
|
|
67
|
-
'Basic ' +
|
|
68
|
-
btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : ''))
|
|
70
|
+
'Basic ' + btoa(username + ':' + (password ? encodeUTF8(password) : ''))
|
|
69
71
|
);
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
if (utils.isFormData(data)) {
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
+
if (
|
|
76
|
+
platform.hasStandardBrowserEnv ||
|
|
77
|
+
platform.hasStandardBrowserWebWorkerEnv ||
|
|
78
|
+
utils.isReactNative(data)
|
|
79
|
+
) {
|
|
80
|
+
headers.setContentType(undefined); // browser/web worker/RN handles it
|
|
75
81
|
} else if (utils.isFunction(data.getHeaders)) {
|
|
76
82
|
// Node.js FormData (like form-data package)
|
|
77
83
|
setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
|
|
@@ -103,4 +109,6 @@ export default (config) => {
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
return newConfig;
|
|
106
|
-
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default resolveConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const LOOPBACK_HOSTNAMES = new Set(['localhost']);
|
|
1
|
+
const LOOPBACK_HOSTNAMES = new Set(['localhost', '0.0.0.0']);
|
|
2
2
|
|
|
3
3
|
const isIPv4Loopback = (host) => {
|
|
4
4
|
const parts = host.split('.');
|
|
@@ -7,6 +7,37 @@ const isIPv4Loopback = (host) => {
|
|
|
7
7
|
return parts.every((p) => /^\d+$/.test(p) && Number(p) >= 0 && Number(p) <= 255);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
const isIPv6ZeroGroup = (group) => /^0{1,4}$/.test(group);
|
|
11
|
+
|
|
12
|
+
// The unspecified address (IPv4 0.0.0.0 / IPv6 ::) resolves to the local host
|
|
13
|
+
// for outbound connections, so treat it as loopback-equivalent for NO_PROXY
|
|
14
|
+
// matching. 0.0.0.0 is covered by LOOPBACK_HOSTNAMES; this handles compressed
|
|
15
|
+
// and full IPv6 all-zero forms so both families bypass symmetrically.
|
|
16
|
+
const isIPv6Unspecified = (host) => {
|
|
17
|
+
if (host === '::') return true;
|
|
18
|
+
|
|
19
|
+
const compressionIndex = host.indexOf('::');
|
|
20
|
+
|
|
21
|
+
if (compressionIndex !== -1) {
|
|
22
|
+
if (compressionIndex !== host.lastIndexOf('::')) return false;
|
|
23
|
+
|
|
24
|
+
const left = host.slice(0, compressionIndex);
|
|
25
|
+
const right = host.slice(compressionIndex + 2);
|
|
26
|
+
const leftGroups = left ? left.split(':') : [];
|
|
27
|
+
const rightGroups = right ? right.split(':') : [];
|
|
28
|
+
const explicitGroups = leftGroups.length + rightGroups.length;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
explicitGroups < 8 &&
|
|
32
|
+
leftGroups.every(isIPv6ZeroGroup) &&
|
|
33
|
+
rightGroups.every(isIPv6ZeroGroup)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const groups = host.split(':');
|
|
38
|
+
return groups.length === 8 && groups.every(isIPv6ZeroGroup);
|
|
39
|
+
};
|
|
40
|
+
|
|
10
41
|
const isIPv6Loopback = (host) => {
|
|
11
42
|
// Collapse all-zero groups: any form of ::1 / 0:0:...:0:1
|
|
12
43
|
// First, strip any leading "::" by normalising with Set lookup of common forms,
|
|
@@ -42,6 +73,7 @@ const isLoopback = (host) => {
|
|
|
42
73
|
if (!host) return false;
|
|
43
74
|
if (LOOPBACK_HOSTNAMES.has(host)) return true;
|
|
44
75
|
if (isIPv4Loopback(host)) return true;
|
|
76
|
+
if (isIPv6Unspecified(host)) return true;
|
|
45
77
|
return isIPv6Loopback(host);
|
|
46
78
|
};
|
|
47
79
|
|
|
@@ -5,6 +5,10 @@ import AxiosError from '../core/AxiosError.js';
|
|
|
5
5
|
// temporary hotfix to avoid circular references until AxiosURLSearchParams is refactored
|
|
6
6
|
import PlatformFormData from '../platform/node/classes/FormData.js';
|
|
7
7
|
|
|
8
|
+
// Default nesting limit shared with the inverse transform (formDataToJSON) so
|
|
9
|
+
// the FormData <-> JSON round-trip stays symmetric.
|
|
10
|
+
export const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Determines if the given thing is a array or js object.
|
|
10
14
|
*
|
|
@@ -115,8 +119,9 @@ function toFormData(obj, formData, options) {
|
|
|
115
119
|
const dots = options.dots;
|
|
116
120
|
const indexes = options.indexes;
|
|
117
121
|
const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
|
|
118
|
-
const maxDepth = options.maxDepth === undefined ?
|
|
122
|
+
const maxDepth = options.maxDepth === undefined ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
|
|
119
123
|
const useBlob = _Blob && utils.isSpecCompliantForm(formData);
|
|
124
|
+
const stack = [];
|
|
120
125
|
|
|
121
126
|
if (!utils.isFunction(visitor)) {
|
|
122
127
|
throw new TypeError('visitor must be a function');
|
|
@@ -144,6 +149,38 @@ function toFormData(obj, formData, options) {
|
|
|
144
149
|
return value;
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
function throwIfMaxDepthExceeded(depth) {
|
|
153
|
+
if (depth > maxDepth) {
|
|
154
|
+
throw new AxiosError(
|
|
155
|
+
'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
|
|
156
|
+
AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function stringifyWithDepthLimit(value, depth) {
|
|
162
|
+
if (maxDepth === Infinity) {
|
|
163
|
+
return JSON.stringify(value);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const ancestors = [];
|
|
167
|
+
|
|
168
|
+
return JSON.stringify(value, function limitDepth(_key, currentValue) {
|
|
169
|
+
if (!utils.isObject(currentValue)) {
|
|
170
|
+
return currentValue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
|
|
174
|
+
ancestors.pop();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
ancestors.push(currentValue);
|
|
178
|
+
throwIfMaxDepthExceeded(depth + ancestors.length - 1);
|
|
179
|
+
|
|
180
|
+
return currentValue;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
147
184
|
/**
|
|
148
185
|
* Default visitor.
|
|
149
186
|
*
|
|
@@ -167,7 +204,7 @@ function toFormData(obj, formData, options) {
|
|
|
167
204
|
// eslint-disable-next-line no-param-reassign
|
|
168
205
|
key = metaTokens ? key : key.slice(0, -2);
|
|
169
206
|
// eslint-disable-next-line no-param-reassign
|
|
170
|
-
value =
|
|
207
|
+
value = stringifyWithDepthLimit(value, 1);
|
|
171
208
|
} else if (
|
|
172
209
|
(utils.isArray(value) && isFlatArray(value)) ||
|
|
173
210
|
((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
|
|
@@ -200,8 +237,6 @@ function toFormData(obj, formData, options) {
|
|
|
200
237
|
return false;
|
|
201
238
|
}
|
|
202
239
|
|
|
203
|
-
const stack = [];
|
|
204
|
-
|
|
205
240
|
const exposedHelpers = Object.assign(predicates, {
|
|
206
241
|
defaultVisitor,
|
|
207
242
|
convertValue,
|
|
@@ -211,15 +246,10 @@ function toFormData(obj, formData, options) {
|
|
|
211
246
|
function build(value, path, depth = 0) {
|
|
212
247
|
if (utils.isUndefined(value)) return;
|
|
213
248
|
|
|
214
|
-
|
|
215
|
-
throw new AxiosError(
|
|
216
|
-
'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
|
|
217
|
-
AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
218
|
-
);
|
|
219
|
-
}
|
|
249
|
+
throwIfMaxDepthExceeded(depth);
|
|
220
250
|
|
|
221
251
|
if (stack.indexOf(value) !== -1) {
|
|
222
|
-
throw Error('Circular reference detected in ' + path.join('.'));
|
|
252
|
+
throw new Error('Circular reference detected in ' + path.join('.'));
|
|
223
253
|
}
|
|
224
254
|
|
|
225
255
|
stack.push(value);
|