{"record":{"id":"3b4544ce090c1bc9","repo":"anthropics/skills","slug":"symlink-archive-entry-not-allowed-m-filename-r-3b4544","errorCode":null,"errorMessage":"symlink archive entry not allowed: {m.filename!r}","messagePattern":"symlink archive entry not allowed: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/xlsx/scripts/office/helpers/__init__.py","lineNumber":78,"sourceCode":"    return posixpath.join(owner_dir.as_posix(), rels_file.name[: -len(\".rels\")]).lstrip(\"./\")\n\n\ndef 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)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/anthropics/skills/blob/f6656c1256d5a8adfa37db9110046ef20bac644c/skills/xlsx/scripts/office/helpers/__init__.py#L60-L96","documentation":"safe_extract() refuses to extract any zip entry whose unix mode bits (external_attr >> 16) indicate a symlink. Office files are expected to contain only regular files; symlinks in archives are a classic vehicle for arbitrary-file-write attacks, so extraction aborts before writing anything for that entry.","triggerScenarios":"Calling safe_extract(zf, dest) on an OOXML package (or any zip) that contains an entry created with symlink mode bits — e.g. crafted with `ln -s /etc/passwd l; zip -y evil.zip l`; archives produced on unix systems that preserved symlinks.","commonSituations":"Processing Office documents from untrusted sources (email attachments, uploads); test fixtures accidentally zipped with -y; hostile files specifically targeting zip-slip-adjacent extraction bugs.","solutions":["Inspect the archive: `unzip -l file.xlsx` plus `zipinfo` shows the mode column — symlinks appear as 'l' in `zipinfo`","Do not attempt to bypass; reject or quarantine the file — a symlink entry in an Office package is never legitimate","If it is your own fixture, re-zip without symlinks: dereference with `zip -r` (no -y) or tar the files fresh"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import stat, zipfile\n\ndef archive_has_symlinks(path: str) -> bool:\n    with zipfile.ZipFile(path) as zf:\n        return any(stat.S_ISLNK(m.external_attr >> 16) for m in zf.infolist())","typeGuard":null,"tryCatchPattern":"try:\n    safe_extract(zf, dest)\nexcept ValueError as e:\n    if \"symlink\" in str(e):\n        quarantine(file_path)  # never extract anyway — this is hostile content\n    raise","preventionTips":["Screen uploads with the symlink check before any extraction","Create your own test archives without `zip -y` so fixtures stay regular-file-only","Remember: an Office package legitimately contains only regular files; any exception is hostile or corrupt"],"tags":["zip","security","symlink","extraction","hardening"],"backgroundTag":null,"analyzedSha":"f6656c1256d5a8adfa37db9110046ef20bac644c","analyzedAt":"2026-08-14T16:09:17.493Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}