/

CVE-2026-22871

Severity:

CRITICAL RISK

(9.8)

Path Traversal in GuardDog safe_extract() Enables Arbitrary

CVE-2026-22871

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Overwrite and Potential Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A path traversal vulnerability in GuardDog's safe_extract() function allows malicious PyPI packages to write files outside the intended extraction directory when the tool processes package contents.

If an attacker can supply a crafted package that GuardDog analyzes, they may overwrite arbitrary files on the host system, which in many environments can be chained to remote code execution.

Affected context

This vulnerability affects environments where GuardDog is installed and used to scan or analyze potentially untrusted PyPI packages, such as CI pipelines, security scanning services, or developer workstations.

The issue arises specifically in the archive extraction phase handled by safe_extract(), where file paths embedded in package archives are not fully constrained to the designated extraction directory.

Systems that run GuardDog with elevated privileges or in close proximity to sensitive configuration or executable files are at higher risk of severe impact.

Exploit preconditions

  • Attack surface: The GuardDog CLI when invoked to scan or process Python packages (e.g., local distributions, downloaded artifacts, or CI-integrated scans).
  • Required access: Ability to cause GuardDog to analyze a crafted, malicious PyPI package or archive (for example by publishing a malicious package, influencing dependency selection, or feeding GuardDog a tampered file).
  • Trigger point: The call to safe_extract() during package/archive extraction, where paths from the archive are interpreted and written to disk.
  • Why exploitation is possible: The extraction logic does not reliably prevent directory traversal elements (such as .. segments or absolute paths), allowing archive entries to escape the intended directory and overwrite files elsewhere on the filesystem.

Why this happens

The underlying bug falls under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal").

GuardDog's safe_extract() function is intended to confine extracted files to a specific directory, but it fails to correctly normalize and validate archive member paths before writing them.

As a result, attacker-controlled filenames that include traversal sequences or absolute paths can resolve to locations outside the target extraction directory.

This breaks the assumption that extracted content is isolated, turning what should be a local, sandboxed unpacking operation into a primitive for arbitrary file overwrite.

Potential impact

  • Overwrite of arbitrary files writable by the GuardDog process, including configuration files, scripts, or application binaries.
  • Modification of startup scripts, virtual environment files, or build artifacts to inject malicious code.
  • Escalation to remote code execution when an overwritten file is later executed or interpreted (e.g., Python modules, shell scripts, systemd units).
  • Tampering with security tooling itself (e.g., altering GuardDog or related tooling) to hide future malicious activity.
  • Disruption or sabotage of CI/CD pipelines by corrupting build outputs or configuration files.

General mitigation guidance

Mitigation centers on strictly constraining file extraction to a trusted directory and treating all archive paths as untrusted input.

Common defensive patterns include:

  • Normalizing and validating each archive member's path before extraction, ensuring it remains under the intended root directory after resolution.
  • Rejecting paths that contain directory traversal elements (..), leading path separators, or absolute path indicators.
  • Performing extraction in an isolated, dedicated directory with minimal privileges and no sensitive files, followed by controlled copying of validated content.
  • Running GuardDog and similar tooling under least-privilege accounts, avoiding unnecessary write access to system-wide or user-critical paths.
  • Incorporating defense-in-depth with filesystem permissions and sandboxing (containers, VMs, or restricted execution environments) around security scanning tools.

How teams detect issues like this

Organizations can look for this class of issue and its potential exploitation using a mix of review and monitoring:

  • Static analysis: Configure linters or SAST tools to flag code that joins untrusted filenames with base directories without proper normalization and boundary checks.
  • Code review signals: Scrutinize any archive extraction utilities (tarfile, zipfile, custom safe_extract helpers, etc.) to ensure they validate resolved paths against a fixed root.
  • Policy enforcement: Enforce secure extraction patterns in internal libraries and coding standards so teams reuse vetted, hardened extraction helpers rather than ad hoc logic.
  • Runtime monitoring: Monitor CI and build environments for unexpected file modifications in configuration directories or tool installations when new or untrusted packages are scanned.
  • Automated tooling: Use automated code review and dependency scanning tools to surface vulnerable archive handling patterns early in development.

Sources

SourceLink
github.comgithub.com/DataDog/guarddog/commit/9aa6a725b2c71d537d3c18d1c15621395ebb879c
github.comgithub.com/DataDog/guarddog/security/advisories/GHSA-xg9w-vg3g-6m68

Frequently asked

questions

It can be, depending on how GuardDog is integrated. If an attacker can get a malicious package into a workflow where GuardDog automatically scans dependencies (such as a CI pipeline consuming public PyPI), they may be able to exploit the vulnerability without direct access to the host.

The attacker must be able to influence which package GuardDog scans—typically by publishing or supplying a crafted package that a user or automated system runs GuardDog against. They do not necessarily need shell access to the machine where GuardDog runs.

The most robust fix is to normalize and validate all archive member paths before extraction, enforcing that the final resolved path remains within the intended extraction root, and rejecting any entry that would escape that directory.

Standardize on hardened archive extraction utilities, treat all filenames from untrusted archives as untrusted data, embed path traversal checks into shared helper functions, and enforce these patterns via code review and static analysis policies for any tool that processes external packages or archives.

Find out what's already
exploitable in your codebase.