mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 18:54:58 +00:00
fix(security): harden archive extraction (#16203)
* fix(browser): confine upload paths for file chooser * fix(browser): sanitize suggested download filenames * chore(lint): avoid control regex in download sanitizer * test(browser): cover absolute escape paths * docs(browser): update upload example path * refactor(browser): centralize upload path confinement * fix(infra): harden tmp dir selection * fix(security): harden archive extraction * fix(infra): harden tar extraction filter
This commit is contained in:
committed by
GitHub
parent
9a134c8a10
commit
3aa94afcfd
@@ -1,6 +1,11 @@
|
||||
import JSZip from "jszip";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import * as tar from "tar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ReleaseAsset } from "./signal-install.js";
|
||||
import { looksLikeArchive, pickAsset } from "./signal-install.js";
|
||||
import { extractSignalCliArchive, looksLikeArchive, pickAsset } from "./signal-install.js";
|
||||
|
||||
// Realistic asset list modelled after an actual signal-cli GitHub release.
|
||||
const SAMPLE_ASSETS: ReleaseAsset[] = [
|
||||
@@ -126,3 +131,44 @@ describe("pickAsset", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractSignalCliArchive", () => {
|
||||
it("rejects zip slip path traversal", async () => {
|
||||
const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-signal-install-"));
|
||||
try {
|
||||
const archivePath = path.join(workDir, "bad.zip");
|
||||
const extractDir = path.join(workDir, "extract");
|
||||
await fs.mkdir(extractDir, { recursive: true });
|
||||
|
||||
const zip = new JSZip();
|
||||
zip.file("../pwned.txt", "pwnd");
|
||||
await fs.writeFile(archivePath, await zip.generateAsync({ type: "nodebuffer" }));
|
||||
|
||||
await expect(extractSignalCliArchive(archivePath, extractDir, 5_000)).rejects.toThrow(
|
||||
/(escapes destination|absolute)/i,
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(workDir, { recursive: true, force: true }).catch(() => undefined);
|
||||
}
|
||||
});
|
||||
|
||||
it("extracts tar.gz archives", async () => {
|
||||
const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-signal-install-"));
|
||||
try {
|
||||
const archivePath = path.join(workDir, "ok.tgz");
|
||||
const extractDir = path.join(workDir, "extract");
|
||||
const rootDir = path.join(workDir, "root");
|
||||
await fs.mkdir(rootDir, { recursive: true });
|
||||
await fs.writeFile(path.join(rootDir, "signal-cli"), "bin", "utf-8");
|
||||
await tar.c({ cwd: workDir, file: archivePath, gzip: true }, ["root"]);
|
||||
|
||||
await fs.mkdir(extractDir, { recursive: true });
|
||||
await extractSignalCliArchive(archivePath, extractDir, 5_000);
|
||||
|
||||
const extracted = await fs.readFile(path.join(extractDir, "root", "signal-cli"), "utf-8");
|
||||
expect(extracted).toBe("bin");
|
||||
} finally {
|
||||
await fs.rm(workDir, { recursive: true, force: true }).catch(() => undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user