@devries-cameron20 / composio-1 / commits / f92605814
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.

fix(cli): refuse symlink entries when extracting archives (#4210)

Addresses the `pnpm audit --prod` warning that has been riding along on recent CLI PRs: **`extract-zip` unvalidated symlink path traversal**, [GHSA-jmr9-qjv8-65gv](https://github.com/advisories/GHSA-jmr9-qjv8-65gv) / CVE-2026-56876, high. ## There is no version to upgrade to `pnpm audit` renders "Patched versions >=2.0.2", which reads like a bump would fix it. It would not: - `npm view extract-zip versions` ends at **2.0.1** — no 2.0.2 was ever published - the advisory itself records `"first_patched_version": null` So `pnpm audit --fix --prod` cannot resolve this, and neither can a version constraint. ## What the flaw actually is I reproduced it rather than working from the summary. `extract-zip` 2.0.1 **does** block writes that traverse a symlink — an archive with `link -> ../../ESCAPED` plus `link/pwned.txt` is refused with `Out of bound path ... while processing file link/pwned.txt`, and nothing lands outside the target. What it does not do is validate the symlink itself. An archive whose only entry is `escape-abs -> /tmp/ABSOLUTE-TARGET` extracts cleanly and plants that dangling symlink in the output directory. Per the advisory: *"Depending on how extract-zip is used, an attacker could read or write to arbitrary files."* Every call site here extracts an archive and then reads or copies files back out of the tree, which is exactly the shape that turns a planted symlink into an arbitrary-path read. ## Why not swap the library `#4183` moved tar extraction to `Bun.Archive`, so that was the obvious candidate. It does not work: **`Bun.Archive` cannot read zip archives at all.** A benign zip fails with `ReadError`, same as the malicious ones — those "refusals" were read failures, not security. Verified before ruling it out. ## Why not fix it upstream Because it already is, three times over, and none of it has moved: | PR | Date | Targets | | --- | --- | --- | | [max-mapper/extract-zip#158](https://github.com/max-mapper/extract-zip/pull/158) | 2026-08-14 | GHSA-jmr9-qjv8-65gv, this advisory | | [#160](https://github.com/max-mapper/extract-zip/pull/160) | 2026-08-17 | CVE-2026-19693, symlink at the final path component | | [#161](https://github.com/max-mapper/extract-zip/pull/161) | 2026-08-20 | CVE-2026-56876 again, and bumps the version to 2.0.2 | All three are mergeable with zero review comments. The repository's last commit to `master` was **August 2021**; 2.0.1 shipped June 2020. [Issue #159](https://github.com/max-mapper/extract-zip/issues/159), a downstream consumer asking whether a patched release is planned, has three replies — every one from another stranded consumer, none from a maintainer. A fourth PR would not be a contribution. And our implementation is the wrong shape to upstream regardless: refusing *every* symlink is right for an application whose archives never carry one, but a breaking change for a general-purpose library, where the correct fix is validating that a link's resolved target stays inside the extraction root — which is what #158 and #161 already do. Upstream even tracks "do not extract symlinks" as a separate [feature request](https://github.com/max-mapper/extract-zip/issues/140), open since 2023. So this is a deliberate local workaround on a timeline we control. The helper's doc comment records the tracking PRs and the condition for deleting it: a published release that actually carries the fix. ## The fix No archive either package extracts — release binaries, companion assets, skills, sidecar bundles — legitimately contains a symlink. So the entry type is refused outright, via `extract-zip`'s own `onEntry` hook, which runs **before** the entry is written. A rejected archive plants nothing. All four call sites now go through it: | package | call site | | --- | --- | | `cli` | `services/upgrade-binary.ts` | | `cli` | `services/run-companion-modules.ts` | | `cli` | `effects/install-skill.ts` | | `cli-local-tools` | `src/bundled-binaries.ts` | Each package carries its own copy of the helper rather than sharing one. `run-companion-modules.ts` is bundled as a standalone companion module and imports nothing from `@composio/cli-local-tools`; routing it through that package to share ~15 lines would pull the local-tools tree into those bundles. ## Verification Committed three fixture archives (827 bytes total) and tested against real zips, not mocks: - benign archive extracts, contents intact - `symlink-absolute.zip` (`-> /tmp/ABSOLUTE-TARGET`) refused, output directory left empty - `symlink-relative.zip` (`-> ../../outside`) refused, output directory left empty - `isSymlinkZipEntry` unit-tested across symlink, regular file, directory, and Windows-authored entries with no Unix mode **Mutation-checked:** neutering the predicate makes exactly the three symlink tests fail and leaves the other four green, so the suite genuinely detects the regression rather than passing by construction. Suites: `@composio/cli` 123 files / 1263 passed, `@composio/cli-local-tools` 7 files / 20 passed. Typecheck clean on both. `pnpm validate:changesets` passes; note lands in `ts/packages/cli/CHANGELOG.md`. `extract-zip` stays as the dependency — it is still the only working zip reader here, and with symlink entries refused the advisory's vector no longer applies to this codebase. https://claude.ai/code/session_01JkwtxPHfobZxzvAqe53x62

Alberto Schiabel committed Aug 23, 2026 at 12:28 UTC f926058147ced00bf2381e846a001b983fb5bc79
15 files changed +237 -8
ts/packages/cli-local-tools/src/bundled-binaries.ts
+2 -2
@@ -3,7 +3,7 @@ import fs from 'node:fs/promises';
3 import os from 'node:os';
4 import path from 'node:path';
5 import { fileURLToPath } from 'node:url';
6 -import extractZip from 'extract-zip';
6 +import { extractZipSafely } from './extract-zip-safely';
7 import { detectCliPlatform, supportsCliPlatform } from './platform';
8 import type {
9 LocalBundledBinaryDeclaration,
@@ -233,7 +233,7 @@ const repairInstalledLocalToolsBundle = async (): Promise<boolean> => {
233 const zipPath = path.join(tempDir, asset.name);
234 const extractDir = path.join(tempDir, 'extract');
235 await fs.writeFile(zipPath, archiveData);
236 - await extractZip(zipPath, { dir: extractDir });
236 + await extractZipSafely(zipPath, extractDir);
237
238 const archiveBundleRoot = path.join(
239 extractDir,
ts/packages/cli-local-tools/src/extract-zip-safely.test.ts new
+54
@@ -0,0 +1,54 @@
1 +import fs from 'node:fs';
2 +import os from 'node:os';
3 +import path from 'node:path';
4 +import { describe, expect, it } from 'vitest';
5 +import { extractZipSafely, isSymlinkZipEntry, UnsafeZipEntryError } from './extract-zip-safely';
6 +
7 +const FIXTURES_DIR = path.join(__dirname, 'zip-fixtures');
8 +
9 +const withTempDir = async (use: (dir: string) => Promise<void>): Promise<void> => {
10 + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'local-tools-extract-'));
11 + try {
12 + await use(dir);
13 + } finally {
14 + fs.rmSync(dir, { recursive: true, force: true });
15 + }
16 +};
17 +
18 +describe('isSymlinkZipEntry', () => {
19 + it.each([
20 + ['symbolic link', 0o120755, true],
21 + ['regular file', 0o100644, false],
22 + ['directory', 0o40755, false],
23 + ])('classifies a %s', (_label, mode, expected) => {
24 + expect(isSymlinkZipEntry(mode << 16)).toBe(expected);
25 + });
26 +
27 + it('accepts a Windows-authored entry that carries no Unix mode', () => {
28 + expect(isSymlinkZipEntry(0)).toBe(false);
29 + });
30 +});
31 +
32 +describe('extractZipSafely', () => {
33 + it('extracts an archive of regular files and directories', async () => {
34 + await withTempDir(async dir => {
35 + await extractZipSafely(path.join(FIXTURES_DIR, 'benign.zip'), dir);
36 +
37 + expect(fs.readFileSync(path.join(dir, 'a.txt'), 'utf8').trim()).toBe('hello');
38 + expect(fs.readFileSync(path.join(dir, 'sub', 'b.txt'), 'utf8').trim()).toBe('world');
39 + });
40 + });
41 +
42 + it.each(['symlink-absolute.zip', 'symlink-relative.zip'])(
43 + 'refuses %s and plants nothing',
44 + async fixture => {
45 + await withTempDir(async dir => {
46 + await expect(extractZipSafely(path.join(FIXTURES_DIR, fixture), dir)).rejects.toThrow(
47 + UnsafeZipEntryError
48 + );
49 +
50 + expect(fs.readdirSync(dir)).toEqual([]);
51 + });
52 + }
53 + );
54 +});
ts/packages/cli-local-tools/src/extract-zip-safely.ts new
+40
@@ -0,0 +1,40 @@
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), and the advisory has no fixed
8 + * version. Sidecar archives never contain symlinks, so rejecting the entry type
9 + * removes the vector. See the matching helper in `@composio/cli` for why this
10 + * is a local workaround rather than an upstream fix, and when it can go; the
11 + * two are kept separate because this package must not be pulled into the CLI's
12 + * standalone companion bundles.
13 + */
14 +
15 +// Unix mode lives in the high 16 bits of a zip entry's external attributes.
16 +const UNIX_MODE_SHIFT = 16;
17 +const FILE_TYPE_MASK = 0o170000;
18 +const SYMLINK_FILE_TYPE = 0o120000;
19 +
20 +export class UnsafeZipEntryError extends Error {
21 + constructor(readonly entryName: string) {
22 + super(
23 + `Refusing to extract archive: "${entryName}" is a symbolic link, which this CLI never ships.`
24 + );
25 + this.name = 'UnsafeZipEntryError';
26 + }
27 +}
28 +
29 +export const isSymlinkZipEntry = (externalFileAttributes: number): boolean =>
30 + ((externalFileAttributes >>> UNIX_MODE_SHIFT) & FILE_TYPE_MASK) === SYMLINK_FILE_TYPE;
31 +
32 +export const extractZipSafely = (zipPath: string, dir: string): Promise<void> =>
33 + extractZip(zipPath, {
34 + dir,
35 + onEntry: entry => {
36 + if (isSymlinkZipEntry(entry.externalFileAttributes)) {
37 + throw new UnsafeZipEntryError(entry.fileName);
38 + }
39 + },
40 + });
ts/packages/cli-local-tools/src/zip-fixtures/benign.zip
Binary files /dev/null and b/ts/packages/cli-local-tools/src/zip-fixtures/benign.zip differ
ts/packages/cli-local-tools/src/zip-fixtures/symlink-absolute.zip
Binary files /dev/null and b/ts/packages/cli-local-tools/src/zip-fixtures/symlink-absolute.zip differ
ts/packages/cli-local-tools/src/zip-fixtures/symlink-relative.zip
Binary files /dev/null and b/ts/packages/cli-local-tools/src/zip-fixtures/symlink-relative.zip differ
ts/packages/cli/CHANGELOG.md
+5
@@ -4,6 +4,11 @@
4
5 ### Patch Changes
6
7 +- Archives are no longer extracted with symbolic links in them. `extract-zip`
8 + creates a symlink entry without validating its target (CVE-2026-56876), which
9 + has no fixed release, and anything that later reads the extracted tree can be
10 + walked out of it. No archive this CLI extracts legitimately contains a
11 + symlink, so such an entry is now refused before it is written.
12 - `composio search` now uses schemas returned by Tool Router for dashboard-registered custom MCP tools instead of querying the legacy managed-tool endpoint, which returned 404 for `CUSTOM_*` tool slugs.
13 - `composio upgrade` works again from any previously released CLI. Release
14 archives had been narrowed to carry only the `codex-acp` binary their own
ts/packages/cli/src/effects/install-skill.ts
+2 -2
@@ -11,7 +11,7 @@ import {
11 type GitHubRelease,
12 type GitHubRepoConfig,
13 } from 'src/effects/resolve-cli-release';
14 -import extractZip from 'extract-zip';
14 +import { extractZipSafely } from 'src/utils/extract-zip-safely';
15
16 const SKILL_NAME = 'composio-cli';
17 const SKILL_ASSET_NAME = 'composio-skill.zip';
@@ -218,7 +218,7 @@ export const installSkill = (options?: {
218 yield* fs.writeFile(zipPath, new Uint8Array(zipData));
219
220 yield* Effect.tryPromise({
221 - try: () => extractZip(zipPath, { dir: tmpDir }),
221 + try: () => extractZipSafely(zipPath, tmpDir),
222 catch: cause =>
223 new SkillInstallError({
224 cause,
ts/packages/cli/src/services/run-companion-modules.ts
+2 -2
@@ -5,7 +5,7 @@
5 import { FileSystem, Path } from '@effect/platform';
6 import type { PlatformError } from '@effect/platform/Error';
7 import { Config, ConfigProvider, Data, Effect, Option, Schema } from 'effect';
8 -import extractZip from 'extract-zip';
8 +import { extractZipSafely } from 'src/utils/extract-zip-safely';
9 import { IS_RELEASE_BUILD } from 'src/constants';
10 import { GitHubRelease } from 'src/effects/resolve-cli-release';
11 import { BaseConfigProviderLive, extendConfigProvider } from 'src/services/config';
@@ -713,7 +713,7 @@ export const repairMissingInstalledRunCompanionModules = ({
713 yield* fs.writeFile(archivePath, archiveData);
714 yield* fs.makeDirectory(extractDirectory, { recursive: true });
715 yield* Effect.tryPromise({
716 - try: () => extractZip(archivePath, { dir: extractDirectory }),
716 + try: () => extractZipSafely(archivePath, extractDirectory),
717 catch: toRepairError,
718 });
719
ts/packages/cli/src/services/upgrade-binary.ts
+2 -2
@@ -23,7 +23,7 @@ import {
23 } from 'src/utils/atomic-replace';
24
25 // Note: `node:zlib` does not support Github's zip files
26 -import extractZip from 'extract-zip';
26 +import { extractZipSafely } from 'src/utils/extract-zip-safely';
27 import { renderPrettyError } from './utils/pretty-error';
28 import { TerminalUI } from './terminal-ui';
29 import {
@@ -366,7 +366,7 @@ const extractBinary = (
366
367 yield* Effect.tryPromise({
368 try: async () => {
369 - await extractZip(zipPath, { dir: extractDir });
369 + await extractZipSafely(zipPath, extractDir);
370 },
371 catch: error =>
372 new UpgradeBinaryError({
ts/packages/cli/src/utils/extract-zip-safely.ts new
+61
@@ -0,0 +1,61 @@
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 + });
ts/packages/cli/test/src/utils/extract-zip-safely.test.ts new
+69
@@ -0,0 +1,69 @@
1 +import * as fs from 'node:fs';
2 +import * as os from 'node:os';
3 +import * as path from 'node:path';
4 +import { describe, expect, it } from '@effect/vitest';
5 +import {
6 + extractZipSafely,
7 + isSymlinkZipEntry,
8 + UnsafeZipEntryError,
9 +} from 'src/utils/extract-zip-safely';
10 +
11 +const FIXTURES_DIR = path.join(__dirname, 'zip-fixtures');
12 +
13 +const withTempDir = async (use: (dir: string) => Promise<void>): Promise<void> => {
14 + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'extract-zip-safely-'));
15 + try {
16 + await use(dir);
17 + } finally {
18 + fs.rmSync(dir, { recursive: true, force: true });
19 + }
20 +};
21 +
22 +/**
23 + * `mode << 16` is how a zip stores the Unix mode in its external attributes.
24 + */
25 +const externalAttributesFor = (mode: number): number => mode << 16;
26 +
27 +describe('isSymlinkZipEntry', () => {
28 + it('detects a symbolic link', () => {
29 + expect(isSymlinkZipEntry(externalAttributesFor(0o120755))).toBe(true);
30 + });
31 +
32 + it('accepts a regular file', () => {
33 + expect(isSymlinkZipEntry(externalAttributesFor(0o100644))).toBe(false);
34 + });
35 +
36 + it('accepts a directory', () => {
37 + expect(isSymlinkZipEntry(externalAttributesFor(0o40755))).toBe(false);
38 + });
39 +
40 + it('accepts a Windows-authored entry that carries no Unix mode', () => {
41 + expect(isSymlinkZipEntry(0)).toBe(false);
42 + });
43 +});
44 +
45 +describe('extractZipSafely', () => {
46 + it('extracts an archive of regular files and directories', async () => {
47 + await withTempDir(async dir => {
48 + await extractZipSafely(path.join(FIXTURES_DIR, 'benign.zip'), dir);
49 +
50 + expect(fs.readFileSync(path.join(dir, 'a.txt'), 'utf8').trim()).toBe('hello');
51 + expect(fs.readFileSync(path.join(dir, 'sub', 'b.txt'), 'utf8').trim()).toBe('world');
52 + });
53 + });
54 +
55 + it.each([
56 + ['symlink-absolute.zip', 'escape-abs'],
57 + ['symlink-relative.zip', 'escape-rel'],
58 + ])('refuses %s and plants nothing', async (fixture, entryName) => {
59 + await withTempDir(async dir => {
60 + await expect(extractZipSafely(path.join(FIXTURES_DIR, fixture), dir)).rejects.toThrow(
61 + UnsafeZipEntryError
62 + );
63 +
64 + // The guard runs before the entry is written, so the target stays empty.
65 + expect(fs.readdirSync(dir)).toEqual([]);
66 + expect(fs.existsSync(path.join(dir, entryName))).toBe(false);
67 + });
68 + });
69 +});
ts/packages/cli/test/src/utils/zip-fixtures/benign.zip
Binary files /dev/null and b/ts/packages/cli/test/src/utils/zip-fixtures/benign.zip differ
ts/packages/cli/test/src/utils/zip-fixtures/symlink-absolute.zip
Binary files /dev/null and b/ts/packages/cli/test/src/utils/zip-fixtures/symlink-absolute.zip differ
ts/packages/cli/test/src/utils/zip-fixtures/symlink-relative.zip
Binary files /dev/null and b/ts/packages/cli/test/src/utils/zip-fixtures/symlink-relative.zip differ