bn.js Denial-of-Service Vulnerability via maskn(0)

Vulnerability

A denial-of-service vulnerability has been identified in the bn.js package, affecting all versions prior to 5.2.3. The issue arises when the maskn(0) method is called on any BN instance, which corrupts the internal state of the object. This corruption causes methods like toString() and divmod() to enter an infinite loop, effectively hanging the process indefinitely. The vulnerability is rooted in the way maskn(0) sets the object's length to 0, violating an internal invariant that requires the length to be at least 1. As a result, any method that relies on this invariant can loop forever, causing a complete process hang.

Impact

Exploitation of this vulnerability leads to an infinite loop that consumes 100% of the CPU on the affected thread, with no way to recover. This behavior has been observed to cause a process out of memory error when the vulnerability is triggered in a web browser.

Reproduction

The vulnerability can be reproduced by creating a BN instance and calling the maskn(0) method. This can be done using Node.js, version 18 or later. After calling maskn(0), the toString() method can be invoked, which will hang the process indefinitely.

Remediation

Users can upgrade to bn.js version 5.2.3 or later to address this vulnerability.

Added: Feb 20, 2026, 5:24 AM
Updated: Feb 20, 2026, 5:24 AM

Vulnerability Rating

Custom Algorithm
spread
0.0
impact
2.5
exploitability
8.7
remediation
0.0
relevance
3.2
threat
6.4
urgency
2.9
incentive
4.2

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.