mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
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:
@@ -24,6 +24,11 @@ beforeAll(() => {
|
||||
writeFileSync(join(site, "index.html"), "<h1>home</h1>");
|
||||
writeFileSync(join(site, "pages", "about page.html"), "<h1>about</h1>");
|
||||
writeFileSync(join(site, "logo.png"), "png-bytes");
|
||||
for (const folder of [".git", ".hyperframes", ".aws"]) mkdirSync(join(site, folder));
|
||||
for (const file of [".env", ".env.local", ".git/config", ".hyperframes/x.json", ".npmrc"]) {
|
||||
writeFileSync(join(site, file), "SECRET=1");
|
||||
}
|
||||
writeFileSync(join(site, ".aws", "credentials"), "SECRET=1");
|
||||
writeFileSync(join(base, "secret.txt"), "outside the root");
|
||||
writeFileSync(join(base, "outside.html"), "<h1>outside</h1>");
|
||||
if (process.platform !== "win32") {
|
||||
@@ -98,6 +103,24 @@ describe("startLocalPageServer", () => {
|
||||
expect(await response.text()).toBe("");
|
||||
});
|
||||
|
||||
it.each([
|
||||
"/.env",
|
||||
"/.ENV",
|
||||
"/.env.local",
|
||||
"/.git/config",
|
||||
"/%2egit/config",
|
||||
"/.hyperframes/x.json",
|
||||
"/.npmrc",
|
||||
"/.aws/credentials",
|
||||
])("keeps the private file %s from the page and the capture fetchers", async (path) => {
|
||||
const response = await fetch(`${server.origin}${path}`);
|
||||
expect(response.status).toBe(404);
|
||||
expect(await response.text()).toBe("");
|
||||
const local = await safeFetch(`${server.origin}${path}`);
|
||||
expect(local?.status).toBe(404);
|
||||
expect(await local?.text()).not.toContain("SECRET");
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")("refuses a symlink that leaves the root", async () => {
|
||||
expect((await fetch(`${server.origin}/link.txt`)).status).toBe(404);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep }
|
||||
import { Readable } from "node:stream";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { listenOnBrowserSafePort } from "@hyperframes/engine";
|
||||
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
||||
|
||||
export interface LocalCaptureTarget {
|
||||
/** Real path of the directory the page may read from. */
|
||||
@@ -127,6 +128,7 @@ async function servedFile(root: string, pathname: string): Promise<string | null
|
||||
if (decoded.includes("\0")) return null;
|
||||
const candidate = resolve(root, `.${decoded}`);
|
||||
if (!isInside(root, candidate)) return null;
|
||||
if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) return null;
|
||||
try {
|
||||
// Symlinks are followed, so the containment check must run on the real path.
|
||||
const real = await realpath(candidate);
|
||||
@@ -146,7 +148,7 @@ function end(response: ServerResponse, status: number): void {
|
||||
response.end();
|
||||
}
|
||||
|
||||
/** Serves only regular files whose real path lies inside `target.root`, on a loopback port. */
|
||||
/** Serves only regular, non-private files whose real path lies inside `target.root`, on a loopback port. */
|
||||
export async function startLocalPageServer(target: LocalCaptureTarget): Promise<LocalPageServer> {
|
||||
const sockets = new Set<Socket>();
|
||||
const server = createServer((request, response) => {
|
||||
|
||||
@@ -512,6 +512,7 @@ async function runSites(args: Record<string, unknown>): Promise<void> {
|
||||
projectDir: resolve(projectDir),
|
||||
bucketName: state.bucketName,
|
||||
siteId: args["site-id"] as string | undefined,
|
||||
onNotice: (message) => console.error(message),
|
||||
});
|
||||
if (args.json) {
|
||||
console.log(JSON.stringify(handle, null, 2));
|
||||
@@ -693,6 +694,7 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
|
||||
projectDir: resolve(projectDir),
|
||||
bucketName: state.bucketName,
|
||||
siteId: args["site-id"] as string | undefined,
|
||||
onNotice: (message) => console.error(message),
|
||||
});
|
||||
|
||||
const results: Array<{ outputKey: string; executionName?: string; error?: string }> = [];
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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] === "..";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user