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.
@@ -1,4 +1,4 @@
1
- /*! Axios v1.16.1 Copyright (c) 2026 Matt Zabriskie and contributors */
1
+ /*! Axios v1.18.0 Copyright (c) 2026 Matt Zabriskie and contributors */
2
2
  'use strict';
3
3
 
4
4
  /**
@@ -20,6 +20,57 @@ const { toString } = Object.prototype;
20
20
  const { getPrototypeOf } = Object;
21
21
  const { iterator, toStringTag } = Symbol;
22
22
 
23
+ /* Creating a function that will check if an object has a property. */
24
+ const hasOwnProperty = (
25
+ ({ hasOwnProperty }) =>
26
+ (obj, prop) =>
27
+ hasOwnProperty.call(obj, prop)
28
+ )(Object.prototype);
29
+
30
+ /**
31
+ * Walk the prototype chain (excluding the shared Object.prototype) looking for
32
+ * an own `prop`. This distinguishes genuine own/inherited members — including
33
+ * class accessors and template prototypes — from members injected via
34
+ * Object.prototype pollution (e.g. `Object.prototype.username = '...'`), which
35
+ * live on Object.prototype itself and are therefore never matched.
36
+ *
37
+ * @param {*} thing The value whose chain to inspect
38
+ * @param {string|symbol} prop The property key to look for
39
+ *
40
+ * @returns {boolean} True when `prop` is owned below Object.prototype
41
+ */
42
+ const hasOwnInPrototypeChain = (thing, prop) => {
43
+ let obj = thing;
44
+ const seen = [];
45
+
46
+ while (obj != null && obj !== Object.prototype) {
47
+ if (seen.indexOf(obj) !== -1) {
48
+ return false;
49
+ }
50
+ seen.push(obj);
51
+
52
+ if (hasOwnProperty(obj, prop)) {
53
+ return true;
54
+ }
55
+ obj = getPrototypeOf(obj);
56
+ }
57
+ return false;
58
+ };
59
+
60
+ /**
61
+ * Read `obj[prop]` only when it is safe from Object.prototype pollution. Own
62
+ * properties and members inherited from a non-Object.prototype source (a class
63
+ * instance or template object) are honored; a value reachable only through a
64
+ * polluted Object.prototype is ignored and `undefined` is returned.
65
+ *
66
+ * @param {*} obj The source object
67
+ * @param {string|symbol} prop The property key to read
68
+ *
69
+ * @returns {*} The resolved value, or undefined when unsafe/absent
70
+ */
71
+ const getSafeProp = (obj, prop) =>
72
+ obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : undefined;
73
+
23
74
  const kindOf = ((cache) => (thing) => {
24
75
  const str = toString.call(thing);
25
76
  return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
@@ -145,7 +196,7 @@ const isBoolean = (thing) => thing === true || thing === false;
145
196
  * @returns {boolean} True if value is a plain Object, otherwise false
146
197
  */
147
198
  const isPlainObject = (val) => {
148
- if (kindOf(val) !== 'object') {
199
+ if (!isObject(val)) {
149
200
  return false;
150
201
  }
151
202
 
@@ -153,9 +204,12 @@ const isPlainObject = (val) => {
153
204
  return (
154
205
  (prototype === null ||
155
206
  prototype === Object.prototype ||
156
- Object.getPrototypeOf(prototype) === null) &&
157
- !(toStringTag in val) &&
158
- !(iterator in val)
207
+ getPrototypeOf(prototype) === null) &&
208
+ // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
209
+ // Symbol.iterator as evidence the value is a tagged/iterable type rather
210
+ // than a plain object, while ignoring keys injected onto Object.prototype.
211
+ !hasOwnInPrototypeChain(val, toStringTag) &&
212
+ !hasOwnInPrototypeChain(val, iterator)
159
213
  );
160
214
  };
161
215
 
@@ -424,7 +478,9 @@ function merge(...objs) {
424
478
  return;
425
479
  }
426
480
 
427
- const targetKey = (caseless && findKey(result, key)) || key;
481
+ // findKey lowercases the key, so caseless lookup only applies to strings —
482
+ // symbol keys are identity-matched.
483
+ const targetKey = (caseless && typeof key === 'string' && findKey(result, key)) || key;
428
484
  // Read via own-prop only — a bare `result[targetKey]` walks the prototype
429
485
  // chain, so a polluted Object.prototype value could surface here and get
430
486
  // copied into the merged result.
@@ -441,7 +497,24 @@ function merge(...objs) {
441
497
  };
442
498
 
443
499
  for (let i = 0, l = objs.length; i < l; i++) {
444
- objs[i] && forEach(objs[i], assignValue);
500
+ const source = objs[i];
501
+ if (!source || isBuffer(source)) {
502
+ continue;
503
+ }
504
+
505
+ forEach(source, assignValue);
506
+
507
+ if (typeof source !== 'object' || isArray(source)) {
508
+ continue;
509
+ }
510
+
511
+ const symbols = Object.getOwnPropertySymbols(source);
512
+ for (let j = 0; j < symbols.length; j++) {
513
+ const symbol = symbols[j];
514
+ if (propertyIsEnumerable.call(source, symbol)) {
515
+ assignValue(source[symbol], symbol);
516
+ }
517
+ }
445
518
  }
446
519
  return result;
447
520
  }
@@ -663,12 +736,7 @@ const toCamelCase = (str) => {
663
736
  });
664
737
  };
