@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 61 lines 2.7 KB
Raw
1 import extractZip from 'extract-zip';
2
3 /**
4 * Zip extraction that refuses symlink entries.
5 *
6 * `extract-zip` writes a symlink entry without validating its target
7 * (CVE-2026-56876 / GHSA-jmr9-qjv8-65gv). It does block writes that *traverse* a
8 * symlink, so an archive cannot plant a file outside the extraction directory,
9 * but the dangling symlink itself is created — pointing anywhere, including an
10 * absolute path. Anything that later reads or copies the extracted tree can be
11 * walked out of it. The advisory has no fixed version: 2.0.1 is the newest
12 * release, and GitHub records `first_patched_version` as null.
13 *
14 * No archive this CLI extracts — release binaries, companion assets, skills —
15 * legitimately contains a symlink, so rejecting the entry type outright removes
16 * the vector without narrowing what a valid archive may hold. The check runs
17 * before the entry is written, so a rejected archive plants nothing.
18 *
19 * This is deliberately a local workaround rather than an upstream fix. Refusing
20 * every symlink suits an application whose archives never carry one, but it
21 * would break a general-purpose library, where the correct fix is to validate
22 * that a link's resolved target stays inside the extraction root. That fix is
23 * already proposed upstream several times over — max-mapper/extract-zip#158,
24 * #160 and #161 — and none of them has moved: the repository's last commit was
25 * August 2021, and the issue asking whether a patched release is planned
26 * (max-mapper/extract-zip#159) has drawn replies only from other stranded
27 * consumers. Drop this helper once a release actually carries the fix.
28 */
29
30 // Unix mode lives in the high 16 bits of a zip entry's external attributes.
31 const UNIX_MODE_SHIFT = 16;
32 const FILE_TYPE_MASK = 0o170000;
33 const SYMLINK_FILE_TYPE = 0o120000;
34
35 export class UnsafeZipEntryError extends Error {
36 constructor(readonly entryName: string) {
37 super(
38 `Refusing to extract archive: "${entryName}" is a symbolic link, which this CLI never ships.`
39 );
40 this.name = 'UnsafeZipEntryError';
41 }
42 }
43
44 /**
45 * Whether a zip entry's external attributes describe a symbolic link.
46 *
47 * Archives written on Windows leave the Unix mode bits empty, which reads as a
48 * regular file — the correct answer, since such an archive has no symlinks.
49 */
50 export const isSymlinkZipEntry = (externalFileAttributes: number): boolean =>
51 ((externalFileAttributes >>> UNIX_MODE_SHIFT) & FILE_TYPE_MASK) === SYMLINK_FILE_TYPE;
52
53 export const extractZipSafely = (zipPath: string, dir: string): Promise<void> =>
54 extractZip(zipPath, {
55 dir,
56 onEntry: entry => {
57 if (isSymlinkZipEntry(entry.externalFileAttributes)) {
58 throw new UnsafeZipEntryError(entry.fileName);
59 }
60 },
61 });