axios 0.30.3 → 0.31.1

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/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // axios v0.30.3 Copyright (c) 2026 Matt Zabriskie
1
+ // axios v0.31.1 Copyright (c) 2026 Matt Zabriskie
2
2
  var bind = function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -134,7 +134,15 @@ function isPlainObject(val) {
134
134
  * @return {boolean} True if value is a empty Object, otherwise false
135
135
  */
136
136
  function isEmptyObject(val) {
137
- return val && Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
137
+ if (!isPlainObject(val)) {
138
+ return false;
139
+ }
140
+ for (var key in val) {
141
+ if (Object.prototype.hasOwnProperty.call(val, key)) {
142
+ return false;
143
+ }
144
+ }
145
+ return true;
138
146
  }
139
147
 
140
148
  /**
@@ -201,11 +209,17 @@ function isStream(val) {
201
209
  */
202
210
  function isFormData(thing) {
203
211
  var pattern = '[object FormData]';
204
- return thing && (
205
- (typeof FormData === 'function' && thing instanceof FormData) ||
206
- toString.call(thing) === pattern ||
207
- (isFunction(thing.toString) && thing.toString() === pattern)
208
- );
212
+ if (!thing) return false;
213
+ if (typeof FormData === 'function' && thing instanceof FormData) return true;
214
+ // Reject non-objects (strings, numbers, booleans) up front — Object.getPrototypeOf
215
+ // throws a TypeError on primitives in ES5 environments.
216
+ if (!isObject(thing)) return false;
217
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData (GHSA-6chq-wfr3-2hj9).
218
+ var proto = Object.getPrototypeOf(thing);
219
+ if (!proto || proto === Object.prototype) return false;
220
+ if (!isFunction(thing.append)) return false;
221
+ return toString.call(thing) === pattern ||
222
+ (isFunction(thing.toString) && thing.toString() === pattern);
209
223
  }
210
224
 
211
225
  /**
@@ -592,7 +606,8 @@ var descriptors = {};
592
606
  'ERR_BAD_REQUEST',
593
607
  'ERR_CANCELED',
594
608
  'ERR_NOT_SUPPORT',
595
- 'ERR_INVALID_URL'
609
+ 'ERR_INVALID_URL',
610
+ 'ERR_FORM_DATA_DEPTH_EXCEEDED'
596
611
  // eslint-disable-next-line func-names
597
612
  ].forEach(function(code) {
598
613
  descriptors[code] = {value: code};
@@ -693,6 +708,7 @@ function toFormData(obj, formData, options) {
693
708
  var dots = options.dots;
694
709
  var indexes = options.indexes;
695
710
  var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
711
+ var maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
696
712
  var useBlob = _Blob && isSpecCompliant(formData);
697
713
 
698
714
  if (!utils.isFunction(visitor)) {
@@ -769,9 +785,19 @@ function toFormData(obj, formData, options) {
769
785
  isVisitable: isVisitable
770
786
  });
771
787
 
772
- function build(value, path) {
788
+ function build(value, path, depth) {
773
789
  if (utils.isUndefined(value)) return;
774
790
 
791
+ // eslint-disable-next-line no-param-reassign
792
+ depth = depth || 0;
793
+
794
+ if (depth > maxDepth) {
795
+ throw new AxiosError_1(
796
+ 'Maximum object depth of ' + maxDepth + ' exceeded (got ' + depth + ' levels)',
797
+ AxiosError_1.ERR_FORM_DATA_DEPTH_EXCEEDED
798
+ );
799
+ }
800
+
775
801
  if (stack.indexOf(value) !== -1) {
776
802
  throw Error('Circular reference detected in ' + path.join('.'));
777
803
  }
@@ -784,7 +810,7 @@ function toFormData(obj, formData, options) {
784
810
  );
785
811
 
786
812
  if (result === true) {
787
- build(el, path ? path.concat(key) : [key]);
813
+ build(el, path ? path.concat(key) : [key], depth + 1);
788
814
  }
789
815
  });
790
816
 
@@ -795,7 +821,7 @@ function toFormData(obj, formData, options) {
795
821
  throw new TypeError('data must be an object');
796
822
  }
797
823
 
798
- build(obj);
824
+ build(obj, null, 0);
799
825
 
800
826
  return formData;
801
827
  }
@@ -803,16 +829,17 @@ function toFormData(obj, formData, options) {
803
829
  var toFormData_1 = toFormData;
804
830
 
805
831
  function encode$1(str) {
832
+ // Do not map `%00` back to a raw null byte (GHSA-xhjh-pmcv-23jw): that reversed
833
+ // the safe percent-encoding from encodeURIComponent and enabled null byte injection.
806
834
  var charMap = {
807
835
  '!': '%21',
808
836
  "'": '%27',
809
837
  '(': '%28',
810
838
  ')': '%29',
811
839
  '~': '%7E',
812
- '%20': '+',
813
- '%00': '\x00'
840
+ '%20': '+'
814
841
  };
815
- return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
842
+ return encodeURIComponent(str).replace(/[!'\(\)~]|%20/g, function replacer(match) {
816
843
  return charMap[match];
817
844
  });
818
845
  }
@@ -1329,7 +1356,8 @@ var xhr = function xhrAdapter(config) {
1329
1356
  var requestData = config.data;
1330
1357
  var requestHeaders = config.headers;
1331
1358
  var responseType = config.responseType;
1332
- var withXSRFToken = config.withXSRFToken;
1359
+ // Guard against prototype pollution (GHSA-xx6v-rp6x-q39c): only honor own properties.
1360
+ var withXSRFToken = utils.hasOwnProperty(config, 'withXSRFToken') ? config.withXSRFToken : undefined;
1333
1361
  var onCanceled;
1334
1362
  function done() {
1335
1363
  if (config.cancelToken) {
@@ -1457,8 +1485,11 @@ var xhr = function xhrAdapter(config) {
1457
1485
  // Specifically not if we're in a web worker, or react-native.
1458
1486
  if (utils.isStandardBrowserEnv()) {
1459
1487
  // Add xsrf header
1460
- withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
1461
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
1488
+ if (utils.isFunction(withXSRFToken)) {
1489
+ withXSRFToken = withXSRFToken(config);
1490
+ }
1491
+ // Strict boolean check (GHSA-xx6v-rp6x-q39c): only `true` short-circuits the same-origin guard.
1492
+ if (withXSRFToken === true || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
1462
1493
  // Add xsrf header
1463
1494
  var xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
1464
1495
  if (xsrfValue) {
@@ -1616,17 +1647,20 @@ var defaults = {
1616
1647
  var isFileList;
1617
1648
 
1618
1649
  if (isObjectPayload) {
1650
+ var formSerializer = utils.hasOwnProperty(this, 'formSerializer') ? this.formSerializer : undefined;
1651
+ var envOption = utils.hasOwnProperty(this, 'env') ? this.env : undefined;
1652
+
1619
1653
  if (contentType.indexOf('application/x-www-form-urlencoded') !== -1) {
1620
- return toURLEncodedForm(data, this.formSerializer).toString();
1654
+ return toURLEncodedForm(data, formSerializer).toString();
1621
1655
  }
1622
1656
 
1623
1657
  if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1624
- var _FormData = this.env && this.env.FormData;
1658
+ var _FormData = envOption && envOption.FormData;
1625
1659
 
1626
1660
  return toFormData_1(
1627
1661
  isFileList ? {'files[]': data} : data,
1628
1662
  _FormData && new _FormData(),
1629
- this.formSerializer
1663
+ formSerializer
1630
1664
  );
1631
1665
  }
1632
1666
  }
@@ -1724,6 +1758,25 @@ var isCancel = function isCancel(value) {
1724
1758
  return !!(value && value.__CANCEL__);
1725
1759
  };
1726
1760
 
1761
+ var INVALID_HEADER_VALUE_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
1762
+ var BOUNDARY_WHITESPACE_RE = /^[\x09\x20]+|[\x09\x20]+$/g;
1763
+
1764
+ function sanitizeHeaderValue(value) {
1765
+ if (value === false || value == null) {
1766
+ return value;
1767
+ }
1768
+
1769
+ if (utils.isArray(value)) {
1770
+ return value.map(sanitizeHeaderValue);
1771
+ }
1772
+
1773
+ return String(value)
1774
+ .replace(INVALID_HEADER_VALUE_RE, '')
1775
+ .replace(BOUNDARY_WHITESPACE_RE, '');
1776
+ }
1777
+
1778
+ var sanitizeHeaderValue_1 = sanitizeHeaderValue;
1779
+
1727
1780
  /**
1728
1781
  * Throws a `CanceledError` if cancellation has been requested.
1729
1782
  */
@@ -1775,6 +1828,10 @@ var dispatchRequest = function dispatchRequest(config) {
1775
1828
  }
1776
1829
  );
