axios 0.31.0 → 0.32.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.
@@ -69,6 +69,7 @@ function toFormData(obj, formData, options) {
69
69
  var dots = options.dots;
70
70
  var indexes = options.indexes;
71
71
  var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
72
+ var maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
72
73
  var useBlob = _Blob && isSpecCompliant(formData);
73
74
 
74
75
  if (!utils.isFunction(visitor)) {
@@ -145,9 +146,19 @@ function toFormData(obj, formData, options) {
145
146
  isVisitable: isVisitable
146
147
  });
147
148
 
148
- function build(value, path) {
149
+ function build(value, path, depth) {
149
150
  if (utils.isUndefined(value)) return;
150
151
 
152
+ // eslint-disable-next-line no-param-reassign
153
+ depth = depth || 0;
154
+
155
+ if (depth > maxDepth) {
156
+ throw new AxiosError(
157
+ 'Maximum object depth of ' + maxDepth + ' exceeded (got ' + depth + ' levels)',
158
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
159
+ );
160
+ }
161
+
151
162
  if (stack.indexOf(value) !== -1) {
152
163
  throw Error('Circular reference detected in ' + path.join('.'));
153
164
  }
@@ -160,7 +171,7 @@ function toFormData(obj, formData, options) {
160
171
  );
161
172
 
162
173
  if (result === true) {
163
- build(el, path ? path.concat(key) : [key]);
174
+ build(el, path ? path.concat(key) : [key], depth + 1);
164
175
  }
165
176
  });
166
177
 
@@ -171,7 +182,7 @@ function toFormData(obj, formData, options) {
171
182
  throw new TypeError('data must be an object');
172
183
  }
173
184
 
174
- build(obj);
185
+ build(obj, null, 0);
175
186
 
176
187
  return formData;
177
188
  }
