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.
- package/AGENTS.md +38 -0
- package/CHANGELOG.md +10 -0
- package/CLAUDE.md +1 -0
- package/README.md +46 -7
- package/UPGRADE_GUIDE.md +2 -2
- package/dist/axios.js +328 -93
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +328 -93
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/index.d.ts +4 -0
- package/lib/adapters/http.js +354 -69
- package/lib/adapters/xhr.js +106 -32
- package/lib/core/AxiosError.js +81 -5
- package/lib/core/dispatchRequest.js +10 -5
- package/lib/core/mergeConfig.js +21 -10
- package/lib/defaults/index.js +9 -3
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosURLSearchParams.js +20 -12
- package/lib/helpers/cookies.js +15 -2
- package/lib/helpers/defaultRedactKeys.js +3 -0
- package/lib/helpers/shouldBypassProxy.js +55 -1
- package/lib/helpers/toFormData.js +14 -3
- package/lib/utils.js +51 -20
- package/package.json +2 -2
package/AGENTS.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
- Use npm here; `package-lock.json` is committed and CI installs with `npm ci --ignore-scripts`.
|
|
5
|
+
- `mise.toml` pins local Node 20, but CI runs Node 12, 14, 16, 18, 20, 22, and 24; keep `lib/` source compatible with old CommonJS-era syntax and runtime assumptions.
|
|
6
|
+
- CI order is `npm ci --ignore-scripts`, `npm run build`, then `npm test`.
|
|
7
|
+
|
|
8
|
+
## Commands
|
|
9
|
+
- `npm run build`: runs `grunt build`, which cleans `dist/` and uses Rollup from `lib/axios.js` to create `dist/axios*.js` and `dist/esm/axios*.js`.
|
|
10
|
+
- `npm test`: runs JS tests and declaration tests through `bin/ssl_hotfix.js`; use this full command on Node >16 so old tooling gets `NODE_OPTIONS=--openssl-legacy-provider`.
|
|
11
|
+
- `node bin/ssl_hotfix.js ./node_modules/.bin/grunt test`: JS-only verification, running ESLint on `lib/**/*.js`, Mocha on `test/unit/**/*.js`, and Karma on `test/specs/**/*.spec.js`.
|
|
12
|
+
- `./node_modules/.bin/mocha --timeout 30000 test/unit/<path>.js`: run one Node/Mocha unit test file without Karma or dtslint.
|
|
13
|
+
- `node bin/ssl_hotfix.js ./node_modules/.bin/grunt karma:single`: run the browser suite only.
|
|
14
|
+
- `node bin/ssl_hotfix.js ./node_modules/.bin/dtslint --localTs node_modules/typescript/lib`: run the declaration tests in `test/typescript/axios.ts`.
|
|
15
|
+
- `npm run fix`: ESLint autofix for `lib/**/*.js` only.
|
|
16
|
+
|
|
17
|
+
## Structure
|
|
18
|
+
- Package entry is `index.js` -> `lib/axios.js`; the TypeScript surface is the root `index.d.ts`.
|
|
19
|
+
- `lib/defaults/index.js` chooses the runtime adapter: `lib/adapters/xhr.js` for browsers and `lib/adapters/http.js` for Node.
|
|
20
|
+
- Browser bundlers also rely on `package.json` `browser` mappings from `./lib/adapters/http.js` to `./lib/adapters/xhr.js` and from `./lib/platform/node/index.js` to `./lib/platform/browser/index.js`.
|
|
21
|
+
- `lib/env/data.js` stores the package version and is generated by `grunt version` or `npm run preversion`; do not edit it except as part of a version bump.
|
|
22
|
+
- `grunt build` uses `rollup.config.js`; `webpack.config.js` is not the package build path, while Karma has its own webpack config inside `karma.conf.js`.
|
|
23
|
+
|
|
24
|
+
## Tests
|
|
25
|
+
- Node tests live in `test/unit/**/*.js` and use Mocha plus Node `assert`.
|
|
26
|
+
- Browser tests live in `test/specs/**/*.spec.js` and use Jasmine/Jasmine-Ajax; globals such as `axios` and `getAjaxRequest` come from `test/specs/__helpers.js`.
|
|
27
|
+
- Karma defaults to `FirefoxHeadless` and `ChromeHeadless` whenever `process.env.GITHUB_ACTIONS !== 'false'`, including when the variable is unset; set `GITHUB_ACTIONS=false` only if you need non-headless local browsers.
|
|
28
|
+
- There is no committed single-browser-spec target; do not leave `fdescribe`, `fit`, or `.only` in tests.
|
|
29
|
+
- Declaration changes should update both `index.d.ts` and `test/typescript/axios.ts`, then run the dtslint command above.
|
|
30
|
+
|
|
31
|
+
## Source Conventions
|
|
32
|
+
- `lib/` is CommonJS with `'use strict'`, `var`, semicolons, 2-space indentation, and no trailing commas; ESLint only checks `lib/**/*.js`.
|
|
33
|
+
- Public API behavior usually needs README docs, TypeScript declarations, and declaration tests updated together.
|
|
34
|
+
- Adapter or platform changes usually need both Node and browser paths considered, including Mocha coverage for `http.js` behavior and Karma coverage for `xhr.js` behavior.
|
|
35
|
+
|
|
36
|
+
## Node 12+ Compatibility
|
|
37
|
+
- All shipped code AND test code must run on Node 12 through Node 24. CI runs the full matrix, so a test that only works on Node 16+ will break the build. Avoid `??`, `?.`, top-level `await`, private class fields, `Array.prototype.at`, `structuredClone`, etc. in both `lib/` and `test/`.
|
|
38
|
+
- Be wary of `Object.prototype` pollution tests on Node 12/14: setting `Object.prototype.get` (or `set`) before any code that calls `Object.defineProperty` with a value-only descriptor will throw `TypeError: Getter must be a function`, because the descriptor inherits the polluted property. Construct servers/clients first, pre-load any lazy-required Node internals (e.g. `require('dns')`), then apply the pollution.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
### Notable behavior changes
|
|
6
|
+
|
|
7
|
+
- `utils.merge` (used internally by `mergeConfig` and to merge request headers) now returns objects with a `null` prototype to harden against prototype-pollution gadgets. As a result, `error.config`, `error.config.headers`, and any merged header bucket no longer inherit from `Object.prototype`. Two consequences:
|
|
8
|
+
- `obj.hasOwnProperty(key)` on a merged config or header object throws `TypeError: obj.hasOwnProperty is not a function`. Use `Object.prototype.hasOwnProperty.call(obj, key)` or `key in obj` instead.
|
|
9
|
+
- Implicit string coercion (e.g. `String(obj)`, `'' + obj`, or any path that calls `ToPrimitive`) throws `TypeError: Cannot convert object to primitive value` because there is no inherited `toString`. Coerce explicitly via `JSON.stringify(obj)` or by reading individual properties.
|
|
10
|
+
|
|
11
|
+
Property access (`obj[key]`), enumeration, and `JSON.stringify` are unaffected.
|
|
12
|
+
|
|
3
13
|
## [0.30.0](https://github.com/axios/axios/compare/v0.29.0...v0.30.0) (2025-03-26)
|
|
4
14
|
|
|
5
15
|
## Release notes:
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/README.md
CHANGED
|
@@ -83,12 +83,6 @@ Using npm:
|
|
|
83
83
|
$ npm install axios
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
Using bower:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
$ bower install axios
|
|
90
|
-
```
|
|
91
|
-
|
|
92
86
|
Using yarn:
|
|
93
87
|
|
|
94
88
|
```bash
|
|
@@ -336,13 +330,21 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
336
330
|
|
|
337
331
|
// `params` are the URL parameters to be sent with the request
|
|
338
332
|
// Must be a plain object or a URLSearchParams object
|
|
333
|
+
// Null bytes in param values stay percent-encoded as `%00` in the resulting query string
|
|
334
|
+
// Axios does not reverse `encodeURIComponent` output for `%00`,
|
|
335
|
+
// so null-byte injection cannot be smuggled through the serializer.
|
|
339
336
|
params: {
|
|
340
337
|
ID: 12345
|
|
341
338
|
},
|
|
342
339
|
|
|
343
340
|
// `paramsSerializer` is an optional config in charge of serializing `params`
|
|
341
|
+
// Nested objects are walked with a bounded recursion depth:
|
|
342
|
+
// once `maxDepth` is exceeded the serializer throws `ERR_FORM_DATA_DEPTH_EXCEEDED`
|
|
343
|
+
// instead of overflowing the call stack. The same cap applies to `toFormData` when
|
|
344
|
+
// `Content-Type: multipart/form-data` triggers automatic FormData serialization.
|
|
344
345
|
paramsSerializer: {
|
|
345
|
-
indexes: null // array indexes format (null - no brackets, false - empty brackets, true - brackets with indexes)
|
|
346
|
+
indexes: null, // array indexes format (null - no brackets, false - empty brackets, true - brackets with indexes)
|
|
347
|
+
maxDepth: 100 // maximum recursion depth for nested params (default: 100, Infinity disables the limit)
|
|
346
348
|
},
|
|
347
349
|
|
|
348
350
|
// `data` is the data to be sent as the request body
|
|
@@ -400,6 +402,9 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
400
402
|
xsrfHeaderName: 'X-XSRF-TOKEN', // default
|
|
401
403
|
|
|
402
404
|
// `undefined` (default) - set XSRF header only for the same origin requests
|
|
405
|
+
// Only an explicit `true` (own property on the config) will add the XSRF header for
|
|
406
|
+
// cross-origin requests. Values inherited from `Object.prototype` are ignored
|
|
407
|
+
// so a polluted prototype cannot silently enable the token.
|
|
403
408
|
withXSRFToken: boolean | undefined | ((config: AxiosRequestConfig) => boolean | undefined),
|
|
404
409
|
|
|
405
410
|
// `onUploadProgress` allows handling of progress events for uploads
|
|
@@ -415,11 +420,27 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
415
420
|
},
|
|
416
421
|
|
|
417
422
|
// `maxContentLength` defines the max size of the http response content in bytes allowed in node.js
|
|
423
|
+
// Also enforced on streamed responses (`responseType: 'stream'`): bytes are counted as they
|
|
424
|
+
// arrive and the stream is aborted with an error once the cap is exceeded.
|
|
418
425
|
maxContentLength: 2000,
|
|
419
426
|
|
|
420
427
|
// `maxBodyLength` (Node only option) defines the max size of the http request content in bytes allowed
|
|
428
|
+
// Also enforced on stream uploads: uploaded bytes are tracked and the request is aborted
|
|
429
|
+
// once the cap is exceeded, even when the native http transport is used directly.
|
|
421
430
|
maxBodyLength: 2000,
|
|
422
431
|
|
|
432
|
+
// `formDataHeaderPolicy` controls which headers the Node adapter copies from
|
|
433
|
+
// FormData `getHeaders()`.
|
|
434
|
+
// 'legacy' (default) copies all returned headers for v1 compatibility.
|
|
435
|
+
// 'content-only' copies only Content-Type and Content-Length.
|
|
436
|
+
formDataHeaderPolicy: 'legacy',
|
|
437
|
+
|
|
438
|
+
// `redact` masks matching config keys when AxiosError#toJSON() is called.
|
|
439
|
+
// Matching is case-insensitive and recursive. It does not change the request.
|
|
440
|
+
// An empty array is treated as "no override" and falls back to the defaults so
|
|
441
|
+
// an accidental `redact: []` cannot silently disable redaction.
|
|
442
|
+
redact: ['authorization', 'password'],
|
|
443
|
+
|
|
423
444
|
// `validateStatus` defines whether to resolve or reject the promise for a given
|
|
424
445
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
|
425
446
|
// or `undefined`), the promise will be resolved; otherwise, the promise will be
|
|
@@ -445,10 +466,18 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
445
466
|
|
|
446
467
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
|
447
468
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
|
469
|
+
// Avoid passing user-controlled values because socket paths bypass host,
|
|
470
|
+
// port, DNS, and proxy controls.
|
|
448
471
|
// Only either `socketPath` or `proxy` can be specified.
|
|
449
472
|
// If both are specified, `socketPath` is used.
|
|
450
473
|
socketPath: null, // default
|
|
451
474
|
|
|
475
|
+
// `allowedSocketPaths` constrains `socketPath` to known-safe Unix sockets.
|
|
476
|
+
// Use this when config can include partially user-controlled input.
|
|
477
|
+
// Set to a string or array of strings. An empty array denies all socket paths.
|
|
478
|
+
// Set to `null` on a request to clear an instance-level allowlist.
|
|
479
|
+
allowedSocketPaths: null, // default
|
|
480
|
+
|
|
452
481
|
// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
|
|
453
482
|
// and https requests, respectively, in node.js. This allows options to be added like
|
|
454
483
|
// `keepAlive` that are not enabled by default.
|
|
@@ -522,6 +551,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
522
551
|
dots: boolean; // use dots instead of brackets format
|
|
523
552
|
metaTokens: boolean; // keep special endings like {} in parameter key
|
|
524
553
|
indexes: boolean; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
|
|
554
|
+
maxDepth: number; // maximum recursion depth for nested objects (default: 100, Infinity disables the limit)
|
|
525
555
|
}
|
|
526
556
|
}
|
|
527
557
|
```
|
|
@@ -603,6 +633,8 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
|
603
633
|
|
|
604
634
|
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults/index.js#L28), then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
|
|
605
635
|
|
|
636
|
+
> Note: the merged config object is created with a null prototype (`Object.create(null)`) and only own properties of the inputs are copied across. A polluted `Object.prototype` cannot leak values (for example `transport`, `adapter`, or `transformRequest`) into the outgoing config through inheritance, and keys such as `__proto__`, `constructor`, and `prototype` are dropped during the merge.
|
|
637
|
+
|
|
606
638
|
```js
|
|
607
639
|
// Create an instance using the config defaults provided by the library
|
|
608
640
|
// At this point the timeout config value is `0` as is the default for the library
|
|
@@ -1011,6 +1043,13 @@ The back-end body-parser could potentially use this meta-information to automati
|
|
|
1011
1043
|
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
|
1012
1044
|
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
|
1013
1045
|
|
|
1046
|
+
- `maxDepth: number = 100` - maximum recursion depth when serializing nested objects. Throws an `AxiosError` with
|
|
1047
|
+
code `ERR_FORM_DATA_DEPTH_EXCEEDED` if the limit is exceeded. Set to `Infinity` to disable the limit.
|
|
1048
|
+
|
|
1049
|
+
> **Security note:** If your server-side code forwards client-supplied objects to axios as request `data` or `params`,
|
|
1050
|
+
> keep `maxDepth` at a reasonable value (the default of 100 is sufficient for most use cases) to prevent
|
|
1051
|
+
> denial-of-service via deeply nested payloads.
|
|
1052
|
+
|
|
1014
1053
|
Let's say we have an object like this one:
|
|
1015
1054
|
|
|
1016
1055
|
```js
|
package/UPGRADE_GUIDE.md
CHANGED
|
@@ -159,8 +159,8 @@ axios.get('some/url')
|
|
|
159
159
|
Previous versions of axios shipped with an AMD, CommonJS, and Global build. This has all been rolled into a single UMD build.
|
|
160
160
|
|
|
161
161
|
```js
|
|
162
|
-
// AMD
|
|
163
|
-
require(['
|
|
162
|
+
// AMD (for example with a RequireJS path mapped to `axios/dist/axios`)
|
|
163
|
+
require(['axios/dist/axios'], function (axios) {
|
|
164
164
|
/* ... */
|
|
165
165
|
});
|
|
166
166
|
|