Skip to main content

SKY-D326 · Security in code

Unsafe archive extraction

HighCWE-22

A tar archive can hold members named ../../home/app/.bashrc, absolute paths, or symlinks that point outside the folder you unpack into. SKY-D326 reports Python code that extracts an archive without a filter or a member check that stops this, a bug often called "Zip Slip".

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A plugin or backup upload that is unpacked with extractall() can overwrite any file the process may write: application code, cron jobs or SSH keys. The next restart then runs the attacker's code.

What Skylos flags

app/plugins.py · PythonReported on line 6
import tarfile  def install_plugin(bundle_path, plugins_dir):    with tarfile.open(bundle_path) as bundle:        bundle.extractall(plugins_dir)

What Skylos leaves alone

app/plugins.py · Python
import tarfile  def install_plugin(bundle_path, plugins_dir):    with tarfile.open(bundle_path) as bundle:        bundle.extractall(plugins_dir, filter="data")

Why Skylos leaves it alone

The data filter (Python 3.12, and security releases of 3.8 to 3.11) refuses members with absolute paths, .. parts, links that leave the folder, and device files. Skylos accepts filter="data" and filter="tar" written as literals.

More languages

Python

Flagged

app/restore.py · PythonReported on line 5
import shutil  def restore_backup(archive_path, target_dir):    shutil.unpack_archive(archive_path, target_dir)

Not flagged

app/restore.py · Python
import zipfile  def restore_backup(archive_path, target_dir):    with zipfile.ZipFile(archive_path) as backup:        backup.extractall(target_dir)

Why Skylos leaves it alone

zipfile removes absolute paths and .. parts from member names and never creates links, so Skylos does not report a ZipFile extraction. shutil.unpack_archive() may open a tar file, so it is reported unless it passes a safe filter.

How Skylos decides

  1. Finds extract() and extractall() calls, plus shutil.unpack_archive(). An extract() call must be able to pass a member and use only archive keywords, so BeautifulSoup's tag.extract() and OpenTelemetry's extract() do not match.
  2. Follows the receiver back to its constructor. A zipfile.ZipFile or PyZipFile is skipped, and so is a project class's own extract method. A tarfile archive or a receiver Skylos cannot resolve is checked.
  3. Skips the call when it passes a literal filter="data" or filter="tar".
  4. Skips it when the same function first checks members: it mentions issym, islnk, is_symlink, is_absolute, normpath, commonpath or relative_to before the extraction.
  5. Reports the rest as HIGH. Test files are scanned too.

How to fix it

On current Python, pass filter="data". On older versions, check every member before extracting: refuse links and any name whose resolved path leaves the target folder.

app/plugins.py · Python · the fix, against the flagged file
Added: import osimport tarfile  def install_plugin(bundle_path, plugins_dir):Added:     root = os.path.realpath(plugins_dir)    with tarfile.open(bundle_path) as bundle:Removed:         bundle.extractall(plugins_dir)Added:         for member in bundle.getmembers():Added:             target = os.path.realpath(os.path.join(root, member.name))Added:             if member.issym() or member.islnk():Added:                 raise ValueError(f"link in bundle: {member.name}")Added:             if os.path.commonpath([root, target]) != root:Added:                 raise ValueError(f"unsafe path in bundle: {member.name}")Added:         bundle.extractall(root)

When it can be wrong

  • Extracting an archive your own build produced, such as a vendored test fixture, is still reported: the rule does not ask where the archive comes from.
  • A member check done in a helper function is not seen; only the words in the extracting function count. Equally, mentioning one of those words for another reason quiets the finding.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed call and say why. A bare # noqa does not hide HIGH security findings.

    Python
    bundle.extractall(dest)  # skylos: ignore[SKY-D326] members checked by verify_bundle()
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D326"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.