665
738
 
666
- /* Creating a function that will check if an object has a property. */
667
- const hasOwnProperty = (
668
- ({ hasOwnProperty }) =>
669
- (obj, prop) =>
670
- hasOwnProperty.call(obj, prop)
671
- )(Object.prototype);
739
+ const { propertyIsEnumerable } = Object.prototype;
672
740
 
673
741
  /**
674
742
  * Determine if a value is a RegExp object
@@ -881,6 +949,20 @@ const asap =
881
949
 
882
950
  const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
883
951
 
952
+ /**
953
+ * Determine if a value is iterable via an iterator that is NOT sourced solely
954
+ * from a polluted Object.prototype. Use this instead of `isIterable` whenever
955
+ * the iterable comes from untrusted input (e.g. user-supplied header sources),
956
+ * so `Object.prototype[Symbol.iterator] = ...` cannot turn an ordinary object
957
+ * into an attacker-controlled entries iterator.
958
+ *
959
+ * @param {*} thing The value to test
960
+ *
961
+ * @returns {boolean} True if value has a non-polluted iterator
962
+ */
963
+ const isSafeIterable = (thing) =>
964
+ thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
965
+
884
966
  var utils$1 = {
885
967
  isArray,
886
968
  isArrayBuffer,
@@ -925,6 +1007,8 @@ var utils$1 = {
925
1007
  isHTMLForm,
926
1008
  hasOwnProperty,
927
1009
  hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
1010
+ hasOwnInPrototypeChain,
1011
+ getSafeProp,
928
1012
  reduceDescriptors,
929
1013
  freezeMethods,
930
1014
  toObjectSet,
@@ -941,6 +1025,7 @@ var utils$1 = {
941
1025
  setImmediate: _setImmediate,
942
1026
  asap,
943
1027
  isIterable,
1028
+ isSafeIterable,
944
1029
  };
945
1030
 
946
1031
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1151,7 +1236,7 @@ class AxiosHeaders {
1151
1236
  const lHeader = normalizeHeader(_header);
1152
1237
 
1153
1238
  if (!lHeader) {
1154
- throw new Error('header name must be a non-empty string');
1239
+ return;
1155
1240
  }
1156
1241
 
1157
1242
  const key = utils$1.findKey(self, lHeader);
@@ -1173,20 +1258,23 @@ class AxiosHeaders {
1173
1258
  setHeaders(header, valueOrRewrite);
1174
1259
  } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1175
1260
  setHeaders(parseHeaders(header), valueOrRewrite);
1176
- } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
1177
- let obj = {},
1261
+ } else if (utils$1.isObject(header) && utils$1.isSafeIterable(header)) {
1262
+ let obj = Object.create(null),
1178
1263
  dest,
1179
1264
  key;
1180
1265
  for (const entry of header) {
1181
1266
  if (!utils$1.isArray(entry)) {
1182
- throw TypeError('Object iterator must return a key-value pair');
1267
+ throw new TypeError('Object iterator must return a key-value pair');
1183
1268
  }
1184
1269
 
1185
- obj[(key = entry[0])] = (dest = obj[key])
1186
- ? utils$1.isArray(dest)
1187
- ? [...dest, entry[1]]
1188
- : [dest, entry[1]]
1189
- : entry[1];
1270
+ key = entry[0];
1271
+
1272
+ if (utils$1.hasOwnProp(obj, key)) {
1273
+ dest = obj[key];
1274
+ obj[key] = utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]];
1275
+ } else {
1276
+ obj[key] = entry[1];
1277
+ }
1190
1278
  }
1191
1279
 
1192
1280
  setHeaders(obj, valueOrRewrite);
@@ -1580,6 +1668,10 @@ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
1580
1668
  // eslint-disable-next-line strict
1581
1669
  var httpAdapter = null;
1582
1670
 
