fix(build): make every dist file readable by other users (13-02)

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>
This commit is contained in:
DongHyeonka
2026-09-25 22:52:33 +09:00
co-authored by Claude Opus 5.5
parent b0f7944b41
commit 1a1cfe6605
3 changed files with 61 additions and 0 deletions
+5
View File
@@ -3,6 +3,7 @@ import { rm } from "node:fs/promises";
import process from "node:process";
import { INSTALLED_RUNTIME_CAPABILITIES } from "../src/features/installed-runtime-capabilities.ts";
import { makeDistFilesPublic } from "./lib/dist-permissions.ts";
/**
* §17.2.2. Deterministic two-pass build.
@@ -17,6 +18,7 @@ import { INSTALLED_RUNTIME_CAPABILITIES } from "../src/features/installed-runtim
* 5. scan app dist and generate the static asset source
* 6. ACTIVE only: Vite Service Worker build (emptyOutDir = false)
* 7. generate Release Manifest V2 and the build manifest
* 8. make every dist file readable by other users (13-02)
*
* Steps 5 and 6 are skipped for `REMOVE_REGISTRATION`, `PURGE_OWNED_RESOURCES`
* and `null`: those modes never run an active worker build.
@@ -68,3 +70,6 @@ if (buildsActiveWorker) {
// 6. release + build manifest
run("node", ["scripts/generate-build-manifest.ts"]);
// 8. publishable permissions: the validated writer creates 0600 files
await makeDistFilesPublic("dist");
+18
View File
@@ -0,0 +1,18 @@
import { chmod, readdir, stat } from "node:fs/promises";
import path from "node:path";
/**
* 13-02. dist is published as-is to a web server that may run as another OS
* user, so every file in it must be readable by others. The validated JSON
* writer creates files 0600 on purpose (evidence under artifacts/ stays
* private); the build adds read bits to what it publishes instead of loosening
* that writer.
*/
export async function makeDistFilesPublic(directory: string): Promise<void> {
for (const entry of await readdir(directory, { recursive: true, withFileTypes: true })) {
if (!entry.isFile()) continue;
const file = path.join(entry.parentPath, entry.name);
const { mode } = await stat(file);
if ((mode & 0o004) === 0) await chmod(file, (mode & 0o7777) | 0o444);
}
}