diff --git a/packages/core/src/safePath.test.ts b/packages/core/src/safePath.test.ts index 19b62bc4f5..a5ca9bd866 100644 --- a/packages/core/src/safePath.test.ts +++ b/packages/core/src/safePath.test.ts @@ -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); }); diff --git a/packages/lint/src/project.test.ts b/packages/lint/src/project.test.ts index 529a16474c..c87363adf2 100644 --- a/packages/lint/src/project.test.ts +++ b/packages/lint/src/project.test.ts @@ -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("", ``), + ); + 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": "
TOP-SECRET-VALUE
", + }); + 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{}"); diff --git a/packages/lint/src/project.ts b/packages/lint/src/project.ts index 64090969c5..06ad283b66 100644 --- a/packages/lint/src/project.ts +++ b/packages/lint/src/project.ts @@ -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 diff --git a/packages/parsers/src/privatePath.ts b/packages/parsers/src/privatePath.ts index 9711b7b6a5..c70c049417 100644 --- a/packages/parsers/src/privatePath.ts +++ b/packages/parsers/src/privatePath.ts @@ -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)$/;