1671
+ // Default nesting limit shared with the inverse transform (formDataToJSON) so
1672
+ // the FormData <-> JSON round-trip stays symmetric.
1673
+ const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
1674
+
1583
1675
  /**
1584
1676
  * Determines if the given thing is a array or js object.
1585
1677
  *
@@ -1690,8 +1782,9 @@ function toFormData(obj, formData, options) {
1690
1782
  const dots = options.dots;
1691
1783
  const indexes = options.indexes;
1692
1784
  const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
1693
- const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
1785
+ const maxDepth = options.maxDepth === undefined ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
1694
1786
  const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
1787
+ const stack = [];
1695
1788
 
1696
1789
  if (!utils$1.isFunction(visitor)) {
1697
1790
  throw new TypeError('visitor must be a function');
@@ -1719,6 +1812,38 @@ function toFormData(obj, formData, options) {
1719
1812
  return value;
1720
1813
  }
1721
1814
 
1815
+ function throwIfMaxDepthExceeded(depth) {
1816
+ if (depth > maxDepth) {
1817
+ throw new AxiosError(
1818
+ 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
1819
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
1820
+ );
1821
+ }
1822
+ }
1823
+
1824
+ function stringifyWithDepthLimit(value, depth) {
1825
+ if (maxDepth === Infinity) {
1826
+ return JSON.stringify(value);
1827
+ }
1828
+
1829
+ const ancestors = [];
1830
+
1831
+ return JSON.stringify(value, function limitDepth(_key, currentValue) {
1832
+ if (!utils$1.isObject(currentValue)) {
1833
+ return currentValue;
1834
+ }
1835
+
1836
+ while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
1837
+ ancestors.pop();
1838
+ }
1839
+
1840
+ ancestors.push(currentValue);
1841
+ throwIfMaxDepthExceeded(depth + ancestors.length - 1);
1842
+
1843
+ return currentValue;
1844
+ });
1845
+ }
1846
+
1722
1847
  /**
1723
1848
  * Default visitor.
1724
1849
  *
@@ -1742,7 +1867,7 @@ function toFormData(obj, formData, options) {
1742
1867
  // eslint-disable-next-line no-param-reassign
1743
1868
  key = metaTokens ? key : key.slice(0, -2);
1744
1869
  // eslint-disable-next-line no-param-reassign
1745
- value = JSON.stringify(value);
1870
+ value = stringifyWithDepthLimit(value, 1);
1746
1871
  } else if (
1747
1872
  (utils$1.isArray(value) && isFlatArray(value)) ||
1748
1873
  ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value)))
@@ -1775,8 +1900,6 @@ function toFormData(obj, formData, options) {
1775
1900
  return false;
1776
1901
  }
1777
1902
 
1778
- const stack = [];
1779
-
1780
1903
  const exposedHelpers = Object.assign(predicates, {
1781
1904
  defaultVisitor,
1782
1905
  convertValue,
@@ -1786,15 +1909,10 @@ function toFormData(obj, formData, options) {
1786
1909
  function build(value, path, depth = 0) {
1787
1910
  if (utils$1.isUndefined(value)) return;
1788
1911
 
1789
- if (depth > maxDepth) {
1790
- throw new AxiosError(
1791
- 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
1792
- AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
1793
- );
1794
- }
1912
+ throwIfMaxDepthExceeded(depth);
1795
1913
 
1796
1914
  if (stack.indexOf(value) !== -1) {
1797
- throw Error('Circular reference detected in ' + path.join('.'));
1915
+ throw new Error('Circular reference detected in ' + path.join('.'));
1798
1916
  }
1799
1917
 
1800
1918
  stack.push(value);
@@ -1907,15 +2025,17 @@ function buildURL(url, params, options) {
1907
2025
  return url;
1908
2026
  }
1909
2027
 
1910
- const _encode = (options && options.encode) || encode;
1911
-
1912
2028
  const _options = utils$1.isFunction(options)
1913
2029
  ? {
1914
2030
  serialize: options,
1915
2031
  }
1916
2032
  : options;
1917
2033
 
1918
- const serializeFn = _options && _options.serialize;
2034
+ // Read serializer options pollution-safely: own properties and methods on a
2035
+ // class/template prototype are honored, but values injected onto a polluted
2036
+ // Object.prototype are ignored.
2037
+ const _encode = utils$1.getSafeProp(_options, 'encode') || encode;
2038
+ const serializeFn = utils$1.getSafeProp(_options, 'serialize');
1919
2039
 
1920
2040
  let serializedParams;
1921
2041
 
@@ -2011,6 +2131,8 @@ var transitionalDefaults = {
2011
2131
  forcedJSONParsing: true,
2012
2132
  clarifyTimeoutError: false,
2013
2133
  legacyInterceptorReqResOrdering: true,
2134
+ advertiseZstdAcceptEncoding: false,
2135
+ validateStatusUndefinedResolves: true,
2014
2136
  };
2015
2137
 
2016
2138
  var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
@@ -2102,6 +2224,17 @@ function toURLEncodedForm(data, options) {
2102
2224
  });
2103
2225
  }
2104
2226
 
2227
+ const MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
2228
+
2229
+ function throwIfDepthExceeded(index) {
2230
+ if (index > MAX_DEPTH) {
2231
+ throw new AxiosError(
2232
+ 'FormData field is too deeply nested (' + index + ' levels). Max depth: ' + MAX_DEPTH,
2233
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
2234
+ );
2235
+ }
2236
+ }
2237
+
2105
2238
  /**
2106
2239
  * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
2107
2240
  *
@@ -2114,9 +2247,16 @@ function parsePropPath(name) {
2114
2247
  // foo.x.y.z
2115
2248
  // foo-x-y-z
2116
2249
  // foo x y z
2117
- return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
2118
- return match[0] === '[]' ? '' : match[1] || match[0];
2119
- });
2250
+ const path = [];
2251
+ const pattern = /\w+|\[(\w*)]/g;
2252
+ let match;
2253
+
2254
+ while ((match = pattern.exec(name)) !== null) {
2255
+ throwIfDepthExceeded(path.length);
2256
+ path.push(match[0] === '[]' ? '' : match[1] || match[0]);
2257
+ }
2258
+
2259
+ return path;
2120
2260
  }
2121
2261
 
2122
2262
  /**
@@ -2148,6 +2288,8 @@ function arrayToObject(arr) {
2148
2288
  */
