Skip to main content
Vulnerability Database/CVE-2025-32029

CVE-2025-32029: ts-asn1-der Integer Encoding DOS Vulnerability

CVE-2025-32029 is a denial of service vulnerability in ts-asn1-der library caused by incorrect integer encoding that triggers infinite loops. This post covers the technical details, affected versions, and mitigation strategies.

Published:

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

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2025-32029 Overview

CVE-2025-32029 is a denial-of-service vulnerability in ts-asn1-der, a TypeScript library providing utility classes that encode ASN.1 (Abstract Syntax Notation One) data following DER (Distinguished Encoding Rules). The flaw lives in the numBitLen helper used during two's-complement integer encoding. For absolute values in the range 2**31 to 2**32 - 1, arithmetic using the unsigned right-shift operator produces a negative intermediate value, which causes the loop condition to never terminate. Any caller that encodes an attacker-influenced integer in this range enters an infinite loop and consumes CPU indefinitely. The issue is tracked under CWE-835: Loop with Unreachable Exit Condition and is resolved in version 1.0.4.

Critical Impact

Processing a single crafted Asn1Integer value forces the host process into an uninterruptible infinite loop, exhausting CPU and denying service to legitimate workloads.

Affected Products

  • ApelegHQ/ts-asn1-der versions prior to 1.0.4
  • Downstream Node.js and TypeScript applications that pass untrusted integers to Asn1Integer
  • Services performing DER encoding of certificate, signature, or protocol fields using this library

Discovery Timeline

  • 2025-04-07 - CVE-2025-32029 published to NVD
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2025-32029

Vulnerability Analysis

The defect sits inside src/lib/encode2sComplement.ts, in the numBitLen function that calculates how many bits are required to represent a signed integer. The original code reduced large magnitudes using x /= 2 inside a while (x >= 4294967296) loop and then relied on x >>>= 1 to continue counting. JavaScript's >>> operator coerces its operand to a 32-bit unsigned integer. When x falls in the range 2**31 to 2**32 - 1, that coercion keeps the high bit set, and subsequent arithmetic produces values the loop condition cannot drain.

The practical result is that numBitLen never returns. The event loop stalls, the Node.js worker thread cannot process other requests, and connected clients observe a hang.

Root Cause

The root cause is an unsafe mix of IEEE-754 floating-point arithmetic and 32-bit bitwise operators on values that straddle the signed/unsigned 32-bit boundary. The >>> operator in JavaScript always yields a 32-bit unsigned result, so values the author expected to be shifted toward zero instead stay above zero and recycle through the loop forever.

Attack Vector

Exploitation requires a local attacker, or any upstream code path, able to supply an integer argument in the vulnerable range to Asn1Integer. No authentication, user interaction, or privilege is required at the API boundary. The impact is limited to availability of the hosting process; confidentiality and integrity are not affected.

typescript
// Patch excerpt from src/lib/encode2sComplement.ts
const numBitLen = (x: number) => {
	let l = 1;
	if (x < 0) x = -x;
-	while (x >= 4294967296) {
-		x /= 2;
+	// values higher than 2**32 - 1 (requiring a fifth byte)
+	// need regular math.
+	while (x >>> 0 !== x) {
+		x = Math.floor(x / 2);
		l++;
	}
	while ((x >>>= 1) != 0) {

Source: GitHub commit b2bc903. The fix replaces the magnitude check x >= 4294967296 with the identity test x >>> 0 !== x, which only holds for values outside the 32-bit unsigned range, and swaps the floating-point division for Math.floor(x / 2) to keep the loop variable integral.

Detection Methods for CVE-2025-32029

Indicators of Compromise

  • Node.js worker processes pinned at 100% CPU on a single core with no corresponding network throughput.
  • Request latency spikes or health-check timeouts on services that encode ASN.1 integers derived from external input.
  • Stack traces or --prof output showing time concentrated inside encode2sComplement or numBitLen.

Detection Strategies

  • Inventory dependencies with npm ls @apeleghq/ts-asn1-der or npm audit and flag any version below 1.0.4.
  • Add runtime assertions around Asn1Integer call sites that reject inputs with absolute value greater than 2**31 - 1.
  • Use software composition analysis (SCA) tooling to alert on GitHub Security Advisory GHSA-p4qw-7j9g-5h53.

Monitoring Recommendations

  • Alert on sustained single-thread CPU saturation for Node.js services, especially when request queues grow.
  • Capture process-level stack samples during high-CPU events to confirm the loop is inside the DER encoder.
  • Track error-budget burn and timeout rates on upstream endpoints that feed integers into the library.

How to Mitigate CVE-2025-32029

Immediate Actions Required

  • Upgrade ts-asn1-der to version 1.0.4 or later in all affected services.
  • Audit application code for direct and transitive callers of Asn1Integer and other DER encoding utilities.
  • Rebuild and redeploy container images and lockfiles so the patched version is actually loaded at runtime.

Patch Information

The maintainer released version 1.0.4 containing commit b2bc9032. The patch rewrites numBitLen to detect values outside the 32-bit unsigned range using x >>> 0 !== x and uses Math.floor(x / 2) to guarantee the loop variable converges to zero. Full details are published in GHSA-p4qw-7j9g-5h53.

Workarounds

  • If upgrading is not immediately possible, validate inputs to Asn1Integer so values are no smaller than -(2**31) + 1 and no larger than 2**31 - 1.
  • Wrap encoder calls in a worker thread with a timeout so a stuck encode cannot stall the main event loop.
  • Reject or truncate upstream payloads that contain ASN.1 integer fields exceeding four bytes before they reach the encoder.
bash
# Upgrade the dependency and verify the resolved version
npm install @apeleghq/ts-asn1-der@^1.0.4
npm ls @apeleghq/ts-asn1-der

# Input guard for callers that cannot upgrade immediately
# (TypeScript)
# const MIN = -(2 ** 31) + 1;
# const MAX =  (2 ** 31) - 1;
# if (value < MIN || value > MAX) throw new RangeError('asn1 int out of range');

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

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

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.