mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix: narrow the private-file rule for hidden files, build output and lint (#7990)
* fix: refuse framework build output and service-account files; lint skips private compositions Review follow-ups: - Hidden framework build-output folders (.next, .nuxt, .output, .svelte-kit, .vercel, .netlify, .wrangler, .astro, .turbo) are private whatever the file type, since their scripts can carry inlined server environment values. - credentials.json and common service-account key names are private. - Lint's compositions/ walk skips private files and folders, and an explicit lint entry that is a private file is refused. - New lint tests link .git/m.json, .mcp.json and a .hyperframes record as an import map; they fail when lint's private-file check is removed. * fix: a hidden file is private whatever its type; files in hidden folders keep the asset rule
This commit is contained in:
@@ -326,6 +326,15 @@ describe("isStudioPrivatePath", () => {
|
||||
"AuthKey_ABC.p8",
|
||||
"vault.kdbx",
|
||||
"putty.ppk",
|
||||
".next/server/app/page.js",
|
||||
"web/.svelte-kit/output/client/app.css",
|
||||
".vercel/output/static/logo.png",
|
||||
"credentials.json",
|
||||
"config/serviceAccountKey.json",
|
||||
".secrets.js",
|
||||
".eslintrc.cjs",
|
||||
"sub/.tokens.css",
|
||||
".cache/.session.webp",
|
||||
])("refuses %s", (path) => {
|
||||
expect(isStudioPrivatePath(path)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -1698,6 +1698,33 @@ describe("linked private project files", () => {
|
||||
expect(JSON.stringify(await lintProject(project))).not.toContain("TOP-SECRET-VALUE");
|
||||
});
|
||||
|
||||
// The kind check alone lets these through: they are JSON, as an import map is.
|
||||
it.each([".git/m.json", ".mcp.json", ".hyperframes/share.json"])(
|
||||
"never reads %s as an import map",
|
||||
async (path) => {
|
||||
const project = makeProject("");
|
||||
mkdirSync(dirname(join(project, path)), { recursive: true });
|
||||
writeFileSync(join(project, path), "TOP-SECRET-VALUE not json");
|
||||
writeFileSync(
|
||||
join(project, "index.html"),
|
||||
validHtml().replace("</body>", `<script type="importmap" src="${path}"></script></body>`),
|
||||
);
|
||||
expect(JSON.stringify(await lintProject(project))).not.toContain("TOP-SECRET-VALUE");
|
||||
},
|
||||
);
|
||||
|
||||
it("lints no composition in a hidden folder, and refuses a private entry", async () => {
|
||||
const project = makeProject(validHtml(), {
|
||||
".cache/stale.html": "<div>TOP-SECRET-VALUE</div>",
|
||||
});
|
||||
expect(
|
||||
JSON.stringify(await lintProject(project, undefined, {}, { includeUnmounted: true })),
|
||||
).not.toContain(".cache");
|
||||
await expect(
|
||||
lintProject(project, join(project, "compositions/.cache/stale.html")),
|
||||
).rejects.toThrow("private project file");
|
||||
});
|
||||
|
||||
it("reads a linked file only when it is the kind its link names", async () => {
|
||||
const project = makeProject("");
|
||||
writeFileSync(join(project, "notes.txt"), "TOP-SECRET-VALUE not json {#main{}");
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
} from "./hevcPreviewLint.js";
|
||||
import { lintHyperframeHtml } from "./hyperframeLinter.js";
|
||||
import { readLinkedProjectFile } from "./linkedFile.js";
|
||||
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/parsers/private-path";
|
||||
import { collectGoogleFontFamilies, extractFontFaceFamilies } from "./rules/fonts.js";
|
||||
import { lintProjectShaderScripts } from "./projectShaders.js";
|
||||
import type {
|
||||
@@ -341,6 +342,9 @@ export async function lintProject(
|
||||
if (entryFile && !isWithinProjectRoot(projectDir, indexPath)) {
|
||||
throw new Error(`Explicit lint entry is outside the project directory: ${entryFile}`);
|
||||
}
|
||||
if (entryFile && isPrivateFileUnder(projectDir, indexPath, isStudioPrivatePath)) {
|
||||
throw new Error(`Explicit lint entry is a private project file: ${entryFile}`);
|
||||
}
|
||||
const rootFile = relative(resolve(projectDir), indexPath).replace(/\\/g, "/") || "index.html";
|
||||
const rootCompSrcPath = rootFile === "index.html" ? undefined : rootFile;
|
||||
const results: ProjectLintResult["results"] = [];
|
||||
@@ -375,6 +379,7 @@ export async function lintProject(
|
||||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||||
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
|
||||
if (ignored.ignores(`compositions/${relPath}${entry.isDirectory() ? "/" : ""}`)) continue;
|
||||
if (isStudioPrivatePath(`compositions/${relPath}`)) continue;
|
||||
if (entry.isDirectory()) {
|
||||
// Registry components are source snippets, not independently mounted
|
||||
// sub-compositions. Linting every installed template here makes an
|
||||
|
||||
@@ -63,6 +63,10 @@ const CREDENTIAL_FILES = new Set([
|
||||
".git-credentials",
|
||||
".gitconfig",
|
||||
".mcp.json",
|
||||
"credentials.json",
|
||||
"serviceaccountkey.json",
|
||||
"service-account.json",
|
||||
"service_account.json",
|
||||
]);
|
||||
const CREDENTIAL_FOLDERS = new Set([
|
||||
".ssh",
|
||||
@@ -105,19 +109,33 @@ export function isStudioPrivatePath(relPath: string): boolean {
|
||||
if (isVcsOrSecretPath(relPath) || isCredentialOrToolStatePath(relPath)) return true;
|
||||
const segments = projectPathSegments(relPath);
|
||||
const inside = !isAbsolute(relPath) && !/^\.\.[. ]*$/.test(relPath.split(/[\\/]/, 1)[0] ?? "");
|
||||
const loadedType = LOADED_ASSET_TYPE.test(segments.at(-1) ?? "");
|
||||
const name = segments.at(-1) ?? "";
|
||||
const loadedType = !name.startsWith(".") && LOADED_ASSET_TYPE.test(name);
|
||||
return segments.some((segment, at) => {
|
||||
const atRoot = segments.slice(0, at).every((before) => before === "");
|
||||
if (segment === ".hyperframes")
|
||||
return !atRoot || !isStudioOwnFile(segments.slice(at).join("/"));
|
||||
if (BUILD_OUTPUT_FOLDERS.has(segment)) return inside;
|
||||
const mediaFolder = atRoot && segment === MEDIA_FOLDER;
|
||||
return inside && segment.startsWith(".") && !mediaFolder && !loadedType;
|
||||
});
|
||||
}
|
||||
|
||||
// A new tool keeps its token under a new hidden name, so a hidden file is private unless it is in the media folder or
|
||||
// is an asset a page loads. A path leaving the project (a linked frame cache) is judged elsewhere.
|
||||
// A new tool keeps its token under a new hidden name, so a hidden file is private, and a file in a hidden folder is
|
||||
// private unless it is in the media folder or is an asset a page loads. A path leaving the project is judged elsewhere.
|
||||
const MEDIA_FOLDER = ".media";
|
||||
// Framework build output: its scripts can carry server environment values inlined at build time.
|
||||
const BUILD_OUTPUT_FOLDERS = new Set([
|
||||
".next",
|
||||
".nuxt",
|
||||
".output",
|
||||
".svelte-kit",
|
||||
".vercel",
|
||||
".netlify",
|
||||
".wrangler",
|
||||
".astro",
|
||||
".turbo",
|
||||
]);
|
||||
const LOADED_ASSET_TYPE =
|
||||
/.\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|heic|heif|mp4|m4v|mov|webm|mkv|mxf|avi|mp3|wav|m4a|aac|ogg|oga|opus|flac|woff2?|ttf|otf|css|m?js|cjs)$/;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user