Junglewise Threat Intelligence

CVE-2026-40194: phpseclib timing discrepancy in SSH2 HMAC verification

CVE-2026-40194 · Severity: low · CVSS 3.7 · Published 2026-04-10

Technologies: Phpseclib. Vendors: Phpseclib.

Executive brief

phpseclib is a widely used PHP library for secure communications, such as connecting to servers via SSH. A flaw was found where the library compares security codes (HMACs) in a way that takes slightly different amounts of time depending on how much of the code is correct. While difficult to exploit over a network, a sophisticated attacker could theoretically use these timing differences to eventually guess valid security codes, potentially compromising the integrity of the encrypted connection.

Technical details

The phpseclib library's SSH2 implementation in `get_binary_packet()` uses PHP's `!=` operator to compare received SSH packet HMACs against locally computed HMACs. Because PHP's `!=` operator on equal-length binary strings utilizes `memcmp()`, it short-circuits upon encountering the first differing byte, creating an observable timing discrepancy (CWE-208). An attacker could potentially exploit this side-channel to conduct a timing attack, although practical exploitation is significantly hindered by SSH's default behavior of disconnecting upon MAC failure and the use of per-session keys. The vulnerability affects all non-AEAD ciphers (e.g., AES-CBC, AES-CTR) and is resolved by replacing the inequality operator with the constant-time `hash_equals()` function.

Affected products

  • phpseclib phpseclib 0.1.1 to 1.0.27, 2.0.0 to 2.0.52, 3.0.0 to 3.0.50

Timeline

  • 2026-04-10: advisory: Vendor advisory and GHSA published
  • 2026-04-10: patched: Fixed in versions 3.0.51, 2.0.53, and 1.0.28

References