2149
2289
  function formDataToJSON(formData) {
2150
2290
  function buildPath(path, value, target, index) {
2291
+ throwIfDepthExceeded(index);
2292
+
2151
2293
  let name = path[index++];
2152
2294
 
2153
2295
  if (name === '__proto__') return true;
@@ -2684,6 +2826,31 @@ function combineURLs(baseURL, relativeURL) {
2684
2826
  : baseURL;
2685
2827
  }
2686
2828
 
2829
+ const malformedHttpProtocol = /^https?:(?!\/\/)/i;
2830
+ const httpProtocolControlCharacters = /[\t\n\r]/g;
2831
+
2832
+ function stripLeadingC0ControlOrSpace(url) {
2833
+ let i = 0;
2834
+ while (i < url.length && url.charCodeAt(i) <= 0x20) {
2835
+ i++;
2836
+ }
2837
+ return url.slice(i);
2838
+ }
2839
+
2840
+ function normalizeURLForProtocolCheck(url) {
2841
+ return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, '');
2842
+ }
2843
+
2844
+ function assertValidHttpProtocolURL(url, config) {
2845
+ if (typeof url === 'string' && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
2846
+ throw new AxiosError(
2847
+ 'Invalid URL: missing "//" after protocol',
2848
+ AxiosError.ERR_INVALID_URL,
2849
+ config
2850
+ );
2851
+ }
2852
+ }
2853
+
2687
2854
  /**
2688
2855
  * Creates a new URL by combining the baseURL with the requestedURL,
2689
2856
  * only when the requestedURL is not already an absolute URL.
@@ -2694,9 +2861,11 @@ function combineURLs(baseURL, relativeURL) {
2694
2861
  *
2695
2862
  * @returns {string} The combined full path
2696
2863
  */
2697
- function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2864
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config) {
2865
+ assertValidHttpProtocolURL(requestedURL, config);
2698
2866
  let isRelativeUrl = !isAbsoluteURL(requestedURL);
2699
2867
  if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
2868
+ assertValidHttpProtocolURL(baseURL, config);
2700
2869
  return combineURLs(baseURL, requestedURL);
2701
2870
  }
2702
2871
  return requestedURL;
@@ -2767,6 +2936,28 @@ function mergeConfig(config1, config2) {
2767
2936
  }
2768
2937
  }
2769
2938
 
2939
+ function getMergedTransitionalOption(prop) {
2940
+ const transitional2 = utils$1.hasOwnProp(config2, 'transitional') ? config2.transitional : undefined;
2941
+
2942
+ if (!utils$1.isUndefined(transitional2)) {
2943
+ if (utils$1.isPlainObject(transitional2)) {
2944
+ if (utils$1.hasOwnProp(transitional2, prop)) {
2945
+ return transitional2[prop];
2946
+ }
2947
+ } else {
2948
+ return undefined;
2949
+ }
2950
+ }
2951
+
2952
+ const transitional1 = utils$1.hasOwnProp(config1, 'transitional') ? config1.transitional : undefined;
2953
+
2954
+ if (utils$1.isPlainObject(transitional1) && utils$1.hasOwnProp(transitional1, prop)) {
2955
+ return transitional1[prop];
2956
+ }
2957
+
2958
+ return undefined;
2959
+ }
2960
+
2770
2961
  // eslint-disable-next-line consistent-return
2771
2962
  function mergeDirectKeys(a, b, prop) {
2772
2963
  if (utils$1.hasOwnProp(config2, prop)) {
@@ -2819,6 +3010,18 @@ function mergeConfig(config1, config2) {
2819
3010
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2820
3011
  });
2821
3012
 
3013
+ if (
3014
+ utils$1.hasOwnProp(config2, 'validateStatus') &&
3015
+ utils$1.isUndefined(config2.validateStatus) &&
3016
+ getMergedTransitionalOption('validateStatusUndefinedResolves') === false
3017
+ ) {
3018
+ if (utils$1.hasOwnProp(config1, 'validateStatus')) {
3019
+ config.validateStatus = getMergedValue(undefined, config1.validateStatus);
3020
+ } else {
3021
+ delete config.validateStatus;
3022
+ }
3023
+ }
3024
+
2822
3025
  return config;
2823
3026
  }
