axios 1.6.0 → 1.6.2

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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/index.d.cts CHANGED
@@ -414,6 +414,7 @@ declare namespace axios {
414
414
  family?: AddressFamily;
415
415
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
416
416
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
417
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
417
418
  }
418
419
 
419
420
  // Alias
package/index.d.ts CHANGED
@@ -355,6 +355,7 @@ export interface AxiosRequestConfig<D = any> {
355
355
  family?: AddressFamily;
356
356
  lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
357
357
  ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
358
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
358
359
  }
359
360
 
360
361
  // Alias
@@ -49,7 +49,7 @@ export default isXHRAdapterSupported && function (config) {
49
49
  return new Promise(function dispatchXhrRequest(resolve, reject) {
50
50
  let requestData = config.data;
51
51
  const requestHeaders = AxiosHeaders.from(config.headers).normalize();
52
- const responseType = config.responseType;
52
+ let {responseType, withXSRFToken} = config;
53
53
  let onCanceled;
54
54
  function done() {
55
55
  if (config.cancelToken) {
@@ -64,13 +64,12 @@ export default isXHRAdapterSupported && function (config) {
64
64
  let contentType;
65
65
 
66
66
  if (utils.isFormData(requestData)) {
67
- if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
67
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
68
68
  requestHeaders.setContentType(false); // Let the browser set it
69
- } else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
70
- requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
71
- } else if(utils.isString(contentType = requestHeaders.getContentType())){
69
+ } else if ((contentType = requestHeaders.getContentType()) !== false) {
72
70
  // fix semicolon duplication issue for ReactNative FormData implementation
73
- requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'))
71
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
72
+ requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
74
73
  }
75
74
  }
76
75
 
@@ -186,13 +185,16 @@ export default isXHRAdapterSupported && function (config) {
186
185
  // Add xsrf header
187
186
  // This is only done if running in a standard browser environment.
188
187
  // Specifically not if we're in a web worker, or react-native.
189
- if (platform.isStandardBrowserEnv) {
190
- // Add xsrf header
191
- // regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
192
- const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
188
+ if(platform.hasStandardBrowserEnv) {
189
+ withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
193
190
 
194
- if (xsrfValue) {
195
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
191
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
192
+ // Add xsrf header
193
+ const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
194
+
195
+ if (xsrfValue) {
196
+ requestHeaders.set(config.xsrfHeaderName, xsrfValue);
197
+ }
196
198
  }
197
199
  }
198
200
 
@@ -75,6 +75,7 @@ export default function mergeConfig(config1, config2) {
75
75
  timeout: defaultToConfig2,
76
76
  timeoutMessage: defaultToConfig2,
77
77
  withCredentials: defaultToConfig2,
78
+ withXSRFToken: defaultToConfig2,
78
79
  adapter: defaultToConfig2,
79
80
  responseType: defaultToConfig2,
80
81
  xsrfCookieName: defaultToConfig2,
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.6.0";
1
+ export const VERSION = "1.6.2";
@@ -1,52 +1,42 @@
1
- 'use strict';
2
-
3
1
  import utils from './../utils.js';
4
2
  import platform from '../platform/index.js';
5
3
 
6
- export default platform.isStandardBrowserEnv ?
7
-
8
- // Standard browser envs support document.cookie
9
- (function standardBrowserEnv() {
10
- return {
11
- write: function write(name, value, expires, path, domain, secure) {
12
- const cookie = [];
13
- cookie.push(name + '=' + encodeURIComponent(value));
14
-
15
- if (utils.isNumber(expires)) {
16
- cookie.push('expires=' + new Date(expires).toGMTString());
17
- }
18
-
19
- if (utils.isString(path)) {
20
- cookie.push('path=' + path);
21
- }
22
-
23
- if (utils.isString(domain)) {
24
- cookie.push('domain=' + domain);
25
- }
26
-
27
- if (secure === true) {
28
- cookie.push('secure');
29
- }
30
-
31
- document.cookie = cookie.join('; ');
32
- },
33
-
34
- read: function read(name) {
35
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
36
- return (match ? decodeURIComponent(match[3]) : null);
37
- },
38
-
39
- remove: function remove(name) {
40
- this.write(name, '', Date.now() - 86400000);
41
- }
42
- };
43
- })() :
44
-
45
- // Non standard browser env (web workers, react-native) lack needed support.
46
- (function nonStandardBrowserEnv() {
47
- return {
48
- write: function write() {},
49
- read: function read() { return null; },
50
- remove: function remove() {}
51
- };
52
- })();
4
+ export default platform.hasStandardBrowserEnv ?
5
+
6
+ // Standard browser envs support document.cookie
7
+ {
8
+ write(name, value, expires, path, domain, secure) {
9
+ const cookie = [name + '=' + encodeURIComponent(value)];
10
+
11
+ utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
12
+
13
+ utils.isString(path) && cookie.push('path=' + path);
14
+
15
+ utils.isString(domain) && cookie.push('domain=' + domain);
16
+
17
+ secure === true && cookie.push('secure');
18
+
19
+ document.cookie = cookie.join('; ');
20
+ },
21
+
22
+ read(name) {
23
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
24
+ return (match ? decodeURIComponent(match[3]) : null);
25
+ },
26
+
27
+ remove(name) {
28
+ this.write(name, '', Date.now() - 86400000);
29
+ }
30
+ }
31
+
32
+ :
33
+
34
+ // Non-standard browser env (web workers, react-native) lack needed support.
35
+ {
36
+ write() {},
37
+ read() {
38
+ return null;
39
+ },
40
+ remove() {}
41
+ };
42
+
@@ -3,7 +3,7 @@
3
3
  import utils from './../utils.js';
4
4
  import platform from '../platform/index.js';
5
5
 
6
- export default platform.isStandardBrowserEnv ?
6
+ export default platform.hasStandardBrowserEnv ?
7
7
 
8
8
  // Standard browser envs have full support of the APIs needed to test
9
9
  // whether the request URL is of the same origin as current location.
@@ -13,7 +13,7 @@ export default platform.isStandardBrowserEnv ?
13
13
  let originURL;
14
14
 
15
15
  /**
16
- * Parse a URL to discover it's components
16
+ * Parse a URL to discover its components
17
17
  *
18
18
  * @param {String} url The URL to be parsed
19
19
  * @returns {Object}
@@ -2,55 +2,6 @@ import URLSearchParams from './classes/URLSearchParams.js'
2
2
  import FormData from './classes/FormData.js'
3
3
  import Blob from './classes/Blob.js'
4
4
 
5
- /**
6
- * Determine if we're running in a standard browser environment
7
- *
8
- * This allows axios to run in a web worker, and react-native.
9
- * Both environments support XMLHttpRequest, but not fully standard globals.
10
- *
11
- * web workers:
12
- * typeof window -> undefined
13
- * typeof document -> undefined
14
- *
15
- * react-native:
16
- * navigator.product -> 'ReactNative'
17
- * nativescript
18
- * navigator.product -> 'NativeScript' or 'NS'
19
- *
20
- * @returns {boolean}
21
- */
22
- const isStandardBrowserEnv = (() => {
23
- let product;
24
- if (typeof navigator !== 'undefined' && (
25
- (product = navigator.product) === 'ReactNative' ||
26
- product === 'NativeScript' ||
27
- product === 'NS')
28
- ) {
29
- return false;
30
- }
31
-
32
- return typeof window !== 'undefined' && typeof document !== 'undefined';
33
- })();
34
-
35
- /**
36
- * Determine if we're running in a standard browser webWorker environment
37
- *
38
- * Although the `isStandardBrowserEnv` method indicates that
39
- * `allows axios to run in a web worker`, the WebWorker will still be
40
- * filtered out due to its judgment standard
41
- * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
42
- * This leads to a problem when axios post `FormData` in webWorker
43
- */
44
- const isStandardBrowserWebWorkerEnv = (() => {
45
- return (
46
- typeof WorkerGlobalScope !== 'undefined' &&
47
- // eslint-disable-next-line no-undef
48
- self instanceof WorkerGlobalScope &&
49
- typeof self.importScripts === 'function'
50
- );
51
- })();
52
-
53
-
54
5
  export default {
55
6
  isBrowser: true,
56
7
  classes: {
@@ -58,7 +9,5 @@ export default {
58
9
  FormData,
59
10
  Blob
60
11
  },
61
- isStandardBrowserEnv,
62
- isStandardBrowserWebWorkerEnv,
63
12
  protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
64
13
  };
@@ -0,0 +1,47 @@
1
+ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
2
+
3
+ /**
4
+ * Determine if we're running in a standard browser environment
5
+ *
6
+ * This allows axios to run in a web worker, and react-native.
7
+ * Both environments support XMLHttpRequest, but not fully standard globals.
8
+ *
9
+ * web workers:
10
+ * typeof window -> undefined
11
+ * typeof document -> undefined
12
+ *
13
+ * react-native:
14
+ * navigator.product -> 'ReactNative'
15
+ * nativescript
16
+ * navigator.product -> 'NativeScript' or 'NS'
17
+ *
18
+ * @returns {boolean}
19
+ */
20
+ const hasStandardBrowserEnv = (
21
+ (product) => {
22
+ return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
23
+ })(typeof navigator !== 'undefined' && navigator.product);
24
+
25
+ /**
26
+ * Determine if we're running in a standard browser webWorker environment
27
+ *
28
+ * Although the `isStandardBrowserEnv` method indicates that
29
+ * `allows axios to run in a web worker`, the WebWorker will still be
30
+ * filtered out due to its judgment standard
31
+ * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
32
+ * This leads to a problem when axios post `FormData` in webWorker
33
+ */
34
+ const hasStandardBrowserWebWorkerEnv = (() => {
35
+ return (
36
+ typeof WorkerGlobalScope !== 'undefined' &&
37
+ // eslint-disable-next-line no-undef
38
+ self instanceof WorkerGlobalScope &&
39
+ typeof self.importScripts === 'function'
40
+ );
41
+ })();
42
+
43
+ export {
44
+ hasBrowserEnv,
45
+ hasStandardBrowserWebWorkerEnv,
46
+ hasStandardBrowserEnv
47
+ }
@@ -1,3 +1,7 @@
1
1
  import platform from './node/index.js';
2
+ import * as utils from './common/utils.js';
2
3
 
3
- export {platform as default}
4
+ export default {
5
+ ...utils,
6
+ ...platform
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -121,6 +121,7 @@
121
121
  "karma-sauce-launcher": "^4.3.6",
122
122
  "karma-sinon": "^1.0.5",
123
123
  "karma-sourcemap-loader": "^0.3.8",
124
+ "memoizee": "^0.4.15",
124
125
  "minimist": "^1.2.7",
125
126
  "mocha": "^10.0.0",
126
127
  "multer": "^1.4.4",