axios 1.7.9 → 1.12.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/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.7.9";
1
+ export const VERSION = "1.12.0";
@@ -16,9 +16,7 @@ function encode(val) {
16
16
  replace(/%3A/gi, ':').
17
17
  replace(/%24/g, '$').
18
18
  replace(/%2C/gi, ',').
19
- replace(/%20/g, '+').
20
- replace(/%5B/gi, '[').
21
- replace(/%5D/gi, ']');
19
+ replace(/%20/g, '+');
22
20
  }
23
21
 
24
22
  /**
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
3
+ * - For base64: compute exact decoded size using length and padding;
4
+ * handle %XX at the character-count level (no string allocation).
5
+ * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
6
+ *
7
+ * @param {string} url
8
+ * @returns {number}
9
+ */
10
+ export default function estimateDataURLDecodedBytes(url) {
11
+ if (!url || typeof url !== 'string') return 0;
12
+ if (!url.startsWith('data:')) return 0;
13
+
14
+ const comma = url.indexOf(',');
15
+ if (comma < 0) return 0;
16
+
17
+ const meta = url.slice(5, comma);
18
+ const body = url.slice(comma + 1);
19
+ const isBase64 = /;base64/i.test(meta);
20
+
21
+ if (isBase64) {
22
+ let effectiveLen = body.length;
23
+ const len = body.length; // cache length
24
+
25
+ for (let i = 0; i < len; i++) {
26
+ if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
27
+ const a = body.charCodeAt(i + 1);
28
+ const b = body.charCodeAt(i + 2);
29
+ const isHex =
30
+ ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
31
+ ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
32
+
33
+ if (isHex) {
34
+ effectiveLen -= 2;
35
+ i += 2;
36
+ }
37
+ }
38
+ }
39
+
40
+ let pad = 0;
41
+ let idx = len - 1;
42
+
43
+ const tailIsPct3D = (j) =>
44
+ j >= 2 &&
45
+ body.charCodeAt(j - 2) === 37 && // '%'
46
+ body.charCodeAt(j - 1) === 51 && // '3'
47
+ (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
48
+
49
+ if (idx >= 0) {
50
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
51
+ pad++;
52
+ idx--;
53
+ } else if (tailIsPct3D(idx)) {
54
+ pad++;
55
+ idx -= 3;
56
+ }
57
+ }
58
+
59
+ if (pad === 1 && idx >= 0) {
60
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
61
+ pad++;
62
+ } else if (tailIsPct3D(idx)) {
63
+ pad++;
64
+ }
65
+ }
66
+
67
+ const groups = Math.floor(effectiveLen / 4);
68
+ const bytes = groups * 3 - (pad || 0);
69
+ return bytes > 0 ? bytes : 0;
70
+ }
71
+
72
+ return Buffer.byteLength(body, 'utf8');
73
+ }
@@ -2,8 +2,9 @@ import util from 'util';
2
2
  import {Readable} from 'stream';
3
3
  import utils from "../utils.js";
4
4
  import readBlob from "./readBlob.js";
5
+ import platform from "../platform/index.js";
5
6
 
6
- const BOUNDARY_ALPHABET = utils.ALPHABET.ALPHA_DIGIT + '-_';
7
+ const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
7
8
 
8
9
  const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new util.TextEncoder();
9
10
 
@@ -63,7 +64,7 @@ const formDataToStream = (form, headersHandler, options) => {
63
64
  const {
64
65
  tag = 'form-data-boundary',
65
66
  size = 25,
66
- boundary = tag + '-' + utils.generateString(size, BOUNDARY_ALPHABET)
67
+ boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET)
67
68
  } = options || {};
68
69
 
69
70
  if(!utils.isFormData(form)) {
@@ -75,7 +76,7 @@ const formDataToStream = (form, headersHandler, options) => {
75
76
  }
76
77
 
77
78
  const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
78
- const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF + CRLF);
79
+ const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
79
80
  let contentLength = footerBytes.byteLength;
80
81
 
