From c625ae181d584e35700b98e17481192d70ab7a51 Mon Sep 17 00:00:00 2001 From: Roger Chappel Date: Tue, 24 Nov 2026 23:47:09 +1000 Subject: [PATCH] fix: reject package entry traversal segments --- scripts/check-package-content.js | 2 +- test/package-content.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/check-package-content.js b/scripts/check-package-content.js index 21d07b5..0690c9c 100644 --- a/scripts/check-package-content.js +++ b/scripts/check-package-content.js @@ -19,7 +19,7 @@ function addEntry(value, label) { throw new Error(`Invalid package ${label} entry: ${JSON.stringify(value)}`); } const path = normalize(value.replace(/^\.\//, '')); - if (path === '..' || path.startsWith(`..${join('', '/')}`) || path.startsWith('/')) { + if (path === '..' || path.startsWith(`..${join('', '/')}`) || path.startsWith('/') || path.split(/[\\/]+/).includes('..')) { throw new Error(`Package ${label} entry must stay inside the package: ${value}`); } required.add(path); diff --git a/test/package-content.test.js b/test/package-content.test.js index 7776450..ab84603 100644 --- a/test/package-content.test.js +++ b/test/package-content.test.js @@ -47,3 +47,10 @@ test('package content checker rejects package entry paths outside the package', assert.notEqual(result.status, 0); assert.match(result.stderr, /must stay inside the package/); }); + +test('package content checker rejects internal traversal after normalization', (t) => { + const pkg = { ...packageJson, bin: { atomcommit: 'src/../../outside.js' }, main: undefined, exports: {} }; + const result = runChecker(t, pkg); + assert.notEqual(result.status, 0); + assert.match(result.stderr, /must stay inside the package/); +});