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, customsafe_extracthelpers, 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.

