CVE-2026-31808: file-type Package Experiences Denial of Service Due to Infinite Loop in ASF Parser
Summary
CVE-2026-31808: file-type affected by infinite loop in ASF parser on malformed input with zero-size sub-header. Affects file-type versions >= 13.0.0, < 21.3.1. Fixed in 21.3.1. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The file-type package is a widely used Node.js library that detects the type of files based on their binary signatures. It supports various file formats, including images, audio, and video files. This package is essential for applications that need to handle file uploads or process files based on their types. However, it is vulnerable to a denial of service attack when parsing malformed ASF files, specifically when the sub-header has a zero-size field.
Vulnerability Detail
A denial of service vulnerability exists in the ASF (WMV/WMA) file type detection parser within the file-type package. When the parser processes a crafted input where an ASF sub-header has a 'size' field of zero, it enters an infinite loop. This occurs because the 'payload' value becomes negative (-24), causing the tokenizer to move the read position backwards, resulting in the same sub-header being read repeatedly. Any application utilizing file-type to detect untrusted or attacker-controlled input is susceptible to this issue, allowing an attacker to stall the Node.js event loop with a minimal payload of 55 bytes.
How To Fix
Latest published version: 22.2.0 as of 23 Oct 2026
npm install file-type@22.2.0
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
21.3.1
This is the first release that contains the fix.
npm install file-type@21.3.1
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary measure, you can validate or limit the size of input buffers before passing them to the file-type parser. Additionally, consider running file type detection in a worker thread with a timeout to prevent the main event loop from being stalled. Here is an example of how to implement a timeout in a worker thread:
const { Worker } = require('worker_threads');
function detectFileType(buffer) {
return new Promise((resolve, reject) => {
const worker = new Worker('./fileTypeWorker.js', { workerData: buffer });
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0) {
reject(new Error(`Worker stopped with exit code ${code}`));
}
});
setTimeout(() => {
worker.terminate();
reject(new Error('File type detection timed out'));
}, 5000); // 5 seconds timeout
});
}
Conclusion
The file-type package has a significant vulnerability (CVE-2026-31808) that can lead to denial of service due to an infinite loop in its ASF parser. Users are strongly encouraged to upgrade to version 21.3.1 or later to protect their applications. Implementing workarounds can also help mitigate the risks until an upgrade is feasible.
See every vulnerability recorded for file-type →
FAQ
CVE-2026-31808 is a vulnerability in the file-type package that allows for a denial of service attack due to an infinite loop in the ASF parser when processing malformed input.
If your application uses the file-type package to detect file types from untrusted sources, it may become unresponsive due to the infinite loop triggered by specially crafted ASF files.
The vulnerability has a CVSS score of 5.3, indicating a moderate severity level that could lead to denial of service.
You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. You can check if your application is affected by this vulnerability using the Vulert playground at Vulert Scanner without any signup.
If an immediate upgrade is not possible, implement input validation or run file type detection in a worker thread with a timeout to mitigate the risk of denial of service.
References
Related vulnerabilities
Recent vulnerabilities recorded for file-type.