package/lib/utils.js CHANGED
@@ -49,8 +49,14 @@ function isUndefined(val) {
49
49
  * @returns {boolean} True if value is a Buffer, otherwise false
50
50
  */
51
51
  function isBuffer(val) {
52
- return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
53
- && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
52
+ return (
53
+ val !== null &&
54
+ !isUndefined(val) &&
55
+ val.constructor !== null &&
56
+ !isUndefined(val.constructor) &&
57
+ typeof val.constructor.isBuffer === 'function' &&
58
+ val.constructor.isBuffer(val)
59
+ );
54
60
  }
55
61
 
56
62
  /**
@@ -62,7 +68,6 @@ function isBuffer(val) {
62
68
  */
63
69
  var isArrayBuffer = kindOfTest('ArrayBuffer');
64
70
 
65
-
66
71
  /**
67
72
  * Determine if a value is a view on an ArrayBuffer
68
73
  *
@@ -71,10 +76,10 @@ var isArrayBuffer = kindOfTest('ArrayBuffer');
71
76
  */
72
77
  function isArrayBufferView(val) {
73
78
  var result;
74
- if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
79
+ if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {
75
80
  result = ArrayBuffer.isView(val);
76
81
  } else {
77
- result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
82
+ result = val && val.buffer && isArrayBuffer(val.buffer);
78
83
  }
79
84
  return result;
80
85
  }
@@ -206,8 +211,16 @@ function isStream(val) {
206
211
  */
207
212
  function isFormData(thing) {
208
213
  var pattern = '[object FormData]';
209
- return thing && (
210
- (typeof FormData === 'function' && thing instanceof FormData) ||
214
+ if (!thing) return false;
215
+ if (typeof FormData === 'function' && thing instanceof FormData) return true;
216
+ // Reject non-objects (strings, numbers, booleans) up front — Object.getPrototypeOf
217
+ // throws a TypeError on primitives in ES5 environments.
218
+ if (!isObject(thing)) return false;
219
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData.
220
+ var proto = Object.getPrototypeOf(thing);
221
+ if (!proto || proto === Object.prototype) return false;
222
+ if (!isFunction(thing.append)) return false;
223
+ return (
211
224
  toString.call(thing) === pattern ||
212
225
  (isFunction(thing.toString) && thing.toString() === pattern)
213
226
  );
@@ -228,7 +241,9 @@ var isURLSearchParams = kindOfTest('URLSearchParams');
228
241
  * @returns {String} The String freed of excess whitespace
229
242
  */
230
243
  function trim(str) {
231
- return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
244
+ return str.trim
245
+ ? str.trim()
246
+ : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
232
247
  }
233
248
 
234
249
  /**
@@ -248,10 +263,11 @@ function trim(str) {
248
263
  */
249
264
  function isStandardBrowserEnv() {
250
265
  var product;
251
- if (typeof navigator !== 'undefined' && (
252
- (product = navigator.product) === 'ReactNative' ||
253
- product === 'NativeScript' ||
254
- product === 'NS')
266
+ if (
267
+ typeof navigator !== 'undefined' &&
268
+ ((product = navigator.product) === 'ReactNative' ||
269
+ product === 'NativeScript' ||
270
+ product === 'NS')
255
271
  ) {
256
272
  return false;
257
273
  }
@@ -316,14 +332,20 @@ function forEach(obj, fn) {
316
332
  * @returns {Object} Result of all merge properties
317
333
  */
318
334
  function merge(/* obj1, obj2, obj3, ... */) {
319
- var result = {};
335
+ var result = Object.create(null);
320
336
  function assignValue(val, key) {
337
+ var target;
338
+
321
339
  if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
322
340
  return;
323
341
  }
324
342
 
325
- if (isPlainObject(result[key]) && isPlainObject(val)) {
326
- result[key] = merge(result[key], val);
343
+ target = Object.prototype.hasOwnProperty.call(result, key)
344
+ ? result[key]
345
+ : undefined;
346
+
347
+ if (isPlainObject(target) && isPlainObject(val)) {
348
+ result[key] = merge(target, val);
327
349
  } else if (isPlainObject(val)) {
328
350
  result[key] = merge({}, val);
329
351
  } else if (isArray(val)) {
@@ -365,7 +387,7 @@ function extend(a, b, thisArg) {
365
387
  * @return {string} content value without BOM
366
388
  */
367
389
  function stripBOM(content) {
368
- if (content.charCodeAt(0) === 0xFEFF) {
390
+ if (content.charCodeAt(0) === 0xfeff) {
369
391
  content = content.slice(1);
370
392
  }
371
393
  return content;
@@ -380,7 +402,10 @@ function stripBOM(content) {
380
402
  */
381
403
 
382
404
  function inherits(constructor, superConstructor, props, descriptors) {
383
- constructor.prototype = Object.create(superConstructor.prototype, descriptors);
405
+ constructor.prototype = Object.create(
406
+ superConstructor.prototype,
407
+ descriptors
408
+ );
384
409
  constructor.prototype.constructor = constructor;
385
410
  props && Object.assign(constructor.prototype, props);
386
411
  }
@@ -409,13 +434,20 @@ function toFlatObject(sourceObj, destObj, filter, propFilter) {
409
434
  i = props.length;
410
435
  while (i-- > 0) {
411
436
  prop = props[i];
412
- if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
437
+ if (
438
+ (!propFilter || propFilter(prop, sourceObj, destObj)) &&
439
+ !merged[prop]
440
+ ) {
413
441
  destObj[prop] = sourceObj[prop];
414
442
  merged[prop] = true;
415
443
  }
416
444
  }
417
445
  sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
418
- } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
446
+ } while (
447
+ sourceObj &&
448
+ (!filter || filter(sourceObj, destObj)) &&
449
+ sourceObj !== Object.prototype
450
+ );
419
451
 
420
452
  return destObj;
421
453
  }
@@ -437,7 +469,6 @@ function endsWith(str, searchString, position) {
437
469
  return lastIndex !== -1 && lastIndex === position;
438
470
  }
439
471
 
440
-
441
472
  /**
442
473
  * Returns new array from array like object or null if failed
443
474
  * @param {*} [thing]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -97,4 +97,4 @@
97
97
  "threshold": "5kB"
98
98
  }
99
99
  ]
100
- }
100
+ }