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: keep file and platform credential paths inside the Host state root

fetw696167659c7c
diff --git a/packages/credential-store-file/src/activation.ts b/packages/credential-store-file/src/activation.ts
index e6e532e8..f72c0335 100644
--- a/packages/credential-store-file/src/activation.ts
+++ b/packages/credential-store-file/src/activation.ts
@@ -1,10 +1,10 @@
-import { join, resolve } from "node:path";
import {
createRuntimeCredentialStoreAdapterFacet,
runtimeConfigExact,
runtimeConfigObject,
runtimeConfigString,
} from "@hypit/runtime-kit";
+import { resolveCredentialDirectory } from "./paths.js";
import { FileCredentialStore } from "./store.js";
const fileCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
@@ -17,8 +17,9 @@ const fileCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
open(context) {
const config = runtimeConfigObject(context.config, "file CredentialStore");
const path = runtimeConfigString(config.path, "file credential path");
- return { value: new FileCredentialStore(path === undefined
- ? join(context.hostStateRoot, "credentials") : resolve(context.hostStateRoot, path)) };
+ return { value: new FileCredentialStore(
+ resolveCredentialDirectory(context.hostStateRoot, path, "file CredentialStore"),
+ ) };
},
});
diff --git a/packages/credential-store-file/src/index.ts b/packages/credential-store-file/src/index.ts
index 481b1203..97d1909d 100644
--- a/packages/credential-store-file/src/index.ts
+++ b/packages/credential-store-file/src/index.ts
@@ -1 +1,2 @@
export { FileCredentialStore } from "./store.js";
+export { resolveCredentialDirectory } from "./paths.js";
diff --git a/packages/credential-store-file/src/paths.ts b/packages/credential-store-file/src/paths.ts
new file mode 100644
index 00000000..3a8905e5
--- /dev/null
+++ b/packages/credential-store-file/src/paths.ts
@@ -0,0 +1,16 @@
+import { isAbsolute, join, relative, resolve, sep } from "node:path";
+
+/** Profile `path` is Host-state-relative; it must not write secrets outside that root. */
+export function resolveCredentialDirectory(
+ hostStateRoot: string,
+ path: string | undefined,
+ label: string,
+): string {
+ const root = resolve(hostStateRoot);
+ const directory = path === undefined ? join(root, "credentials") : resolve(root, path);
+ const relation = relative(root, directory);
+ if (relation === ".." || relation.startsWith(`..${sep}`) || isAbsolute(relation)) {
+ throw new Error(`${label} path must stay inside the Host state root`);
+ }
+ return directory;
+}
diff --git a/packages/credential-store-file/test/paths.test.ts b/packages/credential-store-file/test/paths.test.ts
new file mode 100644
index 00000000..8f10bd00
--- /dev/null
+++ b/packages/credential-store-file/test/paths.test.ts
@@ -0,0 +1,25 @@
+import assert from "node:assert/strict";
+import { mkdtemp, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+import test from "node:test";
+
+import { resolveCredentialDirectory } from "../src/paths.js";
+
+test("credential directories stay inside the Host state root", async () => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-credential-root-"));
+ try {
+ assert.equal(resolveCredentialDirectory(root, undefined, "file CredentialStore"), join(root, "credentials"));
+ assert.equal(resolveCredentialDirectory(root, "nested/keys", "file CredentialStore"), resolve(root, "nested/keys"));
+ assert.throws(
+ () => resolveCredentialDirectory(root, "..", "file CredentialStore"),
+ /file CredentialStore path must stay inside the Host state root/u,
+ );
+ assert.throws(
+ () => resolveCredentialDirectory(root, join("foo", "..", "..", "outside"), "file CredentialStore"),
+ /file CredentialStore path must stay inside the Host state root/u,
+ );
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/packages/credential-store-platform/src/activation.ts b/packages/credential-store-platform/src/activation.ts
index e97bcfa3..3539fdd1 100644
--- a/packages/credential-store-platform/src/activation.ts
+++ b/packages/credential-store-platform/src/activation.ts
@@ -1,10 +1,10 @@
-import { join, resolve } from "node:path";
import {
createRuntimeCredentialStoreAdapterFacet,
runtimeConfigExact,
runtimeConfigObject,
runtimeConfigString,
} from "@hypit/runtime-kit";
+import { resolveCredentialDirectory } from "@hypit/credential-store-file";
import { PlatformCredentialStore } from "./store.js";
const platformCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
@@ -23,9 +23,7 @@ const platformCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet(
value: new PlatformCredentialStore({
// Linux uses the same directory the file Store uses by default, so a Profile
// that switches between them on Linux finds the credential it stored.
- directory: path === undefined
- ? join(context.hostStateRoot, "credentials")
- : resolve(context.hostStateRoot, path),
+ directory: resolveCredentialDirectory(context.hostStateRoot, path, "platform CredentialStore"),
...(service === undefined ? {} : { service }),
}),
};