2824
3027
 
@@ -2845,12 +3048,12 @@ function setFormDataHeaders(headers, formHeaders, policy) {
2845
3048
  *
2846
3049
  * @returns {string} UTF-8 bytes as a Latin-1 string
2847
3050
  */
2848
- const encodeUTF8 = (str) =>
3051
+ const encodeUTF8$1 = (str) =>
2849
3052
  encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
2850
3053
  String.fromCharCode(parseInt(hex, 16))
2851
3054
  );
2852
3055
 
2853
- var resolveConfig = (config) => {
3056
+ function resolveConfig(config) {
2854
3057
  const newConfig = mergeConfig({}, config);
2855
3058
 
2856
3059
  // Read only own properties to prevent prototype pollution gadgets
@@ -2870,23 +3073,29 @@ var resolveConfig = (config) => {
2870
3073
  newConfig.headers = headers = AxiosHeaders.from(headers);
2871
3074
 
2872
3075
  newConfig.url = buildURL(
2873
- buildFullPath(baseURL, url, allowAbsoluteUrls),
2874
- config.params,
2875
- config.paramsSerializer
3076
+ buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
3077
+ own('params'),
3078
+ own('paramsSerializer')
2876
3079
  );
2877
3080
 
2878
3081
  // HTTP basic authentication
2879
3082
  if (auth) {
3083
+ const username = utils$1.getSafeProp(auth, 'username') || '';
3084
+ const password = utils$1.getSafeProp(auth, 'password') || '';
3085
+
2880
3086
  headers.set(
2881
3087
  'Authorization',
2882
- 'Basic ' +
2883
- btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : ''))
3088
+ 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : ''))
2884
3089
  );
2885
3090
  }
2886
3091
 
2887
3092
  if (utils$1.isFormData(data)) {
2888
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2889
- headers.setContentType(undefined); // browser handles it
3093
+ if (
3094
+ platform.hasStandardBrowserEnv ||
3095
+ platform.hasStandardBrowserWebWorkerEnv ||
3096
+ utils$1.isReactNative(data)
3097
+ ) {
3098
+ headers.setContentType(undefined); // browser/web worker/RN handles it
2890
3099
  } else if (utils$1.isFunction(data.getHeaders)) {
2891
3100
  // Node.js FormData (like form-data package)
2892
3101
  setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
@@ -2918,7 +3127,7 @@ var resolveConfig = (config) => {
2918
3127
  }
2919
3128
 
2920
3129
  return newConfig;
2921
- };
3130
+ }
2922
3131
 
2923
3132
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2924
3133
 
@@ -3282,11 +3491,19 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
3282
3491
  * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
3283
3492
  * - For base64: compute exact decoded size using length and padding;
3284
3493
  * handle %XX at the character-count level (no string allocation).
3285
- * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
3494
+ * - For non-base64: compute the exact percent-decoded UTF-8 byte length.
3286
3495
  *
3287
3496
  * @param {string} url
3288
3497
  * @returns {number}
3289
3498
  */