1777
1830
 
1831
+ utils.forEach(config.headers, function sanitizeHeaderConfigValue(value, header) {
1832
+ config.headers[header] = sanitizeHeaderValue_1(value);
1833
+ });
1834
+
1778
1835
  var adapter = config.adapter || defaults_1.adapter;
1779
1836
 
1780
1837
  return adapter(config).then(function onAdapterResolution(response) {
@@ -1821,7 +1878,17 @@ var dispatchRequest = function dispatchRequest(config) {
1821
1878
  var mergeConfig = function mergeConfig(config1, config2) {
1822
1879
  // eslint-disable-next-line no-param-reassign
1823
1880
  config2 = config2 || {};
1824
- var config = {};
1881
+ // Use a null-prototype object so a polluted Object.prototype cannot leak
1882
+ // values (e.g. transport, adapter) into the returned config via inheritance.
1883
+ var config = Object.create(null);
1884
+
1885
+ function getOwn(source, prop) {
1886
+ return utils.hasOwnProperty(source, prop) ? source[prop] : undefined;
1887
+ }
1888
+
1889
+ function hasOwn(source, prop) {
1890
+ return utils.hasOwnProperty(source, prop);
1891
+ }
1825
1892
 
1826
1893
  function getMergedValue(target, source) {
1827
1894
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
@@ -1838,34 +1905,34 @@ var mergeConfig = function mergeConfig(config1, config2) {
1838
1905
 
1839
1906
  // eslint-disable-next-line consistent-return
1840
1907
  function mergeDeepProperties(prop) {
1841
- if (!utils.isUndefined(config2[prop])) {
1842
- return getMergedValue(config1[prop], config2[prop]);
1843
- } else if (!utils.isUndefined(config1[prop])) {
1908
+ if (hasOwn(config2, prop) && !utils.isUndefined(config2[prop])) {
1909
+ return getMergedValue(getOwn(config1, prop), config2[prop]);
1910
+ } else if (hasOwn(config1, prop) && !utils.isUndefined(config1[prop])) {
1844
1911
  return getMergedValue(undefined, config1[prop]);
1845
1912
  }
1846
1913
  }
1847
1914
 
1848
1915
  // eslint-disable-next-line consistent-return
1849
1916
  function valueFromConfig2(prop) {
1850
- if (!utils.isUndefined(config2[prop])) {
1917
+ if (hasOwn(config2, prop) && !utils.isUndefined(config2[prop])) {
1851
1918
  return getMergedValue(undefined, config2[prop]);
1852
1919
  }
1853
1920
  }
1854
1921
 
1855
1922
  // eslint-disable-next-line consistent-return
1856
1923
  function defaultToConfig2(prop) {
1857
- if (!utils.isUndefined(config2[prop])) {
1924
+ if (hasOwn(config2, prop) && !utils.isUndefined(config2[prop])) {
1858
1925
  return getMergedValue(undefined, config2[prop]);
1859
- } else if (!utils.isUndefined(config1[prop])) {
1926
+ } else if (hasOwn(config1, prop) && !utils.isUndefined(config1[prop])) {
1860
1927
  return getMergedValue(undefined, config1[prop]);
1861
1928
  }
1862
1929
  }
1863
1930
 
1864
1931
  // eslint-disable-next-line consistent-return
1865
1932
  function mergeDirectKeys(prop) {
1866
- if (prop in config2) {
1867
- return getMergedValue(config1[prop], config2[prop]);
1868
- } else if (prop in config1) {
1933
+ if (hasOwn(config2, prop)) {
1934
+ return getMergedValue(getOwn(config1, prop), config2[prop]);
1935
+ } else if (hasOwn(config1, prop)) {
1869
1936
  return getMergedValue(undefined, config1[prop]);
1870
1937
  }
1871
1938
  }
@@ -1914,7 +1981,7 @@ var mergeConfig = function mergeConfig(config1, config2) {
1914
1981
  };
1915
1982
 
1916
1983
  var data = {
1917
- version: "0.30.3",
1984
+ "version": "0.31.1"
1918
1985
  };
1919
1986
 
1920
1987
  var VERSION = data.version;