pan-os-python icon indicating copy to clipboard operation
pan-os-python copied to clipboard

Security: xml.etree.ElementTree used across 10 core modules — no XXE protection

Open DataWizual opened this issue 6 months ago • 2 comments

During a security audit of pan-os-python, two findings were identified.


Finding 1: Unsafe XML parser (High)

xml.etree.ElementTree is used across 10 core modules with no defusedxml replacement or defuse_stdlib() call anywhere in the codebase.

Affected modules: base.py, firewall.py, network.py, panorama.py, policies.py, objects.py, ha.py, plugins.py, userid.py, __init__.py

The library's purpose is parsing XML responses from live network devices. Any attacker-influenced response (MitM, compromised appliance, rogue endpoint) is processed without XXE or Billion Laughs protection.

Fix: replace import xml.etree.ElementTree as ET with import defusedxml.ElementTree as ET in each affected module. Drop-in compatible, no API changes required.


Finding 2: SHA-1 used for value hashing (Medium)

panos/base.py:3172 uses hashlib.sha1() with an inline comment explicitly documenting the usage. SHA-1 has been cryptographically broken since 2017.

DataWizual avatar May 20 '26 08:05 DataWizual

Thanks for the reference. You're right that defusedxml is no longer recommended — Python docs were updated after expat 2.6.0 (February 2024) addressed the core vulnerabilities, and Python 3.11–3.15 ship with expat 2.7.1 which is not vulnerable. The concern stands for environments running Python < 3.11 or using a system-provided expat older than 2.6.0, which is still common in enterprise and embedded deployments. If pan-os-python officially requires Python 3.11+, this finding is effectively mitigated. If the minimum supported version is lower, the exposure remains for those users. What's the minimum Python version this library supports?

DataWizual avatar May 20 '26 11:05 DataWizual

Following up on the defusedxml discussion — Python 3.11+ ships with expat ≥ 2.7.1 which mitigates the core XXE vectors. However, pan-os-python explicitly supports Python 3.5+ per setup.py, meaning environments on older interpreters remain exposed.

Submitted PR #623 with a defense-in-depth approach:

  • New panos/_xml_safety.py module providing safe_fromstring() — a drop-in replacement that validates XML before parsing
  • Works on all supported Python versions (2.7, 3.5+)
  • Does not depend on defusedxml — implements targeted checks for: DOCTYPE declarations, external entity references, parameter entity references, and Billion Laughs expansion patterns
  • On Python 3.11+, it acts as a belt-and-suspenders check; on older versions, it provides the protection the stdlib lacks
  • Includes test coverage (tests/test_xml_safety.py)
  • Applied to userid.py as the first migration point (highest-risk module — parses external device responses)

The module is designed as a minimal, auditable safety layer rather than a full XML parser replacement. This keeps the attack surface explicit and reviewable.

Correctover avatar Jul 16 '26 05:07 Correctover

Following up on the defense-in-depth discussion — I put together a more comprehensive MCP runtime verification architecture document that addresses the broader validation concerns:

→ https://github.com/PaloAltoNetworks/AI-Security-Architecture-Hub/pull/1

The architecture covers:

  • Threat model for MCP tool execution (what static XML parsing fixes alone cannot address)
  • Three-stage verification pipeline: pre-execution parameter validation → runtime output verification → post-execution integrity check
  • Fail-closed design with configurable policy enforcement
  • Real audit data from scanning 53+ MCP servers across path traversal, SSRF, command injection, and credential leakage categories

The defusedxml fix in PR #623 handles the XML parsing layer. The runtime validator in the architecture doc addresses the broader class of threats where clean XML can still carry malicious payloads — which is the harder problem for agentic systems.

Happy to discuss the threat model or adapt the architecture for pan-os-python's specific use case if useful.

Correctover avatar Jul 16 '26 05:07 Correctover