Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: admit in-root paths whose basename starts with ..

fetwa56576a49ebc
diff --git a/packages/cli/src/output.ts b/packages/cli/src/output.ts
index 4442d7cf..d7ff0362 100644
--- a/packages/cli/src/output.ts
+++ b/packages/cli/src/output.ts
@@ -1,4 +1,4 @@
-import { relative, resolve } from "node:path";
+import { relative, resolve, sep } from "node:path";
import type { CanonicalValue } from "@hypit/protocol";
@@ -279,7 +279,7 @@ function glyph(io: CliIo, unicode: string, ascii: string): string {
function shortPath(path: string): string {
const absolute = resolve(path);
const local = relative(process.cwd(), absolute);
- return local.length > 0 && !local.startsWith("..") ? local : absolute;
+ return local.length > 0 && local !== ".." && !local.startsWith(`..${sep}`) ? local : absolute;
}
function facts(rows: readonly (readonly [string, string])[], colors: Palette): string[] {
diff --git a/packages/cli/src/source-discovery.ts b/packages/cli/src/source-discovery.ts
index 3063e195..17e65e8d 100644
--- a/packages/cli/src/source-discovery.ts
+++ b/packages/cli/src/source-discovery.ts
@@ -1,5 +1,5 @@
import { readFile, realpath } from "node:fs/promises";
-import { dirname, isAbsolute, relative, resolve } from "node:path";
+import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
import { authorFrontendsFromHostFacets, prepareAuthorSource } from "@hypit/elaborator";
import type { AuthorFrontend } from "@hypit/elaborator";
@@ -12,7 +12,7 @@ import { parseSourceHeader, sourceFrontendPackageAbi } from "@hypit/source";
function isWithin(root: string, path: string): boolean {
const relation = relative(root, path);
- return relation === "" || (!relation.startsWith("..") && !isAbsolute(relation));
+ return relation === "" || (relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation));
}
function selectedPackage(request: string): string {
diff --git a/packages/cli/test/source-discovery.test.ts b/packages/cli/test/source-discovery.test.ts
index 8cbe9c27..2082d63d 100644
--- a/packages/cli/test/source-discovery.test.ts
+++ b/packages/cli/test/source-discovery.test.ts
@@ -83,3 +83,17 @@ test("third-party Frontends discover same-named ABI requirements through physica
await rm(root, { recursive: true, force: true });
}
});
+
+test("an in-root Source whose basename starts with .. is still inside the workspace", async () => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-cli-dotdot-name-"));
+ try {
+ const source = join(root, "..keep.svrun");
+ await writeFile(source, `<?svml using="@logical/run@1"?>\nrun`, "utf8");
+ const discovered = await discoverSourcePackages(source, { workspaceRoot: root, packages: [] });
+ assert.deepEqual(discovered.logical, [
+ { abi: sourceFrontendPackageAbi, name: "@logical/run@1" },
+ ]);
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/packages/runtime-local/src/runtime.ts b/packages/runtime-local/src/runtime.ts
index 4d003261..2a797562 100644
--- a/packages/runtime-local/src/runtime.ts
+++ b/packages/runtime-local/src/runtime.ts
@@ -41,7 +41,7 @@ function nonNegativeInteger(value: number, subject: string): number {
function projectPath(root: string, path: string): string {
const absolute = isAbsolute(path) ? resolve(path) : resolve(root, path);
const relation = relative(resolve(root), absolute);
- assert(relation === "" || (!relation.startsWith("..") && !isAbsolute(relation)),
+ assert(relation === "" || (relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation)),
`Build Result source ${path} is outside project ${resolve(root)}`);
return (relation || ".").split(sep).join("/");
}
diff --git a/packages/studio/src/server.ts b/packages/studio/src/server.ts
index e84bfbd5..70936748 100644
--- a/packages/studio/src/server.ts
+++ b/packages/studio/src/server.ts
@@ -2,7 +2,7 @@ import { watch } from "node:fs";
import type { FSWatcher } from "node:fs";
import { existsSync } from "node:fs";
import { readFile } from "node:fs/promises";
-import { dirname, isAbsolute, relative, resolve } from "node:path";
+import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
@@ -207,7 +207,7 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {
if (isAbsolute(patch.path)) throw new Error("Studio patches must use workspace-relative paths.");
const absolute = resolve(options.workspaceRoot, patch.path);
const rel = relative(options.workspaceRoot, absolute);
- if (rel.startsWith("..") || isAbsolute(rel) || !allowedSourceFiles.has(absolute)) {
+ if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel) || !allowedSourceFiles.has(absolute)) {
throw new Error(`Studio cannot write source file ${patch.path}.`);
}
if (!Number.isInteger(patch.range.start) || !Number.isInteger(patch.range.end)
diff --git a/packages/workspace-fs-node/src/workspace.ts b/packages/workspace-fs-node/src/workspace.ts
index 66ac75b0..67757f0b 100644
--- a/packages/workspace-fs-node/src/workspace.ts
+++ b/packages/workspace-fs-node/src/workspace.ts
@@ -2,7 +2,7 @@ import { pathToFileURL } from "node:url";
import { randomUUID } from "node:crypto";
import { createReadStream } from "node:fs";
import { readFile, realpath, stat } from "node:fs/promises";
-import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
+import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
import type {
Awaitable,
@@ -20,7 +20,7 @@ import type { BlobRef } from "@hypit/protocol";
function isWithin(root: string, path: string): boolean {
const relation = relative(root, path);
- return relation === "" || (!relation.startsWith("..") && !isAbsolute(relation));
+ return relation === "" || (relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation));
}
export type NodeFilesystemExternalSource = {
diff --git a/packages/workspace-fs-node/test/workspace.test.ts b/packages/workspace-fs-node/test/workspace.test.ts
new file mode 100644
index 00000000..ebe5cbbf
--- /dev/null
+++ b/packages/workspace-fs-node/test/workspace.test.ts
@@ -0,0 +1,27 @@
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+
+import { WorkspaceError } from "@hypit/workspace";
+import { NodeFilesystemWorkspace } from "../src/index.js";
+
+test("an in-root Source whose basename starts with .. is admitted", async () => {
+ const parent = await mkdtemp(join(tmpdir(), "hypit-workspace-dotdot-name-"));
+ const root = join(parent, "project");
+ try {
+ await mkdir(root);
+ const entryPath = join(root, "..keep.svml");
+ await writeFile(entryPath, "inside", "utf8");
+ await writeFile(join(parent, "outside.svs"), "outside", "utf8");
+ const session = await new NodeFilesystemWorkspace({ root }).open(entryPath);
+ assert.equal(session.entry.text, "inside");
+ await assert.rejects(
+ async () => await session.resolveSource(session.entry, { from: "../outside.svs", alias: "escaped" }),
+ (error: unknown) => error instanceof WorkspaceError && error.code === "SOURCE_OUTSIDE_ROOT",
+ );
+ } finally {
+ await rm(parent, { recursive: true, force: true });
+ }
+});