3499
+ const isHexDigit = (charCode) =>
3500
+ (charCode >= 48 && charCode <= 57) ||
3501
+ (charCode >= 65 && charCode <= 70) ||
3502
+ (charCode >= 97 && charCode <= 102);
3503
+
3504
+ const isPercentEncodedByte = (str, i, len) =>
3505
+ i + 2 < len && isHexDigit(str.charCodeAt(i + 1)) && isHexDigit(str.charCodeAt(i + 2));
3506
+
3290
3507
  function estimateDataURLDecodedBytes(url) {
3291
3508
  if (!url || typeof url !== 'string') return 0;
3292
3509
  if (!url.startsWith('data:')) return 0;
@@ -3306,9 +3523,7 @@ function estimateDataURLDecodedBytes(url) {
3306
3523
  if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
3307
3524
  const a = body.charCodeAt(i + 1);
3308
3525
  const b = body.charCodeAt(i + 2);
3309
- const isHex =
3310
- ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
3311
- ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
3526
+ const isHex = isHexDigit(a) && isHexDigit(b);
3312
3527
 
3313
3528
  if (isHex) {
3314
3529
  effectiveLen -= 2;
@@ -3349,18 +3564,17 @@ function estimateDataURLDecodedBytes(url) {
3349
3564
  return bytes > 0 ? bytes : 0;
3350
3565
  }
3351
3566
 
3352
- if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
3353
- return Buffer.byteLength(body, 'utf8');
3354
- }
3355
-
3356
3567
  // Compute UTF-8 byte length directly from UTF-16 code units without allocating
3357
3568
  // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
3358
- // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
3359
- // but 3 UTF-8 bytes).
3569
+ // Valid %XX triplets count as one decoded byte; this matches the bytes that
3570
+ // decodeURIComponent(body) would produce before Buffer re-encodes the string.
3360
3571
  let bytes = 0;
3361
3572
  for (let i = 0, len = body.length; i < len; i++) {
3362
3573
  const c = body.charCodeAt(i);
3363
- if (c < 0x80) {
3574
+ if (c === 37 /* '%' */ && isPercentEncodedByte(body, i, len)) {
3575
+ bytes += 1;
3576
+ i += 2;
3577
+ } else if (c < 0x80) {
3364
3578
  bytes += 1;
3365
3579
  } else if (c < 0x800) {
3366
3580
  bytes += 2;
@@ -3379,12 +3593,41 @@ function estimateDataURLDecodedBytes(url) {
3379
3593
  return bytes;
3380
3594
  }
3381
3595
 
3382
- const VERSION = "1.16.1";
3596
+ const VERSION = "1.18.0";
3383
3597
 
3384
3598
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
3385
3599
 
3386
3600
  const { isFunction } = utils$1;
3387
3601
 
3602
+ /**
3603
+ * Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
3604
+ * This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
3605
+ *
3606
+ * @param {string} str The string to encode
3607
+ *
3608
+ * @returns {string} UTF-8 bytes as a Latin-1 string
3609
+ */
3610
+ const encodeUTF8 = (str) =>
3611
+ encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
3612
+ String.fromCharCode(parseInt(hex, 16))
3613
+ );
3614
+
3615
+ // Node's WHATWG URL parser returns `username` and `password` percent-encoded.
3616
+ // Decode before composing the `auth` option so credentials such as
3617
+ // `my%40email.com:pass` are sent as `my@email.com:pass`. Falls back to the
3618
+ // original value for malformed input so a bad encoding never throws.
3619
+ const decodeURIComponentSafe = (value) => {
3620
+ if (!utils$1.isString(value)) {
3621
+ return value;
3622
+ }
3623
+
3624
+ try {
3625
+ return decodeURIComponent(value);
3626
+ } catch (error) {
3627
+ return value;
3628
+ }
3629
+ };
3630
+
3388
3631
  const test = (fn, ...args) => {
3389
3632
  try {
3390
3633
  return !!fn(...args);
@@ -3393,6 +3636,15 @@ const test = (fn, ...args) => {
3393
3636
  }
3394
3637
  };
3395
3638
 
3639
+ const maybeWithAuthCredentials = (url) => {
3640
+ const protocolIndex = url.indexOf('://');
3641
+ let urlToCheck = url;
3642
+ if (protocolIndex !== -1) {
3643
+ urlToCheck = urlToCheck.slice(protocolIndex + 3);
3644
+ }
3645
+ return urlToCheck.includes('@') || urlToCheck.includes(':');
3646
+ };
3647
+
3396
3648
  const factory = (env) => {
3397
3649
  const globalObject =
3398
3650
  utils$1.global !== undefined && utils$1.global !== null
@@ -3540,6 +3792,7 @@ const factory = (env) => {
3540
3792
 
3541
3793
  const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
3542
3794
  const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
3795
+ const own = (key) => (utils$1.hasOwnProp(config, key) ? config[key] : undefined);
3543
3796
 
3544
3797
  let _fetch = envFetch || fetch;
3545
3798
 
@@ -3561,7 +3814,61 @@ const factory = (env) => {
3561
3814
 
3562
3815
  let requestContentLength;
3563
3816
 
3817
+ // AxiosError we raise while the request body is being streamed. Captured
3818
+ // by identity so the catch block can surface it directly, regardless of
3819
+ // how the runtime wraps the resulting fetch rejection (undici exposes it
3820
+ // as `err.cause`; some browsers drop the original error entirely).
3821
+ let pendingBodyError = null;
3822
+
3823
+ const maxBodyLengthError = () =>
3824
+ new AxiosError(
3825
+ 'Request body larger than maxBodyLength limit',
3826
+ AxiosError.ERR_BAD_REQUEST,
3827
+ config,
3828
+ request
3829
+ );
3830
+
3564
3831
  try {
3832
+ // HTTP basic authentication
3833
+ let auth = undefined;
3834
+ const configAuth = own('auth');
3835
+
3836
+ if (configAuth) {
3837
+ const username = utils$1.getSafeProp(configAuth, 'username') || '';
3838
+ const password = utils$1.getSafeProp(configAuth, 'password') || '';
3839
+ auth = {
3840
+ username,
3841
+ password
3842
+ };
3843
+ }
3844
+
3845
+ if (maybeWithAuthCredentials(url)) {
3846
+ const parsedURL = new URL(url, platform.origin);
3847
+
3848
+ if (!auth && (parsedURL.username || parsedURL.password)) {
3849
+ const urlUsername = decodeURIComponentSafe(parsedURL.username);
3850
+ const urlPassword = decodeURIComponentSafe(parsedURL.password);
3851
+ auth = {
3852
+ username: urlUsername,
3853
+ password: urlPassword
3854
+ };
3855
+ }
3856
+
3857
+ if (parsedURL.username || parsedURL.password) {
3858
+ parsedURL.username = '';
3859
+ parsedURL.password = '';
3860
+ url = parsedURL.href;
3861
+ }
3862
+ }
3863
+
3864
+ if (auth) {
3865
+ headers.delete('authorization');
3866
+ headers.set(
3867
+ 'Authorization',
3868
+ 'Basic ' + btoa(encodeUTF8((auth.username || '') + ':' + (auth.password || '')))
3869
+ );
3870
+ }
3871
+
3565
3872
  // Enforce maxContentLength for data: URLs up-front so we never materialize
3566
3873
  // an oversized payload. The HTTP adapter applies the same check (see http.js
3567
3874
  // "if (protocol === 'data:')" branch).
@@ -3577,53 +3884,96 @@ const factory = (env) => {
3577
3884
  }
3578
3885
  }
3579
3886
 
3580
- // Enforce maxBodyLength against the outbound request body before dispatch.
3581
- // Mirrors http.js behavior (ERR_BAD_REQUEST / 'Request body larger than
3582
- // maxBodyLength limit'). Skip when the body length cannot be determined
3583
- // (e.g. a live ReadableStream supplied by the caller).
3887
+ // Enforce maxBodyLength against known-size bodies before dispatch using
3888
+ // the body's *actual* size never a caller-declared Content-Length,
3889
+ // which could under-report to slip an oversized body past the check.
3890
+ // Unknown-size streams return undefined here and are counted per-chunk
3891
+ // below as fetch consumes them.
3584
3892
  if (hasMaxBodyLength && method !== 'get' && method !== 'head') {
3585
- const outboundLength = await resolveBodyLength(headers, data);
3586
- if (
3587
- typeof outboundLength === 'number' &&
3588
- isFinite(outboundLength) &&
3589
- outboundLength > maxBodyLength
3590
- ) {
3591
- throw new AxiosError(
3592
- 'Request body larger than maxBodyLength limit',
3593
- AxiosError.ERR_BAD_REQUEST,
3594
- config,
3595
- request
3596
- );
3893
+ const outboundLength = await getBodyLength(data);
3894
+ if (typeof outboundLength === 'number' && isFinite(outboundLength)) {
3895
+ requestContentLength = outboundLength;
3896
+ if (outboundLength > maxBodyLength) {
3897
+ throw maxBodyLengthError();
3898
+ }
3597
3899
  }
3598
3900
  }
3599
3901
 
3902
+ // A streamed body under maxBodyLength must be counted as fetch consumes
3903
+ // it; its size is never trusted from a caller-declared Content-Length.
3904
+ const mustEnforceStreamBody =
3905
+ hasMaxBodyLength && (utils$1.isReadableStream(data) || utils$1.isStream(data));
3906
+
3907
+ const trackRequestStream = (stream, onProgress, flush) =>
3908
+ trackStream(
3909
+ stream,
3910
+ DEFAULT_CHUNK_SIZE,
3911
+ (loadedBytes) => {
3912
+ if (hasMaxBodyLength && loadedBytes > maxBodyLength) {
3913
+ throw (pendingBodyError = maxBodyLengthError());
3914
+ }
3915
+ onProgress && onProgress(loadedBytes);
3916
+ },
3917
+ flush
3918
+ );
3919
+
3600
3920
  if (
3601
- onUploadProgress &&
3602
3921
  supportsRequestStream &&
3603
3922
  method !== 'get' &&
3604
3923
  method !== 'head' &&
3605
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
3924
+ (onUploadProgress || mustEnforceStreamBody)
3606
3925
  ) {
3607
- let _request = new Request(url, {
3608
- method: 'POST',
3609
- body: data,
3610
- duplex: 'half',
3611
- });
3926
+ requestContentLength =
3927
+ requestContentLength == null ? await resolveBodyLength(headers, data) : requestContentLength;
3928
+
3929
+ // A declared length of 0 is only trusted to skip the wrap when we are
3930
+ // not enforcing a stream limit (which must not rely on that header).
3931
+ if (requestContentLength !== 0 || mustEnforceStreamBody) {
3932
+ let _request = new Request(url, {
3933
+ method: 'POST',
3934
+ body: data,
3935
+ duplex: 'half',
3936
+ });
3612
3937
 
3613
- let contentTypeHeader;
3938
+ let contentTypeHeader;
3614
3939
 
3615
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
3616
- headers.setContentType(contentTypeHeader);
3617
- }
3940
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
3941
+ headers.setContentType(contentTypeHeader);
3942
+ }
3618
3943
 
3619
- if (_request.body) {
3620
- const [onProgress, flush] = progressEventDecorator(
3621
- requestContentLength,
3622
- progressEventReducer(asyncDecorator(onUploadProgress))
3623
- );
3944
+ if (_request.body) {
3945
+ const [onProgress, flush] =
3946
+ (onUploadProgress &&
3947
+ progressEventDecorator(
3948
+ requestContentLength,
3949
+ progressEventReducer(asyncDecorator(onUploadProgress))
3950
+ )) ||
3951
+ [];
3624
3952
 
3625
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
3953
+ data = trackRequestStream(_request.body, onProgress, flush);
3954
+ }
3626
3955
  }
3956
+ } else if (
3957
+ mustEnforceStreamBody &&
3958
+ !isRequestSupported &&
3959
+ isReadableStreamSupported &&
3960
+ method !== 'get' &&
3961
+ method !== 'head'
3962
+ ) {
3963
+ data = trackRequestStream(data);
3964
+ } else if (
3965
+ mustEnforceStreamBody &&
3966
+ isRequestSupported &&
3967
+ !supportsRequestStream &&
3968
+ method !== 'get' &&
3969
+ method !== 'head'
3970
+ ) {
3971
+ throw new AxiosError(
3972
+ 'Stream request bodies are not supported by the current fetch implementation',
3973
+ AxiosError.ERR_NOT_SUPPORT,
3974
+ config,
3975
+ request
3976
+ );
3627
3977
  }
3628
3978
 
3629
3979
  if (!utils$1.isString(withCredentials)) {
@@ -3666,10 +4016,12 @@ const factory = (env) => {
3666
4016
  ? _fetch(request, fetchOptions)
3667
4017
  : _fetch(url, resolvedOptions));
3668
4018
 
4019
+ const responseHeaders = AxiosHeaders.from(response.headers);
4020
+
3669
4021
  // Cheap pre-check: if the server honestly declares a content-length that
3670
4022
  // already exceeds the cap, reject before we start streaming.
3671
4023
  if (hasMaxContentLength) {
3672
- const declaredLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4024
+ const declaredLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
3673
4025
  if (declaredLength != null && declaredLength > maxContentLength) {
3674
4026
  throw new AxiosError(
3675
4027
  'maxContentLength size of ' + maxContentLength + ' exceeded',
@@ -3694,7 +4046,7 @@ const factory = (env) => {
3694
4046
  options[prop] = response[prop];
3695
4047
  });
3696
4048
 
3697
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4049
+ const responseContentLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
3698
4050
 
3699
4051
  const [onProgress, flush] =
3700
4052
  (onDownloadProgress &&
@@ -3789,6 +4141,23 @@ const factory = (env) => {
3789
4141
  throw canceledError;
3790
4142
  }
3791
4143
 
4144
+ // Surface a maxBodyLength violation we raised while the request body was
4145
+ // being streamed. Matching by identity (rather than reading
4146
+ // `err.cause.isAxiosError`) keeps the error deterministic across runtimes
4147
+ // and avoids both prototype-pollution reads and mis-attributing a foreign
4148
+ // AxiosError that merely happened to land in `err.cause`.
4149
+ if (pendingBodyError) {
4150
+ request && !pendingBodyError.request && (pendingBodyError.request = request);
4151
+ throw pendingBodyError;
4152
+ }
4153
+
4154
+ // Re-throw AxiosErrors we raised synchronously (data: URL / content-length
4155
+ // pre-checks, response size enforcement) without re-wrapping them.
4156
+ if (err instanceof AxiosError) {
4157
+ request && !err.request && (err.request = request);
4158
+ throw err;
4159
+ }
4160
+
3792
4161
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
3793
4162
  throw Object.assign(
3794
4163
  new AxiosError(
@@ -4243,6 +4612,8 @@ class Axios {
4243
4612
  forcedJSONParsing: validators.transitional(validators.boolean),
4244
4613
  clarifyTimeoutError: validators.transitional(validators.boolean),
4245
4614
  legacyInterceptorReqResOrdering: validators.transitional(validators.boolean),
4615
+ advertiseZstdAcceptEncoding: validators.transitional(validators.boolean),
4616
+ validateStatusUndefinedResolves: validators.transitional(validators.boolean),
4246
4617
  },
4247
4618
  false
4248
4619
  );
@@ -4372,7 +4743,7 @@ class Axios {
4372
4743
 
4373
4744
  getUri(config) {
4374
4745
  config = mergeConfig(this.defaults, config);
4375
- const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
4746
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
4376
4747
  return buildURL(fullPath, config.params, config.paramsSerializer);
4377
4748
  }
4378
4749
  }
@@ -4385,7 +4756,7 @@ utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoDa
4385
4756
  mergeConfig(config || {}, {
4386
4757
  method,
4387
4758
  url,
4388
- data: (config || {}).data,
4759
+ data: config && utils$1.hasOwnProp(config, 'data') ? config.data : undefined,
4389
4760
  })
4390
4761
  );
4391
4762
  };