Commit 458c454
Fix axios DoS vulnerability by forcing upgrade to 1.7.9+ (#248)
Summary:
Axios versions < 0.30.2 are vulnerable to DoS via unbounded memory allocation when processing `data:` URIs, bypassing `maxContentLength`/`maxBodyLength` protections. The website transitively depends on axios@0.25.0 through `docusaurus/core` → `wait-on@6.0.1`.
## Changes
- Added yarn resolution `axios: ^1.7.9` to force secure version (resolves to 1.13.2)
- Added yarn resolution `wait-on: ^7.2.0` for axios 1.x compatibility (6.0.1 imports internal APIs removed in axios 1.x)
- Updated yarn.lock with new dependency graph
## Impact
Docusaurus build continues to work without modifications. No API or behavior changes.
<details>
<summary>Original prompt</summary>
----
*This section details on the original issue you should resolve*
<issue_title>[BUG] Fix "Axios is vulnerable to DoS attack through lack of data size check https://github.com/facebookresearch/balance/issues/90"</issue_title>
<issue_description>Dependabot cannot update axios to a non-vulnerable version
The latest possible version that can be installed is 0.25.0 because of the following conflicting dependencies:
docusaurus/core@2.4.3 requires axios@^0.25.0 via wait-on@6.0.1
docusaurus/preset-classic@2.4.3 requires axios@^0.25.0 via a transitive dependency on wait-on@6.0.1
docusaurus/theme-classic@2.4.3 requires axios@^0.25.0 via a transitive dependency on wait-on@6.0.1
The earliest fixed version is 0.30.2.
Transitive dependency axios 0.25.0 is introduced via
docusaurus/core 2.4.3 ... axios 0.25.0
docusaurus/preset-classic 2.4.3 ... axios 0.25.0
docusaurus/theme-classic 2.4.3 ... axios 0.25.0
Package
Affected versions
Patched version
axios
(npm)
< 0.30.2
0.30.2
Summary
When Axios runs on Node.js and is given a URL with the data: scheme, it does not perform HTTP. Instead, its Node http adapter decodes the entire payload into memory (Buffer/Blob) and returns a synthetic 200 response.
This path ignores maxContentLength / maxBodyLength (which only protect HTTP responses), so an attacker can supply a very large data: URI and cause the process to allocate unbounded memory and crash (DoS), even if the caller requested responseType: 'stream'.
Details
The Node adapter (lib/adapters/http.js) supports the data: scheme. When axios encounters a request whose URL starts with data:, it does not perform an HTTP request. Instead, it calls fromDataURI() to decode the Base64 payload into a Buffer or Blob.
Relevant code from [[httpAdapter](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/adapters/http.js#L231)](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/adapters/http.js#L231):
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
const protocol = parsed.protocol || supportedProtocols[0];
if (protocol === 'data:') {
let convertedData;
if (method !== 'GET') {
return settle(resolve, reject, { status: 405, ... });
}
convertedData = fromDataURI(config.url, responseType === 'blob', {
Blob: config.env && config.env.Blob
});
return settle(resolve, reject, { data: convertedData, status: 200, ... });
}
The decoder is in [[lib/helpers/fromDataURI.js](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/helpers/fromDataURI.js#L27)](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/helpers/fromDataURI.js#L27):
export default function fromDataURI(uri, asBlob, options) {
...
if (protocol === 'data') {
uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
const match = DATA_URL_PATTERN.exec(uri);
...
const body = match[3];
const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
if (asBlob) { return new _Blob([buffer], {type: mime}); }
return buffer;
}
throw new AxiosError('Unsupported protocol ' + protocol, ...);
}
The function decodes the entire Base64 payload into a Buffer with no size limits or sanity checks.
It does not honour config.maxContentLength or config.maxBodyLength, which only apply to HTTP streams.
As a result, a data: URI of arbitrary size can cause the Node process to allocate the entire content into memory.
In comparison, normal HTTP responses are monitored for size, the HTTP adapter accumulates the response into a buffer and will reject when totalResponseBytes exceeds [[maxContentLength](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/adapters/http.js#L550)](https://github.com/axios/axios/blob/c959ff29013a3bc90cde3ac7ea2d9a3f9c08974b/lib/adapters/http.js#L550). No such check occurs for data: URIs.
PoC
const axios = require('axios');
async function main() {
// this example decodes ~120 MB
const base64Size = 160_000_000; // 120 MB after decoding
const base64 = 'A'.repeat(base64Size);
const uri = 'data:application/octet-stream;base64,' + base64;
console.log('Generating URI with base64 length:', base64.length);
const response = await axios.get(uri, {
responseType: 'arraybuffer'
});
console.log('Received bytes:', response.data.length);
}
main().catch(err => {
console.error('Error:', err.message);
});
Run with limited heap to force a crash:
node --max-old-space-size=100 poc.js
Since Node heap is capped at 100 MB, the process terminates with an out-of-memory error:
<--- Last few GCs --->
…
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0x… node::Abort() …
…
Mini Real App PoC:
A small link-preview service that uses axios streaming, keep-alive agents, timeouts, and a JSON body. It allows data: URLs which axios fully ignore ma...
</details>
- Fixes #247
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
Pull Request resolved: #248
Reviewed By: wesleytlee
Differential Revision: D90202755
Pulled By: talgalili
fbshipit-source-id: fb5f2023020be02ac87b69930adbc54b18f0951a1 parent 7018355 commit 458c454
2 files changed
Lines changed: 80 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3344 | 3344 | | |
3345 | 3345 | | |
3346 | 3346 | | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
3347 | 3352 | | |
3348 | 3353 | | |
3349 | 3354 | | |
| |||
3373 | 3378 | | |
3374 | 3379 | | |
3375 | 3380 | | |
3376 | | - | |
3377 | | - | |
3378 | | - | |
3379 | | - | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
3380 | 3385 | | |
3381 | | - | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
3382 | 3389 | | |
3383 | 3390 | | |
3384 | 3391 | | |
| |||
3992 | 3999 | | |
3993 | 4000 | | |
3994 | 4001 | | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
3995 | 4009 | | |
3996 | 4010 | | |
3997 | 4011 | | |
| |||
4824 | 4838 | | |
4825 | 4839 | | |
4826 | 4840 | | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
4827 | 4846 | | |
4828 | 4847 | | |
4829 | 4848 | | |
| |||
5212 | 5231 | | |
5213 | 5232 | | |
5214 | 5233 | | |
| 5234 | + | |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
| 5243 | + | |
5215 | 5244 | | |
5216 | 5245 | | |
5217 | 5246 | | |
| |||
5573 | 5602 | | |
5574 | 5603 | | |
5575 | 5604 | | |
5576 | | - | |
| 5605 | + | |
5577 | 5606 | | |
5578 | 5607 | | |
5579 | 5608 | | |
| |||
5602 | 5631 | | |
5603 | 5632 | | |
5604 | 5633 | | |
| 5634 | + | |
| 5635 | + | |
| 5636 | + | |
| 5637 | + | |
| 5638 | + | |
| 5639 | + | |
| 5640 | + | |
| 5641 | + | |
| 5642 | + | |
| 5643 | + | |
| 5644 | + | |
5605 | 5645 | | |
5606 | 5646 | | |
5607 | 5647 | | |
| |||
5921 | 5961 | | |
5922 | 5962 | | |
5923 | 5963 | | |
5924 | | - | |
| 5964 | + | |
5925 | 5965 | | |
5926 | 5966 | | |
5927 | 5967 | | |
| |||
5933 | 5973 | | |
5934 | 5974 | | |
5935 | 5975 | | |
| 5976 | + | |
| 5977 | + | |
| 5978 | + | |
| 5979 | + | |
| 5980 | + | |
| 5981 | + | |
| 5982 | + | |
5936 | 5983 | | |
5937 | 5984 | | |
5938 | 5985 | | |
| |||
6854 | 6901 | | |
6855 | 6902 | | |
6856 | 6903 | | |
6857 | | - | |
| 6904 | + | |
6858 | 6905 | | |
6859 | 6906 | | |
6860 | 6907 | | |
| |||
7867 | 7914 | | |
7868 | 7915 | | |
7869 | 7916 | | |
| 7917 | + | |
| 7918 | + | |
| 7919 | + | |
| 7920 | + | |
| 7921 | + | |
| 7922 | + | |
| 7923 | + | |
7870 | 7924 | | |
7871 | 7925 | | |
7872 | 7926 | | |
7873 | 7927 | | |
7874 | 7928 | | |
7875 | 7929 | | |
7876 | 7930 | | |
7877 | | - | |
7878 | | - | |
7879 | | - | |
7880 | | - | |
7881 | | - | |
7882 | | - | |
7883 | | - | |
7884 | 7931 | | |
7885 | 7932 | | |
7886 | 7933 | | |
| |||
7916 | 7963 | | |
7917 | 7964 | | |
7918 | 7965 | | |
7919 | | - | |
| 7966 | + | |
7920 | 7967 | | |
7921 | 7968 | | |
7922 | 7969 | | |
| |||
8882 | 8929 | | |
8883 | 8930 | | |
8884 | 8931 | | |
| 8932 | + | |
| 8933 | + | |
| 8934 | + | |
| 8935 | + | |
| 8936 | + | |
8885 | 8937 | | |
8886 | 8938 | | |
8887 | 8939 | | |
| |||
9600 | 9652 | | |
9601 | 9653 | | |
9602 | 9654 | | |
9603 | | - | |
| 9655 | + | |
9604 | 9656 | | |
9605 | 9657 | | |
9606 | 9658 | | |
| |||
10931 | 10983 | | |
10932 | 10984 | | |
10933 | 10985 | | |
10934 | | - | |
10935 | | - | |
10936 | | - | |
10937 | | - | |
| 10986 | + | |
| 10987 | + | |
| 10988 | + | |
| 10989 | + | |
10938 | 10990 | | |
10939 | | - | |
10940 | | - | |
| 10991 | + | |
| 10992 | + | |
10941 | 10993 | | |
10942 | | - | |
10943 | | - | |
| 10994 | + | |
| 10995 | + | |
10944 | 10996 | | |
10945 | 10997 | | |
10946 | 10998 | | |
| |||
0 commit comments