Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions browser-companion/scripts/archive-tool.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const fs=require("node:fs");
const path=require("node:path");

// On Windows, PowerShell/nvm may omit System32 from PATH. Never fall back
// to an unrelated tar.exe when producing or verifying release artifacts.
function archiveTool({platform=process.platform,systemRoot=process.env.SystemRoot,exists=fs.existsSync}={}) {
if(platform!=="win32")return "tar";
const root=systemRoot||"C:\\Windows";
if(!/^[A-Za-z]:[\\/]/.test(root) || root.split(/[\\/]/).includes("..") || root.includes("\0"))
throw new Error("Windows system directory must be a local absolute drive path without traversal");
const executable=path.win32.join(root,"System32","tar.exe");
if(!exists(executable))throw new Error("Windows System32 tar.exe is unavailable");
return executable;
}
module.exports={archiveTool};
5 changes: 3 additions & 2 deletions browser-companion/scripts/package.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { spawnSync } = require("node:child_process");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { archiveTool } = require("./archive-tool.cjs");
const { installChrome } = require("./install-chrome.cjs");
const { stageWindowsApplication } = require("./package-stage.cjs");

Expand Down Expand Up @@ -182,9 +183,9 @@ try {
fs.rmSync(artifact, { force:true });
if (targetPlatform === "win32") {
const zipOptions=process.env.CODEXIFY_BROWSER_FAST_LOCAL_PACKAGE==="1"?["--options","zip:compression-level=1"]:[];
runChecked("tar", ["-a", "-cf", artifact,...zipOptions, "-C", packageStage, packageRootName]);
runChecked(archiveTool(), ["-a", "-cf", artifact,...zipOptions, "-C", packageStage, packageRootName]);
} else {
runChecked("tar", ["-czf", artifact, "-C", packageStage, packageRootName], {
runChecked(archiveTool(), ["-czf", artifact, "-C", packageStage, packageRootName], {
env:{ ...process.env, COPYFILE_DISABLE:"1" },
});
}
Expand Down
3 changes: 2 additions & 1 deletion browser-companion/scripts/smoke-package.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { spawnSync } = require("node:child_process");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { archiveTool } = require("./archive-tool.cjs");

const root = path.resolve(__dirname, "..");
const repositoryRoot = path.resolve(root, "..");
Expand Down Expand Up @@ -52,7 +53,7 @@ const descriptor = path.join(scratch, "browser", "descriptor.json");
try {
const extract = path.join(scratch, "extract");
fs.mkdirSync(extract);
run("tar", process.platform === "win32"
run(archiveTool(), process.platform === "win32"
? ["-xf", artifact, "-C", extract]
: ["-xzf", artifact, "-C", extract], { timeout:PACKAGE_EXTRACTION_TIMEOUT_MS });
const packageRoot = path.join(extract, packageRootName);
Expand Down
30 changes: 30 additions & 0 deletions browser-companion/tests/archive-tool.node.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
const test=require("node:test");
const assert=require("node:assert/strict");
const path=require("node:path");
const {archiveTool}=require("../scripts/archive-tool.cjs");

test("non-Windows packaging continues to use PATH tar",()=>{
assert.equal(archiveTool({platform:"linux",exists:()=>{throw new Error("must not probe")}}),"tar");
});
test("Windows resolves the OS-owned tar.exe even if PATH omits System32",()=>{
let checked;
const expected=path.win32.join("C:\\Windows","System32","tar.exe");
assert.equal(archiveTool({platform:"win32",systemRoot:"C:\\Windows",exists:p=>{checked=p;return true}}),expected);
assert.equal(checked,expected);
});
test("Windows system root can contain spaces",()=>{
const expected=path.win32.join("C:\\Windows Dir","System32","tar.exe");
assert.equal(archiveTool({platform:"win32",systemRoot:"C:\\Windows Dir",exists:()=>true}),expected);
});
test("Windows rejects a missing native tar.exe instead of searching arbitrary PATH",()=>{
assert.throws(()=>archiveTool({platform:"win32",systemRoot:"C:\\Windows",exists:()=>false}),/unavailable/);
});
test("Windows rejects a relative system directory",()=>{
assert.throws(()=>archiveTool({platform:"win32",systemRoot:"relative",exists:()=>true}),/local absolute drive/);
});
test("Windows rejects remote UNC roots and traversal in SystemRoot",()=>{
for(const root of ["\\\\server\\share", "C:\\Windows\\..\\Temp", "\\Windows"]){
assert.throws(()=>archiveTool({platform:"win32",systemRoot:root,exists:()=>true}),/local absolute drive/);
}
});
Loading