From 2c2cadacd9b57a3764692f539ffcde6f68e33a1a Mon Sep 17 00:00:00 2001 From: prasanna8585 <65734642+prasanna8585@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:56:56 +0530 Subject: [PATCH] Fix zip-slip blacklist bypass in isDangerousZipEntryName isDangerousZipEntryName rejected entries via string prefix/substring checks (startsWith('/'), startsWith('../'), includes('/../')), which misses entries whose traversal segment isn't bounded by a following '/' -- e.g. an entry named exactly 'scripts/..' (no trailing content) passes all three checks, as does any entry using backslash as a separator instead of forward slash (e.g. 'scripts\\..\\..\\evil'). Confirmed via a dynamic PoC (crafted a real zip with Python's zipfile module, bypassing AdmZip's own write-side path normalization, and fed the raw bytes through the actual compiled loadSkillFromZipBuffer) that 'scripts/..' passes the old check and reaches skill.resources.scripts['..']. A second, independent hardened check in materializeFiles (utils/file_utils.ts) was confirmed to catch and reject the resulting escape attempt in every consumer of this data that writes to disk, so this fix closes a genuine gap in defense-in-depth rather than a currently-reachable filesystem escape. Replaces the prefix/substring checks with a segment-based check: split on both '/' and '\\' and reject if any segment is exactly '..', plus an explicit absolute-path check (POSIX and Windows style). Verified against the previous bypass cases, the existing test suite (68 tests, all still pass), and additional false-positive traps (filenames merely containing '..' as a substring, e.g. 'a/b..c/d', must not be rejected). --- core/src/skills/loader.ts | 9 ++++----- core/test/skills/loader_test.ts | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/src/skills/loader.ts b/core/src/skills/loader.ts index e02d3e5649..dacda6b5a2 100644 --- a/core/src/skills/loader.ts +++ b/core/src/skills/loader.ts @@ -185,11 +185,10 @@ export function parseSkillMdContent(content: string): { * symlinks. */ function isDangerousZipEntryName(entryName: string): boolean { - return ( - entryName.startsWith('/') || - entryName.startsWith('../') || - entryName.includes('/../') - ); + if (path.posix.isAbsolute(entryName) || path.win32.isAbsolute(entryName)) { + return true; + } + return entryName.split(/[/\\]/).some((segment) => segment === '..'); } /** diff --git a/core/test/skills/loader_test.ts b/core/test/skills/loader_test.ts index d9d24d246d..b793dee0ba 100644 --- a/core/test/skills/loader_test.ts +++ b/core/test/skills/loader_test.ts @@ -612,14 +612,17 @@ Instruction body`; expect(skill.resources?.scripts?.['run.sh']?.src).toBe('echo hello'); }); - it.each(['/etc/passwd', '../evil.txt', 'references/../../esc.txt'])( - 'rejects the whole archive for the dangerous entry %s', - (entryName) => { - expect(() => - loadSkillFromZipBuffer(createZipWithRawEntryName(entryName)), - ).toThrow(`Dangerous zip entry ignored: ${entryName}`); - }, - ); + it.each([ + '/etc/passwd', + '../evil.txt', + 'references/../../esc.txt', + 'scripts/..', + 'scripts\\..\\..\\pwned.txt', + ])('rejects the whole archive for the dangerous entry %s', (entryName) => { + expect(() => + loadSkillFromZipBuffer(createZipWithRawEntryName(entryName)), + ).toThrow(`Dangerous zip entry ignored: ${entryName}`); + }); it('reports the dangerous entry even when SKILL.md is absent', () => { const zip = new AdmZip();