FERRAMENTAS LINUX: How to Secure Python 3.10 from Tar Pitfalls, Cookie Bypasses & Browser Injection

quinta-feira, 16 de abril de 2026

How to Secure Python 3.10 from Tar Pitfalls, Cookie Bypasses & Browser Injection

 

SUSE

Stop chasing patch dates. Learn to check, fix, and mitigate critical Python 3.10 vulnerabilities (tar injection, cookie bypass, XML stack overflow) on Ubuntu, Rocky, and SUSE. Includes automation scripts and alternative firewalls. Secure your code today.

If you run Python 3.10 on Linux, you are responsible for five specific failure points in the standard library. A recent SUSE update (2026-1376-1) fixed:

1. Tarfile confusion (CVE-2025-13462): A malicious .tar file can fool Python into writing files where it shouldn't.

2. Path traversal in pkgutil (CVE-2026-3479): get_data() can be tricked into reading files outside its intended directory.

3. Cookie injection (CVE-2026-3644): Incomplete validation in http.cookies lets an attacker bypass input checks.

4. XML stack crash (CVE-2026-4224): Deeply nested DTDs in an XML document can crash your Python process (C stack overflow).

5. Browser command injection (CVE-2026-4519): The webbrowser.open() API fails to sanitize leading dashes (-), allowing attackers to pass dangerous flags to the browser.

You don't need to memorize CVEs. You need a repeatable process to find, fix, or block these problems. Here is that process.

1. How to check if you are vulnerable

Run these commands on your own servers. No guesswork.

On Ubuntu (20.04, 22.04, 24.04)

bash
# Check your Python version
python3.10 --version

# For tarfile vulnerability: try to import and extract a crafted tar (safe test)
python3.10 -c "import tarfile; print('Vulnerable' if hasattr(tarfile, '_GNU_NAME_IS_DIR') is False else 'Check patch level')"

# For the XML crash: test if your Python is patched against deep DTDs
python3.10 -c "import xml.parsers.expat; print('Check CVE-2026-4224 manually via changelog')"
# Better: check package changelog
dpkg -l | grep python3.10
apt changelog python3.10 | grep -i CVE-2026-4224


bash
# Check installed version
rpm -q python3.10

# Look for the specific bug fixes
rpm -q --changelog python3.10 | grep -E "CVE-2026-4224|CVE-2026-4519"


On SUSE (Leap 15.4/15.6, SLES 15 SP4)

bash
# Check if the specific patch is installed
zypper patches | grep python310
rpm -q --changelog python310 | grep -i "bsc#1260026"   # browser injection bug


Quick universal check (any distro):

bash
python3.10 -c "import webbrowser; print('Test manually: run webbrowser.open(\"-version\") in a sandbox')"

Do not actually run webbrowser.open("-version") on a production machine. That is the vulnerability itself.

2. Automation script to apply the fix (bash, major distros)

Save this as fix_python310.sh and run it as root on Ubuntu, Rocky Linux, or SUSE.

bash
#!/bin/bash
# Evergreen fix for Python 3.10 vulnerabilities (tar, cookie, XML, browser injection)
set -e

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 
   exit 1
fi

# Detect distro
if [[ -f /etc/os-release ]]; then
    . /etc/os-release
    OS=$ID
    VER=$VERSION_ID
fi

case $OS in
    ubuntu|debian)
        apt update
        apt install -y python3.10 python3.10-full
        ;;
    rocky|almalinux|rhel|centos)
        dnf update -y python3.10
        ;;
    suse|opensuse-leap|opensuse)
        zypper refresh
        # The exact patch name from April 2026. Replace with current if needed.
        zypper patch -y --cve=CVE-2026-4519 --cve=CVE-2026-4224
        ;;
    *)
        echo "Unsupported OS: $OS"
        exit 1
        ;;
esac

echo "Python 3.10 updated. Verify with: python3.10 -c 'import tarfile; print(tarfile.__version__)'"

How to use:

bash
chmod +x fix_python310.sh
sudo ./fix_python310.sh

3. Alternative mitigation if you can't update now

You cannot patch? Block the attack surface instead.

For the browser injection (CVE-2026-4519) – use AppArmor or SELinux

Create an AppArmor profile for your Python app that denies access to the webbrowser module.

bash
# /etc/apparmor.d/usr.bin.python3.10
/usr/bin/python3.10 {
  # ... your existing rules ...
  deny /usr/lib/python3.10/webbrowser.py r,
  deny /usr/lib/python3.10/webbrowser.pyc r,
}ML from the internet, put nginx or haproxy in front and reject requests with deeply nested elements.


Then reload: apparmor_parser -r /etc/apparmor.d/usr.bin.python3.10

For the XML stack overflow (CVE-2026-4224) – use a proxy to filter XML


If you accept XML from the internet, put nginx or haproxy in front and reject requests with deeply nested elements.

Nginx example (reject any XML with > 100 nested tags – crude but effective):

nginx
location /xml-endpoint {
    # Only allow POST with small body
    client_max_body_size 10k;
    # Use a Lua script or external module to check nesting depth
    # Simpler: block XML altogether if you don't need it
    if ($content_type ~* "application/xml") {
        return 403;
    }
}


For the tarfile vulnerability (CVE-2025-13462) – never tarfile.extractall() on untrusted data

Instead, always validate:
python
import tarfile
with tarfile.open('untrusted.tar') as tf:
    for member in tf.getmembers():
        if member.name.startswith('/') or '..' in member.name:
            raise ValueError("Bad path in tar")
        tf.extract(member, path="/safe/dir")


For cookie injection (CVE-2026-3644) – replace http.cookies with itsdangerous

If you can't update Python, swap the module:
bash
pip install itsdangerous


Then in your code:
python
# Instead of: from http.cookies import SimpleCookie
from itsdangerous import Signer
# This is a breaking change, but it closes the bypass.

Suggested reading



Offensive Security Using Python: A Hands-on Guide to Offensive Tactics and Threat Mitigation Using Practical Strategies . by Rejah Rehim -Amazon

Why it fits: 

You cannot defend against XML stack overflows (CVE-2026-4224) or cookie injection (CVE-2026-3644) unless you understand how they are exploited. This book teaches you how to use Python to actually perform penetration testing and exploit web vulnerabilities . It covers SQL injection, XSS, and the logic flaws that lead to the input validation issues mentioned in the SUSE advisory.



Affiliate disclosure: As an Amazon Associate, I earn from qualifying purchases. This helps me keep writing in-depth security guides – at no extra cost to you.)

Conclusion: Stop firefighting, start automating


Every six months, a new batch of Python CVEs appears. The difference between a tired admin and a solid engineer is checklists and scripts.



Nenhum comentário:

Postar um comentário