axios 0.32.0 → 0.34.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 +163 -7
- package/README.md +70 -1
- package/dist/axios.js +242 -39
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +242 -39
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/index.d.ts +5 -1
- package/lib/adapters/http.js +64 -11
- package/lib/adapters/xhr.js +12 -7
- package/lib/cancel/fromSignal.js +20 -0
- package/lib/core/Axios.js +82 -12
- package/lib/core/dispatchRequest.js +5 -4
- package/lib/core/mergeConfig.js +7 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/buildURL.js +11 -3
- package/lib/helpers/formDataToJSON.js +18 -1
- package/lib/helpers/shouldBypassProxy.js +213 -2
- package/lib/helpers/toFormData.js +59 -10
- package/lib/utils.js +33 -3
- package/package.json +1 -1
|
@@ -40,6 +40,15 @@ function parseNoProxyEntry(entry) {
|
|
|
40
40
|
return [entryHost, entryPort];
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// Parses a dotted-quad into its four octet strings, or null when the input is
|
|
44
|
+
// not an unambiguous decimal IPv4 address.
|
|
45
|
+
//
|
|
46
|
+
// Octets with a leading zero are rejected. The Node URL parser reads them the
|
|
47
|
+
// way inet_aton does, so `http://010.0.0.1/` arrives here as `8.0.0.1`, while a
|
|
48
|
+
// decimal read of the same literal would be `10.0.0.1`. Accepting the ambiguous
|
|
49
|
+
// form would let a no_proxy entry match a host the operator did not name.
|
|
50
|
+
// Rejecting fails closed: the entry falls back to literal hostname comparison,
|
|
51
|
+
// which will not match, so the request keeps using the proxy.
|
|
43
52
|
function parseIPv4Octets(hostname) {
|
|
44
53
|
var octets = hostname.split('.');
|
|
45
54
|
|
|
@@ -51,6 +60,10 @@ function parseIPv4Octets(hostname) {
|
|
|
51
60
|
if (!/^\d+$/.test(octets[i]) || Number(octets[i]) > 255) {
|
|
52
61
|
return null;
|
|
53
62
|
}
|
|
63
|
+
|
|
64
|
+
if (octets[i].length > 1 && octets[i].charAt(0) === '0') {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
return octets;
|
|
@@ -92,6 +105,20 @@ function normalizeIPv4MappedIPv6(hostname) {
|
|
|
92
105
|
return hostname;
|
|
93
106
|
}
|
|
94
107
|
|
|
108
|
+
// Trailing dots are trimmed without a regular expression. An anchored `/\.+$/`
|
|
109
|
+
// backtracks quadratically over a long run of dots that is not at the end of
|
|
110
|
+
// the string, and hostnames reaching this helper include redirect Location
|
|
111
|
+
// values, which are attacker-controlled.
|
|
112
|
+
function stripTrailingDots(hostname) {
|
|
113
|
+
var end = hostname.length;
|
|
114
|
+
|
|
115
|
+
while (end > 0 && hostname.charAt(end - 1) === '.') {
|
|
116
|
+
end--;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return end === hostname.length ? hostname : hostname.slice(0, end);
|
|
120
|
+
}
|
|
121
|
+
|
|
95
122
|
function normalizeNoProxyHost(hostname) {
|
|
96
123
|
if (!hostname) {
|
|
97
124
|
return hostname;
|
|
@@ -101,11 +128,189 @@ function normalizeNoProxyHost(hostname) {
|
|
|
101
128
|
hostname = hostname.slice(1, -1);
|
|
102
129
|
}
|
|
103
130
|
|
|
104
|
-
hostname = hostname
|
|
131
|
+
hostname = stripTrailingDots(hostname);
|
|
105
132
|
|
|
106
133
|
return normalizeIPv4MappedIPv6(hostname);
|
|
107
134
|
}
|
|
108
135
|
|
|
136
|
+
function ipv4ToBytes(hostname) {
|
|
137
|
+
var octets = parseIPv4Octets(hostname);
|
|
138
|
+
|
|
139
|
+
if (!octets) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return [Number(octets[0]), Number(octets[1]), Number(octets[2]), Number(octets[3])];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function pushIPv6Group(bytes, group) {
|
|
147
|
+
if (!/^[0-9a-f]{1,4}$/.test(group)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var value = parseInt(group, 16);
|
|
152
|
+
|
|
153
|
+
bytes.push((value >> 8) & 0xff, value & 0xff);
|
|
154
|
+
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function ipv6ToBytes(hostname) {
|
|
159
|
+
var halves = hostname.split('::');
|
|
160
|
+
|
|
161
|
+
if (halves.length > 2) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var compressed = halves.length === 2;
|
|
166
|
+
var head = halves[0] ? halves[0].split(':') : [];
|
|
167
|
+
var tail = compressed && halves[1] ? halves[1].split(':') : [];
|
|
168
|
+
|
|
169
|
+
// A dotted quad may only stand for the final 32 bits of an address, so it has
|
|
170
|
+
// to be the last group in the text. When `::` follows the head, the head is not
|
|
171
|
+
// the end of the address and a dotted quad there is malformed. Expanding it
|
|
172
|
+
// anyway read `1.2.3.4::/64` as the unrelated network 102:304::/64, so a
|
|
173
|
+
// mistyped entry silently bypassed the proxy for hosts the operator never
|
|
174
|
+
// listed. Returning null fails closed: the entry falls back to hostname
|
|
175
|
+
// comparison, which never matches a range.
|
|
176
|
+
if (compressed && !tail.length && head.length &&
|
|
177
|
+
head[head.length - 1].indexOf('.') !== -1) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var groups = tail.length ? tail : head;
|
|
182
|
+
|
|
183
|
+
// Expand a trailing dotted-quad tail such as ::ffff:127.0.0.1 into two groups.
|
|
184
|
+
if (groups.length && groups[groups.length - 1].indexOf('.') !== -1) {
|
|
185
|
+
var quad = ipv4ToBytes(groups[groups.length - 1]);
|
|
186
|
+
|
|
187
|
+
if (!quad) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
groups.pop();
|
|
192
|
+
groups.push((((quad[0] << 8) | quad[1]) >>> 0).toString(16));
|
|
193
|
+
groups.push((((quad[2] << 8) | quad[3]) >>> 0).toString(16));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var headBytes = [];
|
|
197
|
+
var tailBytes = [];
|
|
198
|
+
var i;
|
|
199
|
+
|
|
200
|
+
for (i = 0; i < head.length; i++) {
|
|
201
|
+
if (!pushIPv6Group(headBytes, head[i])) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
for (i = 0; i < tail.length; i++) {
|
|
207
|
+
if (!pushIPv6Group(tailBytes, tail[i])) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var missing = 16 - headBytes.length - tailBytes.length;
|
|
213
|
+
|
|
214
|
+
// `::` stands for one or more groups of zeros, so a compressed address that
|
|
215
|
+
// already spells out all eight groups is malformed. Accepting it let
|
|
216
|
+
// `1:2:3:4:5:6:7:8::/0` parse as a valid /0 network and bypass the proxy for
|
|
217
|
+
// every IPv6 destination.
|
|
218
|
+
if (compressed ? missing <= 0 : missing !== 0) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (i = 0; i < missing; i++) {
|
|
223
|
+
headBytes.push(0);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return headBytes.concat(tailBytes);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function hostToBytes(hostname) {
|
|
230
|
+
return hostname.indexOf(':') !== -1 ? ipv6ToBytes(hostname) : ipv4ToBytes(hostname);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Parses a CIDR-form no_proxy entry such as 10.0.0.0/8 or [fd00::]/8.
|
|
234
|
+
// Returns null for anything that is not a well-formed network range so the
|
|
235
|
+
// caller can fall back to hostname matching.
|
|
236
|
+
//
|
|
237
|
+
// Range entries are matched on address alone. Unlike host entries they carry no
|
|
238
|
+
// port, because a trailing `:port` leaves a prefix that is not a bare number and
|
|
239
|
+
// so falls back to hostname matching, which will not match a range.
|
|
240
|
+
//
|
|
241
|
+
// An IPv4-mapped IPv6 host is normalised to its IPv4 form before it reaches
|
|
242
|
+
// here, so list those addresses as IPv4 ranges (10.0.0.0/8), not as
|
|
243
|
+
// ::ffff:0:0/96, which will not match.
|
|
244
|
+
function parseCIDREntry(entry) {
|
|
245
|
+
var slashIndex = entry.indexOf('/');
|
|
246
|
+
|
|
247
|
+
if (slashIndex === -1) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var prefixText = entry.slice(slashIndex + 1);
|
|
252
|
+
|
|
253
|
+
if (!/^\d{1,3}$/.test(prefixText)) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var host = entry.slice(0, slashIndex);
|
|
258
|
+
|
|
259
|
+
if (host.charAt(0) === '[' && host.charAt(host.length - 1) === ']') {
|
|
260
|
+
host = host.slice(1, -1);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var bytes = hostToBytes(host);
|
|
264
|
+
|
|
265
|
+
if (!bytes) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var prefix = parseInt(prefixText, 10);
|
|
270
|
+
|
|
271
|
+
if (prefix > bytes.length * 8) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return [bytes, prefix];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function isInCIDR(hostname, cidr) {
|
|
279
|
+
var networkBytes = cidr[0];
|
|
280
|
+
var prefix = cidr[1];
|
|
281
|
+
var bytes = hostToBytes(hostname);
|
|
282
|
+
|
|
283
|
+
if (!bytes || bytes.length !== networkBytes.length) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
var index = 0;
|
|
288
|
+
var remaining = prefix;
|
|
289
|
+
|
|
290
|
+
while (remaining >= 8) {
|
|
291
|
+
if (bytes[index] !== networkBytes[index]) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
remaining -= 8;
|
|
296
|
+
index++;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (remaining > 0) {
|
|
300
|
+
var mask = (0xff << (8 - remaining)) & 0xff;
|
|
301
|
+
|
|
302
|
+
if ((bytes[index] & mask) !== (networkBytes[index] & mask)) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Deliberately more permissive than parseIPv4Octets: this only asks whether the
|
|
311
|
+
// first octet is exactly 127, and a leading zero in any later octet cannot
|
|
312
|
+
// change that answer, so a hand-written no_proxy entry like 127.000.000.001
|
|
313
|
+
// still resolves to loopback.
|
|
109
314
|
function isLoopbackIPv4(hostname) {
|
|
110
315
|
var octets = hostname.split('.');
|
|
111
316
|
|
|
@@ -123,7 +328,7 @@ function isLoopbackIPv4(hostname) {
|
|
|
123
328
|
}
|
|
124
329
|
|
|
125
330
|
function isLoopbackHost(hostname) {
|
|
126
|
-
return hostname === 'localhost' || hostname === '::1' || isLoopbackIPv4(hostname);
|
|
331
|
+
return hostname === 'localhost' || hostname === '::1' || hostname === '0.0.0.0' || isLoopbackIPv4(hostname);
|
|
127
332
|
}
|
|
128
333
|
|
|
129
334
|
module.exports = function shouldBypassProxy(location) {
|
|
@@ -154,6 +359,12 @@ module.exports = function shouldBypassProxy(location) {
|
|
|
154
359
|
return false;
|
|
155
360
|
}
|
|
156
361
|
|
|
362
|
+
var cidr = parseCIDREntry(entry);
|
|
363
|
+
|
|
364
|
+
if (cidr) {
|
|
365
|
+
return isInCIDR(hostname, cidr);
|
|
366
|
+
}
|
|
367
|
+
|
|
157
368
|
var entryParts = parseNoProxyEntry(entry);
|
|
158
369
|
var entryHost = normalizeNoProxyHost(entryParts[0]);
|
|
159
370
|
var entryPort = entryParts[1];
|
|
@@ -33,6 +33,40 @@ function isSpecCompliant(thing) {
|
|
|
33
33
|
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
var UNSAFE_OPTION_KEYS = ['__proto__', 'constructor', 'prototype'];
|
|
37
|
+
|
|
38
|
+
// Materialises the serializer options onto a null-prototype object. Reading the
|
|
39
|
+
// options from a plain object let a polluted Object.prototype supply a visitor,
|
|
40
|
+
// a depth limit, a Blob implementation or key-format flags that the caller never
|
|
41
|
+
// asked for, and also let a polluted key mask an option the caller did set.
|
|
42
|
+
// Only own, defined properties of the caller's options are carried over.
|
|
43
|
+
function toFormDataOptions(source) {
|
|
44
|
+
var options = Object.create(null);
|
|
45
|
+
|
|
46
|
+
options.metaTokens = true;
|
|
47
|
+
options.dots = false;
|
|
48
|
+
options.indexes = false;
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
51
|
+
if (source == null) {
|
|
52
|
+
return options;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var names = Object.getOwnPropertyNames(source);
|
|
56
|
+
|
|
57
|
+
for (var i = 0; i < names.length; i++) {
|
|
58
|
+
var name = names[i];
|
|
59
|
+
|
|
60
|
+
if (UNSAFE_OPTION_KEYS.indexOf(name) !== -1 || utils.isUndefined(source[name])) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
options[name] = source[name];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return options;
|
|
68
|
+
}
|
|
69
|
+
|
|
36
70
|
/**
|
|
37
71
|
* Convert a data object to FormData
|
|
38
72
|
* @param {Object} obj
|
|
@@ -54,14 +88,7 @@ function toFormData(obj, formData, options) {
|
|
|
54
88
|
formData = formData || new (envFormData || FormData)();
|
|
55
89
|
|
|
56
90
|
// eslint-disable-next-line no-param-reassign
|
|
57
|
-
options =
|
|
58
|
-
metaTokens: true,
|
|
59
|
-
dots: false,
|
|
60
|
-
indexes: false
|
|
61
|
-
}, false, function defined(option, source) {
|
|
62
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
63
|
-
return !utils.isUndefined(source[option]);
|
|
64
|
-
});
|
|
91
|
+
options = toFormDataOptions(options);
|
|
65
92
|
|
|
66
93
|
var metaTokens = options.metaTokens;
|
|
67
94
|
// eslint-disable-next-line no-use-before-define
|
|
@@ -94,6 +121,29 @@ function toFormData(obj, formData, options) {
|
|
|
94
121
|
return value;
|
|
95
122
|
}
|
|
96
123
|
|
|
124
|
+
var stack = [];
|
|
125
|
+
|
|
126
|
+
function assertValueDepth(value, depth) {
|
|
127
|
+
if (depth > maxDepth) {
|
|
128
|
+
throw new AxiosError(
|
|
129
|
+
'Maximum object depth of ' + maxDepth + ' exceeded (got ' + depth + ' levels)',
|
|
130
|
+
AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!utils.isObject(value) || stack.indexOf(value) !== -1) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
stack.push(value);
|
|
139
|
+
|
|
140
|
+
utils.forEach(value, function each(el) {
|
|
141
|
+
assertValueDepth(el, depth + 1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
stack.pop();
|
|
145
|
+
}
|
|
146
|
+
|
|
97
147
|
/**
|
|
98
148
|
*
|
|
99
149
|
* @param {*} value
|
|
@@ -109,6 +159,7 @@ function toFormData(obj, formData, options) {
|
|
|
109
159
|
if (utils.endsWith(key, '{}')) {
|
|
110
160
|
// eslint-disable-next-line no-param-reassign
|
|
111
161
|
key = metaTokens ? key : key.slice(0, -2);
|
|
162
|
+
assertValueDepth(value, 1);
|
|
112
163
|
// eslint-disable-next-line no-param-reassign
|
|
113
164
|
value = JSON.stringify(value);
|
|
114
165
|
} else if (
|
|
@@ -138,8 +189,6 @@ function toFormData(obj, formData, options) {
|
|
|
138
189
|
return false;
|
|
139
190
|
}
|
|
140
191
|
|
|
141
|
-
var stack = [];
|
|
142
|
-
|
|
143
192
|
var exposedHelpers = Object.assign(predicates, {
|
|
144
193
|
defaultVisitor: defaultVisitor,
|
|
145
194
|
convertValue: convertValue,
|
package/lib/utils.js
CHANGED
|
@@ -393,6 +393,15 @@ function stripBOM(content) {
|
|
|
393
393
|
return content;
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
+
function defineOwnProperty(target, key, value) {
|
|
397
|
+
var descriptor = Object.create(null);
|
|
398
|
+
descriptor.value = value;
|
|
399
|
+
descriptor.writable = true;
|
|
400
|
+
descriptor.enumerable = true;
|
|
401
|
+
descriptor.configurable = true;
|
|
402
|
+
Object.defineProperty(target, key, descriptor);
|
|
403
|
+
}
|
|
404
|
+
|
|
396
405
|
/**
|
|
397
406
|
* Inherit the prototype methods from one constructor into another
|
|
398
407
|
* @param {function} constructor
|
|
@@ -400,14 +409,35 @@ function stripBOM(content) {
|
|
|
400
409
|
* @param {object} [props]
|
|
401
410
|
* @param {object} [descriptors]
|
|
402
411
|
*/
|
|
403
|
-
|
|
404
412
|
function inherits(constructor, superConstructor, props, descriptors) {
|
|
405
413
|
constructor.prototype = Object.create(
|
|
406
414
|
superConstructor.prototype,
|
|
407
415
|
descriptors
|
|
408
416
|
);
|
|
409
|
-
|
|
410
|
-
|
|
417
|
+
if (Object.prototype.hasOwnProperty.call(constructor.prototype, 'constructor')) {
|
|
418
|
+
constructor.prototype.constructor = constructor;
|
|
419
|
+
} else {
|
|
420
|
+
defineOwnProperty(constructor.prototype, 'constructor', constructor);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (props) {
|
|
424
|
+
var keys = Object.keys(props);
|
|
425
|
+
if (Object.getOwnPropertySymbols) {
|
|
426
|
+
keys = keys.concat(Object.getOwnPropertySymbols(props).filter(function(key) {
|
|
427
|
+
return Object.prototype.propertyIsEnumerable.call(props, key);
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
keys.forEach(function(key) {
|
|
431
|
+
var value = props[key];
|
|
432
|
+
if (Object.prototype.hasOwnProperty.call(constructor.prototype, key)) {
|
|
433
|
+
constructor.prototype[key] = value;
|
|
434
|
+
} else {
|
|
435
|
+
// Assignment would invoke an inherited setter or fail on a read-only
|
|
436
|
+
// property installed by another library, such as Error.prototype.toJSON.
|
|
437
|
+
defineOwnProperty(constructor.prototype, key, value);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
411
441
|
}
|
|
412
442
|
|
|
413
443
|
/**
|