CVE-2026-31808: file-type Package Experiences Denial of Service Due to Infinite Loop in ASF Parser

file-type Updated 13 Mar 2026

Summary

10/03/2026
Yes i
Moderate
5.3

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 ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

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 →

Share this vulnerability

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.

Related vulnerabilities

Recent vulnerabilities recorded for file-type.

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback