Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ad75c92
fix(core): accept contained symlinks in the older-Git archive fallback
harjothkhara Aug 24, 2026
008c94c
fix(core): harden contained symlink validation
harjothkhara Aug 25, 2026
0bb7337
test(core): pin post-flatten symlink validation
harjothkhara Aug 25, 2026
4ecfb52
fix(core): reject post-extraction symlink chains
harjothkhara Aug 25, 2026
c54eafb
fix(core): enforce materialized archive size
harjothkhara Aug 25, 2026
c4a23fd
fix(core): validate final archive layout exactly
harjothkhara Aug 25, 2026
7ae9f97
fix(core): bound archive path validation
harjothkhara Aug 25, 2026
7a800e9
fix(core): reject unresolved archive targets
harjothkhara Aug 25, 2026
2135c75
fix(core): canonicalize archive entry separators
harjothkhara Aug 25, 2026
d707895
test(core): cover symlink descendant extraction
harjothkhara Aug 25, 2026
e1c29cf
fix(core): reject ambiguous symlink targets
harjothkhara Aug 25, 2026
83dc67c
fix(core): wrap archive layout errors
harjothkhara Aug 25, 2026
640d8e2
fix(core): preserve validated plugin symlinks
harjothkhara Aug 25, 2026
2b3cafd
fix(core): reject root-normalized link entries
harjothkhara Aug 25, 2026
6d5ae8c
fix(core): close archive-safety review-round-3 gaps
harjothkhara Aug 26, 2026
3e2f352
fix(core): re-validate symlinks when conversion moves the archive-val…
harjothkhara Aug 26, 2026
2340e39
Merge branch 'main' into fix/9724-safe-archive-symlinks
wenshao Aug 26, 2026
5f22a62
fix(core): make the post-conversion symlink re-validation guard reach…
harjothkhara Aug 26, 2026
e0e6530
test(core): fix round-5 review gaps in the re-validation guard's tests
harjothkhara Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/users/extension/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Only scoped packages (`@scope/package-name`) are supported to avoid ambiguity wi

Git 2.37 or newer is required for credentialed, non-GitHub, nested marketplace, submodule, and Git LFS sources because Qwen Code uses `http.curloptResolve` to pin Git connections to validated DNS results. On older Git versions, Qwen Code supports only anonymous public `https://github.com/{owner}/{repo}[.git]` root repositories by resolving the requested ref to a commit and downloading GitHub's source archive with the same public-network and archive-safety checks.

Because the older-Git fallback installs from a source archive rather than a clone, it cannot install repositories that rely on symlinks, submodules, or Git LFS, and it caps downloads at 100 MiB compressed and archives at 100,000 entries / 1 GiB expanded. Release-based installs are still preferred when a repository publishes releases.
Because the older-Git fallback installs from a source archive rather than a clone, it cannot install repositories that rely on submodules or Git LFS, and it caps downloads at 100 MiB compressed and archives at 100,000 entries / 1 GiB expanded, including files materialized from symlinks. Symlinks directly targeting regular files in the repository are supported; directory, chained, dangling, absolute, escaping, and hard links still require Git 2.37 or newer. Release-based installs are still preferred when a repository publishes releases.

