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.
package/lib/utils.js CHANGED
@@ -8,6 +8,57 @@ const { toString } = Object.prototype;
8
8
  const { getPrototypeOf } = Object;
9
9
  const { iterator, toStringTag } = Symbol;
10
10
 
11
+ /* Creating a function that will check if an object has a property. */
12
+ const hasOwnProperty = (
13
+ ({ hasOwnProperty }) =>
14
+ (obj, prop) =>
15
+ hasOwnProperty.call(obj, prop)
16
+ )(Object.prototype);
17
+
18
+ /**
19
+ * Walk the prototype chain (excluding the shared Object.prototype) looking for
20
+ * an own `prop`. This distinguishes genuine own/inherited members — including
21
+ * class accessors and template prototypes — from members injected via
22
+ * Object.prototype pollution (e.g. `Object.prototype.username = '...'`), which
23
+ * live on Object.prototype itself and are therefore never matched.
24
+ *
25
+ * @param {*} thing The value whose chain to inspect
26
+ * @param {string|symbol} prop The property key to look for
27
+ *
28
+ * @returns {boolean} True when `prop` is owned below Object.prototype
29
+ */
30
+ const hasOwnInPrototypeChain = (thing, prop) => {
31
+ let obj = thing;
32
+ const seen = [];
33
+
34
+ while (obj != null && obj !== Object.prototype) {
35
+ if (seen.indexOf(obj) !== -1) {
36
+ return false;
37
+ }
38
+ seen.push(obj);
39
+
40
+ if (hasOwnProperty(obj, prop)) {
41
+ return true;
42
+ }
43
+ obj = getPrototypeOf(obj);
44
+ }
45
+ return false;
46
+ };
47
+
48
+ /**
49
+ * Read `obj[prop]` only when it is safe from Object.prototype pollution. Own
50
+ * properties and members inherited from a non-Object.prototype source (a class
51
+ * instance or template object) are honored; a value reachable only through a
52
+ * polluted Object.prototype is ignored and `undefined` is returned.
53
+ *
54
+ * @param {*} obj The source object
55
+ * @param {string|symbol} prop The property key to read
56
+ *
57
+ * @returns {*} The resolved value, or undefined when unsafe/absent
58
+ */
59
+ const getSafeProp = (obj, prop) =>
60
+ obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : undefined;
61
+
11
62
  const kindOf = ((cache) => (thing) => {
12
63
  const str = toString.call(thing);
13
64
  return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
@@ -133,7 +184,7 @@ const isBoolean = (thing) => thing === true || thing === false;
133
184
  * @returns {boolean} True if value is a plain Object, otherwise false
134
185
  */
135
186
  const isPlainObject = (val) => {
136
- if (kindOf(val) !== 'object') {
187
+ if (!isObject(val)) {
137
188
  return false;
138
189
  }
139
190
 
@@ -141,9 +192,12 @@ const isPlainObject = (val) => {
141
192
  return (
142
193
  (prototype === null ||
143
194
  prototype === Object.prototype ||
144
- Object.getPrototypeOf(prototype) === null) &&
145
- !(toStringTag in val) &&
146
- !(iterator in val)
195
+ getPrototypeOf(prototype) === null) &&
196
+ // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
197
+ // Symbol.iterator as evidence the value is a tagged/iterable type rather
198
+ // than a plain object, while ignoring keys injected onto Object.prototype.
199
+ !hasOwnInPrototypeChain(val, toStringTag) &&
200
+ !hasOwnInPrototypeChain(val, iterator)
147
201
  );
148
202
  };
149
203
 
@@ -412,7 +466,9 @@ function merge(...objs) {
412
466
  return;
413
467
  }
414
468
 
415
- const targetKey = (caseless && findKey(result, key)) || key;
469
+ // findKey lowercases the key, so caseless lookup only applies to strings —
470
+ // symbol keys are identity-matched.
471
+ const targetKey = (caseless && typeof key === 'string' && findKey(result, key)) || key;
416
472
  // Read via own-prop only — a bare `result[targetKey]` walks the prototype
417
473
  // chain, so a polluted Object.prototype value could surface here and get
418
474
  // copied into the merged result.
@@ -429,7 +485,24 @@ function merge(...objs) {
429
485
  };
430
486
 
431
487
  for (let i = 0, l = objs.length; i < l; i++) {
432
- objs[i] && forEach(objs[i], assignValue);
488
+ const source = objs[i];
489
+ if (!source || isBuffer(source)) {
490
+ continue;
491
+ }
492
+
493
+ forEach(source, assignValue);
494
+
495
+ if (typeof source !== 'object' || isArray(source)) {
496
+ continue;
497
+ }
498
+
499
+ const symbols = Object.getOwnPropertySymbols(source);
500
+ for (let j = 0; j < symbols.length; j++) {
501
+ const symbol = symbols[j];
502
+ if (propertyIsEnumerable.call(source, symbol)) {
503
+ assignValue(source[symbol], symbol);
504
+ }
505
+ }
433
506
  }
434
507
  return result;
435
508
  }
@@ -651,12 +724,7 @@ const toCamelCase = (str) => {
651
724
  });
652
725
  };
653
726
 
654
- /* Creating a function that will check if an object has a property. */
655
- const hasOwnProperty = (
656
- ({ hasOwnProperty }) =>
657
- (obj, prop) =>
658
- hasOwnProperty.call(obj, prop)
659
- )(Object.prototype);
727
+ const { propertyIsEnumerable } = Object.prototype;
660
728
 