81
82
  const parts = Array.from(form.entries()).map(([name, value]) => {
@@ -10,11 +10,11 @@ import buildURL from "./buildURL.js";
10
10
  export default (config) => {
11
11
  const newConfig = mergeConfig({}, config);
12
12
 
13
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
13
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
14
14
 
15
15
  newConfig.headers = headers = AxiosHeaders.from(headers);
16
16
 
17
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
17
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
18
18
 
19
19
  // HTTP basic authentication
20
20
  if (auth) {
@@ -23,17 +23,21 @@ export default (config) => {
23
23
  );
24
24
  }
25
25
 
26
- let contentType;
27
-
28
26
  if (utils.isFormData(data)) {
29
27
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
30
- headers.setContentType(undefined); // Let the browser set it
31
- } else if ((contentType = headers.getContentType()) !== false) {
32
- // fix semicolon duplication issue for ReactNative FormData implementation
33
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
34
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
28
+ headers.setContentType(undefined); // browser handles it
29
+ } else if (utils.isFunction(data.getHeaders)) {
30
+ // Node.js FormData (like form-data package)
31
+ const formHeaders = data.getHeaders();
32
+ // Only set safe headers to avoid overwriting security headers
33
+ const allowedHeaders = ['content-type', 'content-length'];
34
+ Object.entries(formHeaders).forEach(([key, val]) => {
35
+ if (allowedHeaders.includes(key.toLowerCase())) {
36
+ headers.set(key, val);
37
+ }
38
+ });
35
39
  }
36
- }
40
+ }
37
41
 
38
42
  // Add xsrf header
39
43
  // This is only done if running in a standard browser environment.
@@ -17,7 +17,7 @@ function throttle(fn, freq) {
17
17
  clearTimeout(timer);
18
18
  timer = null;
19
19
  }
20
- fn.apply(null, args);
20
+ fn(...args);
21
21
  }
22
22
 
23
23
  const throttled = (...args) => {
@@ -120,6 +120,10 @@ function toFormData(obj, formData, options) {
120
120
  return value.toISOString();
121
121
  }
122
122
 
123
+ if (utils.isBoolean(value)) {
124
+ return value.toString();
125
+ }
126
+
123
127
  if (!useBlob && utils.isBlob(value)) {
124
128
  throw new AxiosError('Blob is not supported. Use a Buffer instead.');
125
129
  }
@@ -5,7 +5,7 @@ import toFormData from './toFormData.js';
5
5
  import platform from '../platform/index.js';
6
6
 
7
7
  export default function toURLEncodedForm(data, options) {
8
- return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
8
+ return toFormData(data, new platform.classes.URLSearchParams(), {
9
9
  visitor: function(value, key, path, helpers) {
10
10
  if (platform.isNode && utils.isBuffer(value)) {
11
11
  this.append(key, value.toString('base64'));
@@ -13,6 +13,7 @@ export default function toURLEncodedForm(data, options) {
13
13
  }
14
14
 
15
15
  return helpers.defaultVisitor.apply(this, arguments);
16
- }
17
- }, options));
16
+ },
17
+ ...options
18
+ });
18
19
  }
@@ -1,6 +1,30 @@
1
+ import crypto from 'crypto';
1
2
  import URLSearchParams from './classes/URLSearchParams.js'
2
3
  import FormData from './classes/FormData.js'
3
4
 