```bash
qwen extensions install https://github.com/github/github-mcp-server
Expand Down
242 changes: 230 additions & 12 deletions packages/core/src/extension/archive-safety.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import {
MAX_ARCHIVE_ENTRIES,
MAX_ARCHIVE_EXPANDED_BYTES,
assertTarArchiveHasNoLinks,
assertTarArchiveLinksAreSafe,
} from './archive-safety.js';

// Passthrough wrapper around `fs.createReadStream` that tests can hook to
Expand Down Expand Up @@ -55,7 +55,12 @@ vi.mock('node:fs', async (importOriginal) => {
// crafted headers are enough to exercise the entry-count and expanded-size
// limits without writing gigabytes of data or hundreds of thousands of
// files to disk.
function createTarFileHeader(name: string, size: number): Buffer {
function createTarFileHeader(
name: string,
size: number,
type = '0',
linkPath?: string,
): Buffer {
const header = Buffer.alloc(512);
header.write(name, 0, 100, 'utf8');
header.write('0000644\0', 100, 8); // mode
Expand All @@ -64,7 +69,8 @@ function createTarFileHeader(name: string, size: number): Buffer {
header.write(`${size.toString(8).padStart(11, '0')}\0`, 124, 12);
header.write('14763423360\0', 136, 12); // mtime
header.write(' ', 148, 8); // checksum placeholder (spaces)
header.write('0', 156, 1); // typeflag: regular file
header.write(type, 156, 1);
if (linkPath) header.write(linkPath, 157, 100, 'utf8');
header.write('ustar\0', 257, 6);
header.write('00', 263, 2);
let checksum = 0;
Expand All @@ -84,7 +90,7 @@ async function writeCraftedTar(
await fs.writeFile(archive, Buffer.concat([...headers, TAR_TRAILER]));
}

describe('assertTarArchiveHasNoLinks', () => {
describe('assertTarArchiveLinksAreSafe', () => {
let root: string;

beforeEach(async () => {
Expand All @@ -107,7 +113,7 @@ describe('assertTarArchiveHasNoLinks', () => {
const archive = path.join(root, 'links.tar');
await tar.c({ cwd: root, file: archive }, links);

await expect(assertTarArchiveHasNoLinks(archive)).rejects.toThrow(
await expect(assertTarArchiveLinksAreSafe(archive)).rejects.toThrow(
'more than 100 unsupported link entries',
);
},
Expand Down Expand Up @@ -139,7 +145,7 @@ describe('assertTarArchiveHasNoLinks', () => {
};

try {
await expect(assertTarArchiveHasNoLinks(archive)).rejects.toThrow(
await expect(assertTarArchiveLinksAreSafe(archive)).rejects.toThrow(
'more than 100 unsupported link entries',
);
} finally {
Expand Down Expand Up @@ -168,7 +174,7 @@ describe('assertTarArchiveHasNoLinks', () => {

try {
await expect(
assertTarArchiveHasNoLinks(
assertTarArchiveLinksAreSafe(
path.join(root, 'missing.tar'),
controller.signal,
),
Expand All @@ -191,7 +197,7 @@ describe('assertTarArchiveHasNoLinks', () => {
);

await expect(
assertTarArchiveHasNoLinks(archive, undefined, resourceLimits),
assertTarArchiveLinksAreSafe(archive, undefined, resourceLimits),
).resolves.toBeUndefined();
});

Expand All @@ -204,7 +210,7 @@ describe('assertTarArchiveHasNoLinks', () => {
);

await expect(
assertTarArchiveHasNoLinks(archive, undefined, resourceLimits),
assertTarArchiveLinksAreSafe(archive, undefined, resourceLimits),
).rejects.toThrow(
`Tar archive contains more than ${MAX_ARCHIVE_ENTRIES} entries.`,
);
Expand All @@ -220,7 +226,9 @@ describe('assertTarArchiveHasNoLinks', () => {
]),
);

await expect(assertTarArchiveHasNoLinks(archive)).resolves.toBeUndefined();
await expect(
assertTarArchiveLinksAreSafe(archive),
).resolves.toBeUndefined();
});

// The parser skips `size` content bytes after each header, so every entry
Expand Down Expand Up @@ -249,7 +257,7 @@ describe('assertTarArchiveHasNoLinks', () => {
await writeByteLimitTar(archive, MAX_ARCHIVE_EXPANDED_BYTES - 512);

await expect(
assertTarArchiveHasNoLinks(archive, undefined, resourceLimits),
assertTarArchiveLinksAreSafe(archive, undefined, resourceLimits),
).resolves.toBeUndefined();
});

Expand All @@ -258,9 +266,219 @@ describe('assertTarArchiveHasNoLinks', () => {
await writeByteLimitTar(archive, MAX_ARCHIVE_EXPANDED_BYTES - 512 + 1);

await expect(
assertTarArchiveHasNoLinks(archive, undefined, resourceLimits),
assertTarArchiveLinksAreSafe(archive, undefined, resourceLimits),
).rejects.toThrow(
`Tar archive expands beyond ${MAX_ARCHIVE_EXPANDED_BYTES} bytes.`,
);
});

// Issue #9724: the older-Git public archive fallback has to install public
// repositories that carry in-repo symlinks (the reported repro,
// `obra/superpowers`, ships a root `AGENTS.md -> CLAUDE.md`). Containment is
// decided from the archive's own paths, never from the extracted tree, so a
// hostile entry is refused before anything is written to disk.
describe('contained symlinks', () => {
const allowLinks = { allowContainedSymlinks: true } as const;
const symlinkHeader = (name: string, linkPath: string) =>
createTarFileHeader(name, 0, '2', linkPath);

it.runIf(process.platform !== 'win32')(
'accepts a root-level symlink to a sibling file',
async () => {
await fs.writeFile(path.join(root, 'CLAUDE.md'), '# guide\n');
await fs.symlink('CLAUDE.md', path.join(root, 'AGENTS.md'));
const archive = path.join(root, 'superpowers.tar');
await tar.c({ cwd: root, file: archive }, ['CLAUDE.md', 'AGENTS.md']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).resolves.toBeUndefined();
},
);

it.runIf(process.platform !== 'win32')(
'accepts a nested symlink that stays inside the archive root',
async () => {
await fs.mkdir(path.join(root, 'docs'));
await fs.writeFile(path.join(root, 'real.md'), 'x\n');
await fs.symlink('../real.md', path.join(root, 'docs', 'link.md'));
const archive = path.join(root, 'nested.tar');
await tar.c({ cwd: root, file: archive }, ['real.md', 'docs']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).resolves.toBeUndefined();
},
);

it.runIf(process.platform !== 'win32')(
'rejects a symlink whose target escapes the archive root',
async () => {
await fs.symlink('../../etc/hosts', path.join(root, 'escape'));
const archive = path.join(root, 'escape.tar');
await tar.c({ cwd: root, file: archive }, ['escape']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
},
);

it('rejects a symlink whose normalized target is exactly the archive parent', async () => {
const archive = path.join(root, 'parent.tar');
await writeCraftedTar(archive, [symlinkHeader('escape', '..')]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
});

it('rejects a backslash-separated traversal target', async () => {
const archive = path.join(root, 'backslash.tar');
await writeCraftedTar(archive, [
symlinkHeader('escape', '..\\..\\outside'),
]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
});

it('rejects a symlink with an absolute entry path', async () => {
const archive = path.join(root, 'absolute-entry.tar');
await writeCraftedTar(archive, [
symlinkHeader('/absolute-link', 'target'),
createTarFileHeader('target', 0),
]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
});

it('rejects a symlink resolving to its own directory', async () => {
const archive = path.join(root, 'self-cycle.tar');
await writeCraftedTar(archive, [symlinkHeader('self', '.')]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
});

it('rejects a symlink resolving to an ancestor directory', async () => {
const archive = path.join(root, 'ancestor-cycle.tar');
await writeCraftedTar(archive, [symlinkHeader('sub/loop', '..')]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retargeted both tests at inputs that actually reach their named clause — verified by mutation (deleting the ancestor clause now fails the ancestor test). The self-reference clause turned out to be structurally unreachable as a deciding factor: onReadEntry always records the entry itself in archiveEntries (typed SymbolicLink) before this check runs, so a link naming itself is always caught by the post-loop "target must be a distinct regular-file entry" scan regardless of this clause. Left a comment on that test explaining why it can't be made discriminating rather than claim it is.


await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
});

it('rejects link chains and dangling or directory targets', async () => {
const archive = path.join(root, 'indirect-targets.tar');
await writeCraftedTar(archive, [
createTarFileHeader('target', 0),
symlinkHeader('first', 'target'),
symlinkHeader('second', 'first'),
symlinkHeader('dangling', 'missing'),
createTarFileHeader('directory/', 0, '5'),
symlinkHeader('directory-link', 'directory'),
symlinkHeader('path-link', 'target'),
createTarFileHeader('path-link/child', 0),
]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('4 unsupported link entries');
});

it('counts materialized symlink targets toward the expanded-size limit', async () => {
const archive = path.join(root, 'materialized-size.tar');
const targetSize = Math.floor(MAX_ARCHIVE_EXPANDED_BYTES / 2) + 1;
await writeCraftedTar(archive, [
symlinkHeader('copy', 'target'),
createTarFileHeader('target', targetSize),
]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, {
...resourceLimits,
...allowLinks,
}),
).rejects.toThrow(
`Tar archive expands beyond ${MAX_ARCHIVE_EXPANDED_BYTES} bytes.`,
);
});

it('counts accepted symlinks toward the link-entry limit', async () => {
const archive = path.join(root, 'accepted-link-limit.tar');
await writeCraftedTar(archive, [
...Array.from({ length: 101 }, (_, index) =>
symlinkHeader(`link-${index}`, 'target'),
),
createTarFileHeader('target', 0),
]);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('more than 100 link entries');
});

it.runIf(process.platform !== 'win32')(
'rejects a symlink with an absolute target',
async () => {
await fs.symlink('/etc/passwd', path.join(root, 'absolute'));
const archive = path.join(root, 'absolute.tar');
await tar.c({ cwd: root, file: archive }, ['absolute']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
},
);

it.runIf(process.platform !== 'win32')(
'rejects a symlink with a Windows-absolute target',
async () => {
await fs.symlink('C:\\Windows\\system32', path.join(root, 'drive'));
const archive = path.join(root, 'drive.tar');
await tar.c({ cwd: root, file: archive }, ['drive']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
},
);

it.runIf(process.platform !== 'win32')(
'rejects a hard link even when it points inside the archive root',
async () => {
await fs.writeFile(path.join(root, 'original.txt'), 'y\n');
await fs.link(
path.join(root, 'original.txt'),
path.join(root, 'hard.txt'),
);
const archive = path.join(root, 'hard.tar');
await tar.c({ cwd: root, file: archive }, ['original.txt', 'hard.txt']);

await expect(
assertTarArchiveLinksAreSafe(archive, undefined, allowLinks),
).rejects.toThrow('unsupported link entry');
},
);

it.runIf(process.platform !== 'win32')(
'still rejects a contained symlink when the option is off',
async () => {
await fs.writeFile(path.join(root, 'CLAUDE.md'), '# guide\n');
await fs.symlink('CLAUDE.md', path.join(root, 'AGENTS.md'));
const archive = path.join(root, 'default.tar');
await tar.c({ cwd: root, file: archive }, ['CLAUDE.md', 'AGENTS.md']);

await expect(assertTarArchiveLinksAreSafe(archive)).rejects.toThrow(
'unsupported link entry',
);
},
);
});
});
Loading
Loading