axios 0.33.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 +20 -0
- package/README.md +70 -1
- package/dist/axios.js +177 -27
- 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 +177 -27
- 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 +54 -5
- package/lib/adapters/xhr.js +2 -2
- package/lib/cancel/fromSignal.js +20 -0
- package/lib/core/Axios.js +78 -10
- package/lib/core/dispatchRequest.js +5 -4
- package/lib/core/mergeConfig.js +7 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/shouldBypassProxy.js +212 -1
- package/lib/helpers/toFormData.js +35 -8
- package/lib/utils.js +33 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TypeScript Version: 4.1
|
|
2
2
|
type HeaderValue = string | string[] | number | boolean;
|
|
3
3
|
|
|
4
|
-
type AxiosHeaders = Record<string, HeaderValue | Record<
|
|
4
|
+
type AxiosHeaders = Record<string, HeaderValue | Record<string, HeaderValue>>;
|
|
5
5
|
|
|
6
6
|
type MethodsHeaders = {
|
|
7
7
|
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
|
@@ -86,6 +86,7 @@ export interface TransitionalOptions {
|
|
|
86
86
|
|
|
87
87
|
export interface GenericAbortSignal {
|
|
88
88
|
aborted: boolean;
|
|
89
|
+
readonly reason?: unknown;
|
|
89
90
|
onabort: ((...args: any) => any) | null;
|
|
90
91
|
addEventListener: (...args: any) => any;
|
|
91
92
|
removeEventListener: (...args: any) => any;
|
|
@@ -168,6 +169,7 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
168
169
|
cancelToken?: CancelToken;
|
|
169
170
|
decompress?: boolean;
|
|
170
171
|
transitional?: TransitionalOptions;
|
|
172
|
+
captureCallerStack?: boolean;
|
|
171
173
|
signal?: GenericAbortSignal;
|
|
172
174
|
insecureHTTPParser?: boolean;
|
|
173
175
|
env?: {
|
|
@@ -241,6 +243,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
export class CanceledError<T> extends AxiosError<T> {
|
|
246
|
+
reason?: unknown;
|
|
244
247
|
}
|
|
245
248
|
|
|
246
249
|
export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
|
|
@@ -251,6 +254,7 @@ export interface CancelStatic {
|
|
|
251
254
|
|
|
252
255
|
export interface Cancel {
|
|
253
256
|
message: string | undefined;
|
|
257
|
+
reason?: unknown;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
export interface Canceler {
|
package/lib/adapters/http.js
CHANGED
|
@@ -15,7 +15,7 @@ var zlib = require('zlib');
|
|
|
15
15
|
var VERSION = require('./../env/data').version;
|
|
16
16
|
var transitionalDefaults = require('../defaults/transitional');
|
|
17
17
|
var AxiosError = require('../core/AxiosError');
|
|
18
|
-
var
|
|
18
|
+
var canceledErrorFromSignal = require('../cancel/fromSignal');
|
|
19
19
|
var platform = require('../platform');
|
|
20
20
|
var fromDataURI = require('../helpers/fromDataURI');
|
|
21
21
|
var stream = require('stream');
|
|
@@ -125,6 +125,43 @@ function checkSocketPath(config) {
|
|
|
125
125
|
return null;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Normalize a configured HTTP(S) proxy protocol to the `scheme:` form Node expects.
|
|
130
|
+
*
|
|
131
|
+
* `AxiosProxyConfig.protocol` is documented (and typed) as a bare scheme such
|
|
132
|
+
* as `'http'`, but the value is handed straight to `http.request` as
|
|
133
|
+
* `options.protocol`, where it is compared verbatim against the agent's own
|
|
134
|
+
* `protocol`. A missing colon therefore made every documented proxy config
|
|
135
|
+
* fail with `ERR_ASSERTION: protocol mismatch`. Schemes are case-insensitive,
|
|
136
|
+
* so fold to lower case as well.
|
|
137
|
+
*
|
|
138
|
+
* @param {*} protocol The configured proxy protocol
|
|
139
|
+
* @returns {string|undefined} The normalized protocol, or undefined for non-strings or an empty string
|
|
140
|
+
* @throws {AxiosError} If a non-empty string is not an HTTP(S) protocol
|
|
141
|
+
*/
|
|
142
|
+
function normalizeProxyProtocol(protocol) {
|
|
143
|
+
if (typeof protocol !== 'string' || protocol === '') {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
var normalized = protocol.trim().toLowerCase();
|
|
148
|
+
|
|
149
|
+
if (normalized === 'http' || normalized === 'https') {
|
|
150
|
+
return normalized + ':';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (normalized === 'http:' || normalized === 'https:') {
|
|
154
|
+
return normalized;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Never infer a transport from an explicitly invalid string: an HTTP target
|
|
158
|
+
// could otherwise send HTTPS proxy credentials over a plaintext connection.
|
|
159
|
+
throw new AxiosError(
|
|
160
|
+
'proxy.protocol must be http or https',
|
|
161
|
+
AxiosError.ERR_BAD_OPTION_VALUE
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
128
165
|
/**
|
|
129
166
|
*
|
|
130
167
|
* @param {http.ClientRequestArgs} options
|
|
@@ -147,6 +184,11 @@ function setProxy(options, configProxy, location) {
|
|
|
147
184
|
removeProxyAuthorization(options.headers);
|
|
148
185
|
}
|
|
149
186
|
if (proxy) {
|
|
187
|
+
// Validate before adding proxy credentials or configuring a connection.
|
|
188
|
+
var proxyProtocol = normalizeProxyProtocol(
|
|
189
|
+
utils.hasOwnProperty(proxy, 'protocol') ? proxy.protocol : undefined
|
|
190
|
+
);
|
|
191
|
+
|
|
150
192
|
// Basic proxy authorization
|
|
151
193
|
var proxyAuth = utils.hasOwnProperty(proxy, 'auth')
|
|
152
194
|
? proxy.auth
|
|
@@ -178,8 +220,11 @@ function setProxy(options, configProxy, location) {
|
|
|
178
220
|
options.host = proxy.host;
|
|
179
221
|
options.port = proxy.port;
|
|
180
222
|
options.path = location;
|
|
181
|
-
|
|
182
|
-
|
|
223
|
+
|
|
224
|
+
// Preserve the target protocol when no normalized proxy protocol is supplied.
|
|
225
|
+
// Defaulting to HTTP here could downgrade an existing HTTPS proxy connection.
|
|
226
|
+
if (proxyProtocol) {
|
|
227
|
+
options.protocol = proxyProtocol;
|
|
183
228
|
}
|
|
184
229
|
}
|
|
185
230
|
|
|
@@ -418,7 +463,11 @@ module.exports = function httpAdapter(config) {
|
|
|
418
463
|
auth: auth,
|
|
419
464
|
protocol: protocol,
|
|
420
465
|
beforeRedirect: dispatchBeforeRedirect,
|
|
421
|
-
|
|
466
|
+
// Null-prototype. dispatchBeforeRedirect calls whatever it finds here, and
|
|
467
|
+
// the `config` hook is only populated when the caller supplies
|
|
468
|
+
// beforeRedirect, so a plain object left an inherited function reachable
|
|
469
|
+
// and able to rewrite the redirect target.
|
|
470
|
+
beforeRedirects: Object.create(null)
|
|
422
471
|
};
|
|
423
472
|
|
|
424
473
|
var socketPathError = checkSocketPath(config);
|
|
@@ -701,7 +750,7 @@ module.exports = function httpAdapter(config) {
|
|
|
701
750
|
req.abort();
|
|
702
751
|
reject(
|
|
703
752
|
!cancel || cancel.type
|
|
704
|
-
?
|
|
753
|
+
? canceledErrorFromSignal(config.signal, config, req)
|
|
705
754
|
: cancel
|
|
706
755
|
);
|
|
707
756
|
};
|
package/lib/adapters/xhr.js
CHANGED
|
@@ -9,7 +9,7 @@ var parseHeaders = require('./../helpers/parseHeaders');
|
|
|
9
9
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
|
10
10
|
var transitionalDefaults = require('../defaults/transitional');
|
|
11
11
|
var AxiosError = require('../core/AxiosError');
|
|
12
|
-
var
|
|
12
|
+
var canceledErrorFromSignal = require('../cancel/fromSignal');
|
|
13
13
|
var parseProtocol = require('../helpers/parseProtocol');
|
|
14
14
|
var platform = require('../platform');
|
|
15
15
|
|
|
@@ -261,7 +261,7 @@ module.exports = function xhrAdapter(config) {
|
|
|
261
261
|
}
|
|
262
262
|
reject(
|
|
263
263
|
!cancel || cancel.type
|
|
264
|
-
?
|
|
264
|
+
? canceledErrorFromSignal(config.signal, config, request)
|
|
265
265
|
: cancel
|
|
266
266
|
);
|
|
267
267
|
request.abort();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var CanceledError = require('./CanceledError');
|
|
4
|
+
|
|
5
|
+
module.exports = function fromSignal(signal, config, request) {
|
|
6
|
+
var error = new CanceledError(null, config, request);
|
|
7
|
+
|
|
8
|
+
if (signal) {
|
|
9
|
+
try {
|
|
10
|
+
var reason = signal.reason;
|
|
11
|
+
if (reason !== undefined) {
|
|
12
|
+
error.reason = reason;
|
|
13
|
+
}
|
|
14
|
+
} catch (e) {
|
|
15
|
+
// A custom signal getter must not prevent cancellation.
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return error;
|
|
20
|
+
};
|
package/lib/core/Axios.js
CHANGED
|
@@ -9,6 +9,56 @@ var buildFullPath = require('./buildFullPath');
|
|
|
9
9
|
var validator = require('../helpers/validator');
|
|
10
10
|
|
|
11
11
|
var validators = validator.validators;
|
|
12
|
+
|
|
13
|
+
function captureCallerStack(boundary) {
|
|
14
|
+
var caller = {};
|
|
15
|
+
try {
|
|
16
|
+
if (Error.captureStackTrace) {
|
|
17
|
+
Error.captureStackTrace(caller, boundary);
|
|
18
|
+
} else {
|
|
19
|
+
caller = new Error();
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// Stack hooks must not prevent a request from being sent.
|
|
23
|
+
}
|
|
24
|
+
return caller;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function attachCallerStack(promise, caller) {
|
|
28
|
+
if (!caller) {
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return promise.then(null, function onRequestRejected(error) {
|
|
33
|
+
try {
|
|
34
|
+
if (error instanceof Error || Object.prototype.toString.call(error) === '[object Error]') {
|
|
35
|
+
// Capture at dispatch time, but only format the stack on failure.
|
|
36
|
+
// Capturing in this callback would lose callers using .then/.catch.
|
|
37
|
+
var stack = caller.stack;
|
|
38
|
+
if (typeof stack === 'string') {
|
|
39
|
+
var newline = stack.indexOf('\n');
|
|
40
|
+
stack = newline === -1 ? '' : stack.slice(newline + 1);
|
|
41
|
+
var original = error.stack;
|
|
42
|
+
if (stack && (original === undefined || original === null || original === '')) {
|
|
43
|
+
error.stack = stack;
|
|
44
|
+
} else if (stack && typeof original === 'string' && original.indexOf(stack) === -1) {
|
|
45
|
+
error.stack = original + '\n' + stack;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// Frozen errors and custom stack accessors must retain their rejection.
|
|
51
|
+
}
|
|
52
|
+
return Promise.reject(error);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dispatchAfterRecovery(config) {
|
|
57
|
+
return function dispatchRecoveredRequest() {
|
|
58
|
+
return dispatchRequest(config);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
12
62
|
/**
|
|
13
63
|
* Create a new instance of Axios
|
|
14
64
|
*
|
|
@@ -39,11 +89,14 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
39
89
|
}
|
|
40
90
|
|
|
41
91
|
config = mergeConfig(this.defaults, config);
|
|
92
|
+
var caller = config.captureCallerStack === true ? captureCallerStack(request) : null;
|
|
42
93
|
|
|
43
|
-
// Set config.method
|
|
94
|
+
// Set config.method. The merged config is null-prototype, but instance
|
|
95
|
+
// defaults may be an ordinary object, so the fallback is read as an own
|
|
96
|
+
// property to keep an inherited value from choosing the request method.
|
|
44
97
|
if (config.method) {
|
|
45
98
|
config.method = config.method.toLowerCase();
|
|
46
|
-
} else if (this.defaults.method) {
|
|
99
|
+
} else if (utils.hasOwnProperty(this.defaults, 'method') && this.defaults.method) {
|
|
47
100
|
config.method = this.defaults.method.toLowerCase();
|
|
48
101
|
} else {
|
|
49
102
|
config.method = 'get';
|
|
@@ -105,7 +158,7 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
105
158
|
promise = promise.then(chain.shift(), chain.shift());
|
|
106
159
|
}
|
|
107
160
|
|
|
108
|
-
return promise;
|
|
161
|
+
return attachCallerStack(promise, caller);
|
|
109
162
|
}
|
|
110
163
|
|
|
111
164
|
|
|
@@ -114,24 +167,39 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
114
167
|
var onFulfilled = requestInterceptorChain.shift();
|
|
115
168
|
var onRejected = requestInterceptorChain.shift();
|
|
116
169
|
try {
|
|
117
|
-
newConfig = onFulfilled(newConfig);
|
|
170
|
+
newConfig = onFulfilled ? onFulfilled(newConfig) : newConfig;
|
|
118
171
|
} catch (error) {
|
|
119
|
-
onRejected
|
|
172
|
+
if (!onRejected) {
|
|
173
|
+
promise = Promise.reject(error);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
var recovery = onRejected(error);
|
|
178
|
+
if (recovery && typeof recovery.then === 'function') {
|
|
179
|
+
promise = Promise.resolve(recovery).then(dispatchAfterRecovery(newConfig));
|
|
180
|
+
}
|
|
181
|
+
} catch (rejectedError) {
|
|
182
|
+
promise = Promise.reject(rejectedError);
|
|
183
|
+
}
|
|
120
184
|
break;
|
|
121
185
|
}
|
|
122
186
|
}
|
|
123
187
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
188
|
+
if (!promise) {
|
|
189
|
+
try {
|
|
190
|
+
promise = dispatchRequest(newConfig);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
// Dispatch errors, including pre-aborted signals, still go through the
|
|
193
|
+
// response interceptors registered below.
|
|
194
|
+
promise = Promise.reject(error);
|
|
195
|
+
}
|
|
128
196
|
}
|
|
129
197
|
|
|
130
198
|
while (responseInterceptorChain.length) {
|
|
131
199
|
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
|
132
200
|
}
|
|
133
201
|
|
|
134
|
-
return promise;
|
|
202
|
+
return attachCallerStack(promise, caller);
|
|
135
203
|
};
|
|
136
204
|
|
|
137
205
|
Axios.prototype.getUri = function getUri(config) {
|
|
@@ -4,7 +4,7 @@ var utils = require('./../utils');
|
|
|
4
4
|
var transformData = require('./transformData');
|
|
5
5
|
var isCancel = require('../cancel/isCancel');
|
|
6
6
|
var defaults = require('../defaults');
|
|
7
|
-
var
|
|
7
|
+
var canceledErrorFromSignal = require('../cancel/fromSignal');
|
|
8
8
|
var normalizeHeaderName = require('../helpers/normalizeHeaderName');
|
|
9
9
|
var sanitizeHeaderValue = require('../helpers/sanitizeHeaderValue');
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ function throwIfCancellationRequested(config) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
if (config.signal && config.signal.aborted) {
|
|
20
|
-
throw
|
|
20
|
+
throw canceledErrorFromSignal(config.signal, config);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -30,8 +30,9 @@ function throwIfCancellationRequested(config) {
|
|
|
30
30
|
module.exports = function dispatchRequest(config) {
|
|
31
31
|
throwIfCancellationRequested(config);
|
|
32
32
|
|
|
33
|
-
// Ensure headers exist
|
|
34
|
-
|
|
33
|
+
// Ensure headers exist. A request interceptor may return a replacement config
|
|
34
|
+
// that inherits from Object.prototype, so only an own headers value is used.
|
|
35
|
+
config.headers = (utils.hasOwnProperty(config, 'headers') && config.headers) || {};
|
|
35
36
|
|
|
36
37
|
// Transform request data
|
|
37
38
|
config.data = transformData.call(
|
package/lib/core/mergeConfig.js
CHANGED
|
@@ -63,6 +63,11 @@ module.exports = function mergeConfig(config1, config2) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
function defaultToConfig2Reference(prop) {
|
|
67
|
+
var value = getOwn(config2, prop);
|
|
68
|
+
return utils.isUndefined(value) ? getOwn(config1, prop) : value;
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
// eslint-disable-next-line consistent-return
|
|
67
72
|
function mergeDirectKeys(prop) {
|
|
68
73
|
if (hasOwn(config2, prop)) {
|
|
@@ -98,6 +103,8 @@ module.exports = function mergeConfig(config1, config2) {
|
|
|
98
103
|
'httpAgent': defaultToConfig2,
|
|
99
104
|
'httpsAgent': defaultToConfig2,
|
|
100
105
|
'cancelToken': defaultToConfig2,
|
|
106
|
+
// Signals are live objects; cloning them snapshots getters and reasons.
|
|
107
|
+
'signal': defaultToConfig2Reference,
|
|
101
108
|
'socketPath': defaultToConfig2,
|
|
102
109
|
'allowedSocketPaths': defaultToConfig2,
|
|
103
110
|
'responseEncoding': defaultToConfig2,
|
package/lib/env/data.js
CHANGED
|
@@ -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
|
|
|
@@ -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
|