{"record":{"id":"0157a514acbdcdab","repo":"anthropics/skills","slug":"unsafe-archive-entry-m-filename-r-0157a5","errorCode":null,"errorMessage":"unsafe archive entry: {m.filename!r}","messagePattern":"unsafe archive entry: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/pptx/scripts/office/helpers/__init__.py","lineNumber":81,"sourceCode":"def part_text(data: bytes) -> str:\n    return data.decode(\"utf-8\", \"surrogateescape\")\n\n\nXML_SPACE = \" \\t\\r\\n\"\n\n\ndef rendered_text(text: str, preserve: bool) -> str:\n    return text if preserve else text.strip(XML_SPACE)\n\n\ndef safe_extract(zf: zipfile.ZipFile, dest: Path) -> None:\n    dest = dest.resolve()\n    for m in zf.infolist():\n        if stat.S_ISLNK(m.external_attr >> 16):\n            raise ValueError(f\"symlink archive entry not allowed: {m.filename!r}\")\n        target = (dest / m.filename).resolve()\n        if not target.is_relative_to(dest):\n            raise ValueError(f\"unsafe archive entry: {m.filename!r}\")\n        zf.extract(m, dest)\n\n\ndef rezip(src_dir: Path, out_path: Path) -> None:\n    files = sorted(p for p in src_dir.rglob(\"*\") if p.is_file())\n    ct = src_dir / \"[Content_Types].xml\"\n    fd, tmp_name = tempfile.mkstemp(\n        prefix=out_path.name + \".\", suffix=\".tmp\", dir=out_path.parent\n    )\n    tmp_out = Path(tmp_name)\n    try:\n        with os.fdopen(fd, \"wb\") as fh:\n            with zipfile.ZipFile(fh, \"w\", zipfile.ZIP_DEFLATED) as zf:\n                if ct.exists():\n                    zf.write(ct, ct.relative_to(src_dir), compress_type=zipfile.ZIP_STORED)\n                for f in files:\n                    if f == ct:\n                        continue","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/anthropics/skills/blob/f6656c1256d5a8adfa37db9110046ef20bac644c/skills/pptx/scripts/office/helpers/__init__.py#L63-L99","documentation":"pptx copy of the zip-slip escape guard (same as error 7): safe_extract() resolves each member's destination path and raises if it falls outside the extraction directory — absolute entry names ('/etc/x') or '..' traversal. This blocks arbitrary-file overwrite during unpack of hostile or malformed archives.","triggerScenarios":"Unpacking an archive containing an entry named '/tmp/evil' or '../../../home/u/.bashrc'; also non-OOXML zips mistakenly fed to the pptx unpack flow.","commonSituations":"Malicious uploads; corrupted zip central directories producing mangled names; archives from unreliable sources.","solutions":["Reject/quarantine the file — the guard fired on a genuinely dangerous entry name.","If the entry name is corruption fallout, rebuild the archive with clean relative names.","Pre-scan archives for absolute or '..' names before processing.","Restrict the pipeline to trusted .pptx sources."],"exampleFix":"# pre-scan gate\nimport zipfile\ndef escapes(path):\n    with zipfile.ZipFile(path) as zf:\n        return any(n.startswith(\"/\") or \"..\" in n.split(\"/\") for n in zf.namelist())\nif escapes(upload):\n    raise ValueError(\"reject archive with escaping entries\")","handlingStrategy":"validation","validationCode":"import zipfile\n\ndef has_escaping_entries(path: str) -> bool:\n    with zipfile.ZipFile(path) as zf:\n        return any(n.startswith(\"/\") or n.startswith(\"\\\\\") or \"..\" in n.replace(\"\\\\\", \"/\").split(\"/\") for n in zf.namelist())","typeGuard":null,"tryCatchPattern":"from office.helpers import safe_extract\ntry:\n    safe_extract(zf, dest)\nexcept ValueError as e:\n    if \"unsafe archive entry\" in str(e):\n        quarantine(path)  # zip-slip; no fallback extraction\n    else:\n        raise","preventionTips":["Pre-scan namelist() for absolute and '..' entry names.","Extract to fresh temp dirs; never over live data directories.","Never swap in raw extractall for untrusted archives."],"tags":["pptx","security","zip-slip","extraction"],"backgroundTag":null,"analyzedSha":"f6656c1256d5a8adfa37db9110046ef20bac644c","analyzedAt":"2026-08-14T16:09:17.493Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}