5
+ const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
6
+
7
+ const DIGIT = '0123456789';
8
+
9
+ const ALPHABET = {
10
+ DIGIT,
11
+ ALPHA,
12
+ ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
13
+ }
14
+
15
+ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
16
+ let str = '';
17
+ const {length} = alphabet;
18
+ const randomValues = new Uint32Array(size);
19
+ crypto.randomFillSync(randomValues);
20
+ for (let i = 0; i < size; i++) {
21
+ str += alphabet[randomValues[i] % length];
22
+ }
23
+
24
+ return str;
25
+ }
26
+
27
+
4
28
  export default {
5
29
  isNode: true,
6
30
  classes: {
@@ -8,5 +32,7 @@ export default {
8
32
  FormData,
9
33
  Blob: typeof Blob !== 'undefined' && Blob || null
10
34
  },
35
+ ALPHABET,
36
+ generateString,
11
37
  protocols: [ 'http', 'https', 'file', 'data' ]
12
38
  };
package/lib/utils.js CHANGED
@@ -6,6 +6,7 @@ import bind from './helpers/bind.js';
6
6
 
7
7
  const {toString} = Object.prototype;
8
8
  const {getPrototypeOf} = Object;
9
+ const {iterator, toStringTag} = Symbol;
9
10
 
10
11
  const kindOf = (cache => thing => {
11
12
  const str = toString.call(thing);
@@ -132,7 +133,28 @@ const isPlainObject = (val) => {
132
133
  }
133
134
 
134
135
  const prototype = getPrototypeOf(val);
135
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
136
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
137
+ }
138
+
139
+ /**
140
+ * Determine if a value is an empty object (safely handles Buffers)
141
+ *
142
+ * @param {*} val The value to test
143
+ *
144
+ * @returns {boolean} True if value is an empty object, otherwise false
145
+ */
146
+ const isEmptyObject = (val) => {
147
+ // Early return for non-objects or Buffers to prevent RangeError
148
+ if (!isObject(val) || isBuffer(val)) {
149
+ return false;
150
+ }
151
+
152
+ try {
153
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
154
+ } catch (e) {
155
+ // Fallback for any other objects that might cause RangeError with Object.keys()
156
+ return false;
157
+ }
136
158
  }
137
159
 
138
160
  /**
@@ -257,6 +279,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
257
279
  fn.call(null, obj[i], i, obj);
258
280
  }
259
281
  } else {
282
+ // Buffer check
283
+ if (isBuffer(obj)) {
284
+ return;
285
+ }
286
+
260
287
  // Iterate over object keys
261
288
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
262
289
  const len = keys.length;
@@ -270,6 +297,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
270
297
  }
271
298
 
272
299
  function findKey(obj, key) {
300
+ if (isBuffer(obj)){
301
+ return null;
302
+ }
303
+
273
304
  key = key.toLowerCase();
274
305
  const keys = Object.keys(obj);
275
306
  let i = keys.length;
@@ -310,7 +341,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
310
341
  * @returns {Object} Result of all merge properties
311
342
  */
312
343
  function merge(/* obj1, obj2, obj3, ... */) {
313
- const {caseless} = isContextDefined(this) && this || {};
344
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
314
345
  const result = {};
315
346
  const assignValue = (val, key) => {
316
347
  const targetKey = caseless && findKey(result, key) || key;
@@ -321,7 +352,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
321
352
  } else if (isArray(val)) {
322
353
  result[targetKey] = val.slice();
323
354
  } else {
324
- result[targetKey] = val;
355
+ if (!skipUndefined || !isUndefined(val)) {
356
+ result[targetKey] = val;
357
+ }
325
358
  }
326
359
  }
327
360
 
@@ -483,13 +516,13 @@ const isTypedArray = (TypedArray => {
483
516
  * @returns {void}
484
517
  */
485
518
  const forEachEntry = (obj, fn) => {
486
- const generator = obj && obj[Symbol.iterator];
519
+ const generator = obj && obj[iterator];
487
520
 
488
- const iterator = generator.call(obj);
521
+ const _iterator = generator.call(obj);
489
522
 
490
523
  let result;
491
524
 
492
- while ((result = iterator.next()) && !result.done) {
525
+ while ((result = _iterator.next()) && !result.done) {
493
526
  const pair = result.value;
494
527
  fn.call(obj, pair[0], pair[1]);
495
528
  }
@@ -602,25 +635,7 @@ const toFiniteNumber = (value, defaultValue) => {
602
635
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
603
636
  }
604
637
 
605
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
606
-
607
- const DIGIT = '0123456789';
608
-
609
- const ALPHABET = {
610
- DIGIT,
611
- ALPHA,
612
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
613
- }
614
-
615
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
616
- let str = '';
617
- const {length} = alphabet;
618
- while (size--) {
619
- str += alphabet[Math.random() * length|0]
620
- }
621
638
 
622
- return str;
623
- }
624
639
 
625
640
  /**
626
641
  * If the thing is a FormData object, return true, otherwise return false.
@@ -630,7 +645,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
630
645
  * @returns {boolean}
631
646
  */
632
647
  function isSpecCompliantForm(thing) {
633
- return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
648
+ return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
634
649
  }
635
650
 
636
651
  const toJSONObject = (obj) => {
@@ -643,6 +658,11 @@ const toJSONObject = (obj) => {
643
658
  return;
644
659
  }
645
660
 
661
+ //Buffer check
662
+ if (isBuffer(source)) {
663
+ return source;
664
+ }
665
+
646
666
  if(!('toJSON' in source)) {
647
667
  stack[i] = source;
648
668
  const target = isArray(source) ? [] : {};
@@ -699,6 +719,10 @@ const asap = typeof queueMicrotask !== 'undefined' ?
699
719
 
700
720
  // *********************
701
721
 
722
+
723
+ const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
724
+
725
+
702
726
  export default {
703
727
  isArray,
704
728
  isArrayBuffer,
@@ -710,6 +734,7 @@ export default {
710
734
  isBoolean,
711
735
  isObject,
712
736
  isPlainObject,
737
+ isEmptyObject,
713
738
  isReadableStream,
714
739
  isRequest,
715
740
  isResponse,
@@ -749,12 +774,11 @@ export default {
749
774
  findKey,
750
775
  global: _global,
751
776
  isContextDefined,
752
- ALPHABET,
753
- generateString,
754
777
  isSpecCompliantForm,
755
778
  toJSONObject,
756
779
  isAsyncFn,
757
780
  isThenable,
758
781
  setImmediate: _setImmediate,
759
- asap
782
+ asap,
783
+ isIterable
760
784
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.7.9",
3
+ "version": "1.12.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -9,6 +9,10 @@
9
9
  "require": "./index.d.cts",
10
10
  "default": "./index.d.ts"
11
11
  },
12
+ "react-native": {
13
+ "require": "./dist/browser/axios.cjs",
14
+ "default": "./dist/esm/axios.js"
15
+ },
12
16
  "browser": {
13
17
  "require": "./dist/browser/axios.cjs",
14
18
  "default": "./index.js"
@@ -29,7 +33,9 @@
29
33
  "./unsafe/adapters/http.js": "./lib/adapters/http.js",
30
34
  "./unsafe/adapters/xhr.js": "./lib/adapters/xhr.js",
31
35
  "./unsafe/utils.js": "./lib/utils.js",
32
- "./package.json": "./package.json"
36
+ "./package.json": "./package.json",
37
+ "./dist/browser/axios.cjs": "./dist/browser/axios.cjs",
38
+ "./dist/node/axios.cjs": "./dist/node/axios.cjs"
33
39
  },
34
40
  "type": "module",
35
41
  "types": "index.d.ts",
@@ -45,7 +51,7 @@
45
51
  "test:build:version": "node ./bin/check-build-version.js",
46
52
  "start": "node ./sandbox/server.js",
47
53
  "preversion": "gulp version",
48
- "version": "npm run build && git add dist && git add package.json",
54
+ "version": "npm run build && git add package.json",
49
55
  "prepublishOnly": "npm run test:build:version",
50
56
  "postpublish": "git push && git push --tags",
51
57
  "build": "gulp clear && cross-env NODE_ENV=production rollup -c -m",
@@ -85,6 +91,7 @@
85
91
  "@commitlint/cli": "^17.8.1",
86
92
  "@commitlint/config-conventional": "^17.8.1",
87
93
  "@release-it/conventional-changelog": "^5.1.1",
94
+ "@rollup/plugin-alias": "^5.1.0",
88
95
  "@rollup/plugin-babel": "^5.3.1",
89
96
  "@rollup/plugin-commonjs": "^15.1.0",
90
97
  "@rollup/plugin-json": "^4.1.0",
@@ -106,7 +113,6 @@
106
113
  "fs-extra": "^10.1.0",
107
114
  "get-stream": "^3.0.0",
108
115
  "gulp": "^4.0.2",
109
- "gzip-size": "^7.0.0",
110
116
  "handlebars": "^4.7.8",
111
117
  "husky": "^8.0.3",
112
118
  "istanbul-instrumenter-loader": "^3.0.1",
@@ -125,6 +131,7 @@
125
131
  "minimist": "^1.2.8",
126
132
  "mocha": "^10.3.0",
127
133
  "multer": "^1.4.4",
134
+ "pacote": "^20.0.0",
128
135
  "pretty-bytes": "^6.1.1",
129
136
  "release-it": "^15.11.0",
130
137
  "rollup": "^2.79.1",
@@ -134,21 +141,26 @@
134
141
  "sinon": "^4.5.0",
135
142
  "stream-throttle": "^0.1.3",
136
143
  "string-replace-async": "^3.0.2",
144
+ "tar-stream": "^3.1.7",
137
145
  "terser-webpack-plugin": "^4.2.3",
138
- "typescript": "^4.9.5",
139
- "@rollup/plugin-alias": "^5.1.0"
146
+ "typescript": "^4.9.5"
140
147
  },
141
148
  "browser": {
142
149
  "./lib/adapters/http.js": "./lib/helpers/null.js",
143
150
  "./lib/platform/node/index.js": "./lib/platform/browser/index.js",
144
151
  "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js"
145
152
  },
153
+ "react-native": {
154
+ "./lib/adapters/http.js": "./lib/helpers/null.js",
155
+ "./lib/platform/node/index.js": "./lib/platform/browser/index.js",
156
+ "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js"
157
+ },
146
158
  "jsdelivr": "dist/axios.min.js",
147
159
  "unpkg": "dist/axios.min.js",
148
160
  "typings": "./index.d.ts",
149
161
  "dependencies": {
150
162
  "follow-redirects": "^1.15.6",
151
- "form-data": "^4.0.0",
163
+ "form-data": "^4.0.4",
152
164
  "proxy-from-env": "^1.1.0"
153
165
  },
154
166
  "bundlesize": [
@@ -163,14 +175,14 @@
163
175
  "Dmitriy Mozgovoy (https://github.com/DigitalBrainJS)",
164
176
  "Jay (https://github.com/jasonsaayman)",
165
177
  "Emily Morehouse (https://github.com/emilyemorehouse)",
166
- "Justin Beckwith (https://github.com/JustinBeckwith)",
167
178
  "Rubén Norte (https://github.com/rubennorte)",
179
+ "Justin Beckwith (https://github.com/JustinBeckwith)",
168
180
  "Martti Laine (https://github.com/codeclown)",
169
181
  "Xianming Zhong (https://github.com/chinesedfan)",
170
182
  "Remco Haszing (https://github.com/remcohaszing)",
171
183
  "Rikki Gibson (https://github.com/RikkiGibson)",
172
- "Yasu Flores (https://github.com/yasuf)",
173
- "Ben Carp (https://github.com/carpben)"
184
+ "Willian Agostini (https://github.com/WillianAgostini)",
185
+ "Yasu Flores (https://github.com/yasuf)"
174
186
  ],
175
187
  "sideEffects": false,
176
188
  "release-it": {
@@ -199,8 +211,8 @@
199
211
  },
200
212
  "hooks": {
201
213
  "before:init": "npm test",
202
- "after:bump": "gulp version --bump ${version} && npm run build && npm run test:build:version && git add ./dist && git add ./package-lock.json",
203
- "before:release": "npm run release:changelog:fix",
214
+ "after:bump": "gulp version --bump ${version} && npm run build && npm run test:build:version",
215
+ "before:release": "npm run release:changelog:fix && git add ./package-lock.json",
204
216
  "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
205
217
  }
206
218
  },
package/SECURITY.md DELETED
@@ -1,6 +0,0 @@
1
- # Reporting a Vulnerability
2
-
3
- If you discover a security vulnerability in axios please disclose it via [our huntr page](https://huntr.dev/repos/axios/axios/). Bounty eligibility, CVE assignment, response times and past reports are all there.
4
-
5
-
6
- Thank you for improving the security of axios.