fix: every composition file server refuses credential and tool-state files (#7889)

* wip: paused before review

* test: cover credential files on the preview routes and the deploy notice

* refactor: name the inspector's file lookup for what it serves

* fix(cli): a link to a private file outside the project keeps its own left-out reason

* fix: escape the upload notice and skip private files from old manifests
This commit is contained in:
Michael Wang
2026-11-16 01:42:08 +00:00
committed by GitHub
parent ed93a13125
commit 014326b40b
22 changed files with 456 additions and 93 deletions
@@ -12,8 +12,8 @@ import {
import { spawn } from "node:child_process";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { isCredentialOrToolStatePath } from "@hyperframes/core/safe-path";
import {
isCredentialOrToolStatePath,
isEnvOrGitPath,
isPrivateCompositionFile,
receivedFiles,
+1 -46
View File
@@ -15,7 +15,7 @@ import {
} from "@hyperframes/studio-server/outside-file";
import { isPrivateProjectFile, realFilePath } from "@hyperframes/studio-server/safe-path";
import { mkdirWithinProject } from "@hyperframes/core";
import { projectPathSegments } from "@hyperframes/core/safe-path";
import { isCredentialOrToolStatePath } from "@hyperframes/core/safe-path";
import { publishRegistryFile, registryRoot, registryTargetPath } from "../registry/publication.js";
export { isEnvOrGitPath, isPrivateOutsideFile, linksOutside };
@@ -203,51 +203,6 @@ export function receivedRecordStatus(
return { path: join(nearest.root, RECEIVED_RECORD), listed: records.flatMap(listedUnder) };
}
const CREDENTIAL_FILES = new Set([
".npmrc",
".yarnrc",
".yarnrc.yml",
".pypirc",
"pip.conf",
"pip.ini",
".netrc",
"_netrc",
".git-credentials",
".gitconfig",
".mcp.json",
]);
const CREDENTIAL_FOLDERS = new Set([
".ssh",
".aws",
".gnupg",
".docker",
".kube",
".azure",
".claude",
".codex",
".cursor",
".agents",
".gemini",
".vscode",
".idea",
]);
const CREDENTIAL_CONFIG_FOLDERS = new Set(["gcloud", "gh"]);
const KEY_FILE = /^(?:id_(?:rsa|dsa|ecdsa|ed25519).*|.*\.(?:pem|key|p12|pfx))$/;
export function isCredentialOrToolStatePath(relPath: string): boolean {
const segments = projectPathSegments(relPath);
const name = segments.at(-1) ?? "";
return (
CREDENTIAL_FILES.has(name) ||
KEY_FILE.test(name) ||
segments.some(
(segment, at) =>
CREDENTIAL_FOLDERS.has(segment) ||
(segment === ".config" && CREDENTIAL_CONFIG_FOLDERS.has(segments[at + 1] ?? "")),
)
);
}
const leavesProject = (path: string): boolean =>
isAbsolute(path) || path.split(/[\\/]/)[0] === "..";
+2 -2
View File
@@ -467,8 +467,8 @@ function referencedFileLeftOut(
entryPath: string,
absPath: string,
): LeftOutReason | null {
if (isPrivateCompositionFile(ctx.absProjectDir, absPath)) return "private";
if (linksToPrivateOutsideFile(ctx.absProjectDir, absPath)) return "blocklisted";
if (isPrivateCompositionFile(ctx.absProjectDir, absPath)) return "private";
if (ctx.received(entryPath) && linksOutside(ctx.absProjectDir, absPath)) return "received";
if (!loadableReference(ctx.absProjectDir, absPath)) return "private";
return null;
@@ -875,8 +875,8 @@ function walkedFileLeftOut(
absPath: string,
received: (path: string) => boolean,
): WalkedLeftOutReason | null {
if (isPrivateCompositionFile(absProjectDir, absPath)) return "private";
if (linksToPrivateOutsideFile(absProjectDir, absPath)) return "blocklisted";
if (isPrivateCompositionFile(absProjectDir, absPath)) return "private";
if (received(filePath) && linksOutside(absProjectDir, absPath)) return "received";
return null;
}
@@ -729,6 +729,28 @@ describe("serveStaticProjectHtml private project files", () => {
);
});
describe("serveStaticProjectHtml credential files", () => {
it.each([".npmrc", ".mcp.json", ".claude/x.json", ".aws/credentials", "id_ed25519", "cert.pem"])(
"answers %s with 404",
async (requestPath) => {
dir = mkdtempSync(join(tmpdir(), "hf-static-credentials-"));
for (const folder of [".claude", ".aws"]) mkdirSync(join(dir, folder));
for (const file of [".npmrc", ".mcp.json", ".claude/x.json", ".aws/credentials"]) {
writeFileSync(join(dir, file), "SECRET=1");
}
writeFileSync(join(dir, "id_ed25519"), "SECRET=1");
writeFileSync(join(dir, "cert.pem"), "SECRET=1");
writeFileSync(join(dir, "asset.txt"), "ok");
server = await serveStaticProjectHtml(dir, "<html></html>");
const res = await fetch(`${server.url}${requestPath}`);
expect(res.status).toBe(404);
expect(await res.text()).not.toContain("SECRET");
expect((await fetch(`${server.url}asset.txt`)).status).toBe(200);
},
);
});
describe("serveStaticProjectHtml page another site loads", () => {
const MARK = '<meta name="hyperframes-preview-for-another-site">';
const SANDBOX = "sandbox allow-scripts";