SKY-D326 · Security in code
Unsafe archive extraction
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
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
import tarfile def install_plugin(bundle_path, plugins_dir): with tarfile.open(bundle_path) as bundle: bundle.extractall(plugins_dir)What Skylos leaves alone
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
import shutil def restore_backup(archive_path, target_dir): shutil.unpack_archive(archive_path, target_dir)Not flagged
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
- Finds
extract()andextractall()calls, plusshutil.unpack_archive(). Anextract()call must be able to pass a member and use only archive keywords, so BeautifulSoup'stag.extract()and OpenTelemetry'sextract()do not match. - Follows the receiver back to its constructor. A
zipfile.ZipFileorPyZipFileis skipped, and so is a project class's ownextractmethod. Atarfilearchive or a receiver Skylos cannot resolve is checked. - Skips the call when it passes a literal
filter="data"orfilter="tar". - Skips it when the same function first checks members: it mentions
issym,islnk,is_symlink,is_absolute,normpath,commonpathorrelative_tobefore the extraction. - 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.
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
# noqadoes 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--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D326"]turns the rule off for the whole project.