The validated JSON writer creates files 0600, so dist/config.json, release-manifest.json and runtime-config.schema.json shipped unreadable to a web server running as another user. The build now adds read bits to dist files; evidence under artifacts/ stays private. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { chmod, mkdir, mkdtemp, rm, stat, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import { makeDistFilesPublic } from "../../scripts/lib/dist-permissions.ts";
|
|
|
|
// 13-02. The validated JSON writer publishes with mode 0600, so dist/config.json
|
|
// and dist/release-manifest.json reached the release archive unreadable to a web
|
|
// server running as another user, and every boot failed with 403.
|
|
const roots: string[] = [];
|
|
afterEach(async () => {
|
|
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("dist file permissions", () => {
|
|
it("makes every dist file readable by other users and keeps other bits", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "dist-permissions-"));
|
|
roots.push(root);
|
|
await mkdir(path.join(root, ".vite"), { recursive: true });
|
|
const files = {
|
|
"config.json": 0o600,
|
|
".vite/manifest.json": 0o600,
|
|
"index.html": 0o664,
|
|
} as const;
|
|
for (const [file, mode] of Object.entries(files)) {
|
|
await writeFile(path.join(root, file), "{}");
|
|
await chmod(path.join(root, file), mode);
|
|
}
|
|
|
|
await makeDistFilesPublic(root);
|
|
|
|
expect((await stat(path.join(root, "config.json"))).mode & 0o777).toBe(0o644);
|
|
expect((await stat(path.join(root, ".vite/manifest.json"))).mode & 0o777).toBe(0o644);
|
|
expect((await stat(path.join(root, "index.html"))).mode & 0o777).toBe(0o664);
|
|
});
|
|
});
|