Summary
PraisonAI's archive extraction helper _safe_extractall incorrectly trusts symlink entries in tar bundles, allowing files to be written outside the intended destination directory.
A crafted bundle that chains a symlink and a subsequent file entry can cause writes to arbitrary filesystem locations when recipes are pulled, published, or unpacked, potentially overwriting sensitive files or planting malicious content.
Affected context
This vulnerability affects PraisonAI environments that process recipe bundles (for pull, publish, or unpack flows) using the _safe_extractall helper.
The vulnerable behavior manifests when:
- Tar archives are accepted from sources that may be influenced by an attacker (directly or via a compromised channel).
- The extraction destination directory is assumed to be a safe, confined location, but archive content is not fully constrained to that directory.
- The underlying filesystem honors symlinks and hardlinks created during extraction.
In these conditions, a malicious archive can influence where files end up on disk beyond the nominal destination directory.
Exploit preconditions
- Attack surface: Archive (tar) processing in recipe pull, recipe publish, and recipe unpack flows.
- Required access: Ability to supply or influence a recipe bundle that PraisonAI will extract (e.g., publishing a malicious recipe or compromising a recipe source).
- Trigger point: The application calling _safe_extractall, which then invokes
tar.extractall(dest_dir)without proper filtering and without validating symlinklinknametargets. - Why exploitation is possible:
- Member names are checked for absolute paths and
..traversal, butmember.linknameis not validated. - Symlink and hardlink entries are not rejected, allowing creation of links that point outside
dest_dir. - A subsequent regular file whose path traverses via the freshly created symlink is treated as inside
dest_dir, but actually writes to an external, attacker-chosen location.
Why this happens
The core issue is an incomplete validation of archive entries that focuses only on the visible member path rather than the effective filesystem target of links.
This maps to:
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') — the extraction logic intends to confine writes to
dest_dir, but fails to account for symlink-mediated escape. - CWE-59: Improper Link Resolution Before File Access ('Link Following') — symlink and hardlink entries are accepted without checking where they resolve, and subsequent file operations implicitly follow those links.
Conceptually, the insecure pattern is: treating archives as trusted, validating only the nominal filenames, and then extracting all content (including links) without enforcing a strict "no links, no escapes" policy or using safe filters provided by the tar library.
Potential impact
- Overwriting files outside the intended extraction directory with attacker-controlled content.
- Placing malicious configuration files or scripts in locations that may be automatically loaded by the system or other applications.
- Corrupting or clobbering application data, logs, or cache files to disrupt operations.
- Assisting in privilege escalation if writable paths influence higher-privileged services (e.g., through modified config, unit files, or hooks), depending on environment hardening.
- Facilitating further compromise when combined with other weaknesses such as permissive file permissions or unsafe automatic execution mechanisms.
General mitigation guidance
Effective mitigation focuses on treating archive content as untrusted and enforcing strict extraction policies:
- Reject or strip symlink and hardlink entries when extracting archives that originate from untrusted or semi-trusted sources.
- Validate both the archive entry name and any associated
linknameto ensure that the final resolved path remains within the intended destination directory. - Use safer archive APIs or filters (such as data-only extraction filters) that deny special file types by default.
- Perform path normalization and canonicalization on every target path before creation, and abort extraction if it attempts to leave the destination directory.
- Run extraction processes with least privilege and restricted filesystem access (e.g., chroot/jail, containers, or limited service accounts) to reduce blast radius if a path escape occurs.
- Treat imported recipes and bundles as potentially hostile until verified through content, source, and integrity checks.
How teams detect issues like this
Organizations can detect and monitor for this class of vulnerability using a blend of code-centric and operational techniques:
- Static analysis: Add rules or queries to flag:
- Uses of
tar.extractall()or equivalent high-risk extraction APIs without filters or without explicit rejection of special file types. - Archive extraction helpers that do not inspect or sanitize
linkname, or that allowSYMTYPE/LNKTYPEentries from untrusted sources. - Manual path joins that do not normalize and enforce containment within a base directory.
- Code review signals:
- Helper functions labelled as "safe" that parse or extract archives but only validate entry names and not link targets.
- Absence of checks for symlinks, hardlinks, device files, or uncommon tar member types.
- Extraction logic that assumes inbound bundles are trusted based solely on source or filename.
- Policy and tooling:
- Introduce security review gates for any functionality that processes user-supplied archives.
- Leverage SAST/IAST tools or custom linters that recognize insecure archive usage patterns.
- Monitor runtime for unusual file creation patterns originating from extraction services (e.g., writes outside expected directories) as a compensating operational control.

