Skip to main content
CVE Vulnerability Database

CVE-2026-2739: bn.js Denial of Service (DOS) Vulnerability

CVE-2026-2739 is a denial of service flaw in bn.js versions before 5.2.3. The maskn(0) method corrupts internal state, causing infinite loops that hang processes. This article covers technical details, affected versions, and mitigation.

Published:

CVE-2026-2739 Overview

CVE-2026-2739 is a Denial of Service vulnerability affecting the bn.js JavaScript library, a widely-used arbitrary-precision integer arithmetic package for Node.js and browser environments. The vulnerability exists in versions prior to 5.2.3 and occurs when calling maskn(0) on any BN instance. This operation corrupts the internal state of the BN object, causing subsequent method calls including toString(), divmod(), and other operations to enter an infinite loop, hanging the process indefinitely.

Critical Impact

Applications using vulnerable versions of bn.js can be completely locked up through a simple API call, causing service disruption for any system relying on big number arithmetic operations.

Affected Products

  • bn.js versions prior to 5.2.3
  • Applications and libraries dependent on vulnerable bn.js versions
  • Cryptographic libraries and blockchain applications using bn.js for large integer operations

Discovery Timeline

  • 2026-02-20 - CVE-2026-2739 published to NVD
  • 2026-02-20 - Last updated in NVD database

Technical Details for CVE-2026-2739

Vulnerability Analysis

This vulnerability is classified as CWE-835 (Loop with Unreachable Exit Condition), commonly known as an infinite loop vulnerability. The flaw resides in the imaskn() method of the bn.js library, which is responsible for masking (zeroing out) bits above a specified position in a big number representation.

When maskn(0) is called, the method fails to properly handle the edge case where zero bits are requested to be masked. This results in the internal word array and length properties of the BN instance entering an inconsistent state. Subsequent operations that iterate over the internal representation—such as toString() for string conversion or divmod() for division operations—encounter loop conditions that can never be satisfied, causing the process to hang indefinitely.

The attack can be triggered remotely if user-controlled input influences the bit count parameter passed to maskn(). Since bn.js is commonly used in cryptographic operations, blockchain implementations, and financial calculations, the availability impact could be significant for affected applications.

Root Cause

The root cause lies in the imaskn() method's failure to validate and handle the edge case where the bits parameter equals zero. When bits is 0, the internal length property can be set to 0, creating an invalid internal state. The BN representation expects at least one word in the words array with length >= 1, but this invariant is violated when masking with zero bits.

Attack Vector

An attacker can exploit this vulnerability through any code path that allows user-controlled input to reach the maskn() method with a value of 0. This is particularly concerning in:

  1. Cryptographic operations - Where bit manipulation on user-provided values occurs
  2. Blockchain applications - Processing malicious transaction data
  3. API endpoints - That accept numeric parameters used in big number calculations
  4. Web3 applications - Handling user-submitted cryptographic proofs or signatures

The attack requires no authentication and can be executed remotely over the network against vulnerable applications.

javascript
// Security patch in lib/bn.js - fix imaskn state (#317)
       this.words[this.length - 1] &= mask;
     }
 
+    if (this.length === 0) {
+      this.words[0] = 0;
+      this.length = 1;
+    }
+
     return this._strip();
   };

Source: GitHub Commit Change

The patch adds a guard condition after the masking operation to ensure the BN instance maintains a valid internal state. When length becomes 0, it explicitly sets words[0] = 0 and length = 1, preserving the invariant that a BN instance always has at least one word.

Detection Methods for CVE-2026-2739

Indicators of Compromise

  • Application processes hanging indefinitely with high CPU usage
  • Node.js event loop blocked without apparent network or I/O activity
  • Stack traces showing repeated calls within bn.js toString() or divmod() methods
  • Memory consumption remaining static while CPU usage spikes to 100%

Detection Strategies

  • Monitor application processes for unresponsive states combined with sustained CPU usage
  • Implement dependency scanning to identify bn.js versions prior to 5.2.3 in your dependency tree
  • Use Software Composition Analysis (SCA) tools to flag vulnerable package versions
  • Set up application-level timeouts for cryptographic and arithmetic operations

Monitoring Recommendations

  • Configure process monitors to alert on Node.js processes exceeding CPU thresholds for extended periods
  • Implement watchdog timers around big number operations in critical code paths
  • Enable application performance monitoring (APM) to detect event loop blocking patterns
  • Set up alerts for service health checks failing due to unresponsive application endpoints

How to Mitigate CVE-2026-2739

Immediate Actions Required

  • Upgrade bn.js to version 5.2.3 or later immediately
  • Audit your package-lock.json or yarn.lock for transitive dependencies on vulnerable bn.js versions
  • If immediate patching is not possible, implement input validation to reject zero values for bit mask operations
  • Review application logs for any previous occurrences of hanging processes that may indicate exploitation attempts

Patch Information

The vulnerability has been addressed in bn.js version 5.2.3. The fix is available through the official commit and can be applied by updating the package. The patch ensures the internal state remains valid even when maskn(0) is called by explicitly setting minimum valid values for the word array.

Additional technical details are available in GitHub Issue #316 and GitHub Pull Request #317. The Snyk Vulnerability Report provides additional guidance for affected users.

Workarounds

  • Implement input validation wrappers around maskn() calls to reject zero values
  • Add timeout mechanisms around big number operations to prevent indefinite hangs
  • Use process isolation or worker threads for cryptographic operations to limit blast radius
  • Consider temporarily switching to alternative big number libraries if patching is not immediately feasible
bash
# Update bn.js to patched version
npm update bn.js@^5.2.3

# Or force resolution in package.json (npm)
npm pkg set overrides.bn.js="^5.2.3"

# For yarn, add resolution to package.json
# "resolutions": { "bn.js": "^5.2.3" }

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.