661
729
  /**
662
730
  * Determine if a value is a RegExp object
@@ -869,6 +937,20 @@ const asap =
869
937
 
870
938
  const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
871
939
 
940
+ /**
941
+ * Determine if a value is iterable via an iterator that is NOT sourced solely
942
+ * from a polluted Object.prototype. Use this instead of `isIterable` whenever
943
+ * the iterable comes from untrusted input (e.g. user-supplied header sources),
944
+ * so `Object.prototype[Symbol.iterator] = ...` cannot turn an ordinary object
945
+ * into an attacker-controlled entries iterator.
946
+ *
947
+ * @param {*} thing The value to test
948
+ *
949
+ * @returns {boolean} True if value has a non-polluted iterator
950
+ */
951
+ const isSafeIterable = (thing) =>
952
+ thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
953
+
872
954
  export default {
873
955
  isArray,
874
956
  isArrayBuffer,
@@ -913,6 +995,8 @@ export default {
913
995
  isHTMLForm,
914
996
  hasOwnProperty,
915
997
  hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
998
+ hasOwnInPrototypeChain,
999
+ getSafeProp,
916
1000
  reduceDescriptors,
917
1001
  freezeMethods,
918
1002
  toObjectSet,
@@ -929,4 +1013,5 @@ export default {
929
1013
  setImmediate: _setImmediate,
930
1014
  asap,
931
1015
  isIterable,
1016
+ isSafeIterable,
932
1017
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.16.1",
3
+ "version": "1.18.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "./dist/node/axios.cjs",
6
6
  "module": "./index.js",
@@ -86,8 +86,8 @@
86
86
  "Justin Beckwith (https://github.com/JustinBeckwith)",
87
87
  "Martti Laine (https://github.com/codeclown)",
88
88
  "Xianming Zhong (https://github.com/chinesedfan)",
89
- "Willian Agostini (https://github.com/WillianAgostini)",
90
89
  "Shaan Majid (https://github.com/shaanmajid)",
90
+ "Willian Agostini (https://github.com/WillianAgostini)",
91
91
  "Remco Haszing (https://github.com/remcohaszing)",
92
92
  "Rikki Gibson (https://github.com/RikkiGibson)"
93
93
  ],
@@ -97,6 +97,22 @@
97
97
  "url": "https://github.com/axios/axios/issues"
98
98
  },
99
99
  "homepage": "https://axios-http.com",
100
+ "files": [
101
+ "index.js",
102
+ "index.d.ts",
103
+ "index.d.cts",
104
+ "CHANGELOG.md",
105
+ "MIGRATION_GUIDE.md",
106
+ "lib/",
107
+ "dist/axios.js",
108
+ "dist/axios.min.js",
109
+ "dist/axios.min.js.map",
110
+ "dist/esm/axios.js",
111
+ "dist/esm/axios.min.js",
112
+ "dist/esm/axios.min.js.map",
113
+ "dist/browser/axios.cjs",
114
+ "dist/node/axios.cjs"
115
+ ],
100
116
  "scripts": {
101
117
  "build": "gulp clear && cross-env NODE_ENV=production rollup -c -m",
102
118
  "version": "npm run build && git add package.json",
@@ -128,9 +144,9 @@
128
144
  },
129
145
  "devDependencies": {
130
146
  "@babel/core": "^7.29.0",
131
- "@babel/preset-env": "^7.29.2",
132
- "@commitlint/cli": "^20.5.0",
133
- "@commitlint/config-conventional": "^20.5.0",
147
+ "@babel/preset-env": "^7.29.5",
148
+ "@commitlint/cli": "^21.0.1",
149
+ "@commitlint/config-conventional": "^21.0.1",
134
150
  "@eslint/js": "^10.0.1",
135
151
  "@rollup/plugin-alias": "^6.0.0",
136
152
  "@rollup/plugin-babel": "^7.0.0",
@@ -138,34 +154,34 @@
138
154
  "@rollup/plugin-json": "^6.1.0",
139
155
  "@rollup/plugin-node-resolve": "^16.0.3",
140
156
  "@rollup/plugin-terser": "^1.0.0",
141
- "@vitest/browser": "^4.1.5",
142
- "@vitest/browser-playwright": "^4.1.5",
157
+ "@vitest/browser": "^4.1.7",
158
+ "@vitest/browser-playwright": "^4.1.7",
143
159
  "abortcontroller-polyfill": "^1.7.8",
144
160
  "acorn": "^8.16.0",
145
161
  "body-parser": "^2.2.2",
146
162
  "chalk": "^5.6.2",
147
163
  "cross-env": "^10.1.0",
148
164
  "dev-null": "^0.1.1",
149
- "eslint": "^10.2.1",
165
+ "eslint": "^10.4.0",
150
166
  "express": "^5.2.1",
151
167
  "formdata-node": "^6.0.3",
152
168
  "formidable": "^3.5.4",
153
169
  "fs-extra": "^11.3.4",
154
170
  "get-stream": "^9.0.1",
155
- "globals": "^17.5.0",
171
+ "globals": "^17.6.0",
156
172
  "gulp": "^5.0.1",
157
173
  "husky": "^9.1.7",
158
- "lint-staged": "^16.4.0",
174
+ "lint-staged": "^17.0.5",
159
175
  "minimist": "^1.2.8",
160
176
  "multer": "^2.1.1",
161
- "playwright": "^1.59.1",
177
+ "playwright": "^1.60.0",
162
178
  "prettier": "^3.8.3",
163
- "rollup": "^4.60.2",
179
+ "rollup": "^4.60.4",
164
180
  "rollup-plugin-bundle-size": "^1.0.3",
165
181
  "selfsigned": "^5.5.0",
166
182
  "stream-throttle": "^0.1.3",
167
183
  "typescript": "^5.9.3",
168
- "vitest": "^4.1.5"
184
+ "vitest": "^4.1.7"
169
185
  },
170
186
  "commitlint": {
171
187
  "rules": {