Skip to content

Write HTML. Render video. Built for agents.

fix(media-use): a credentials folder means no HeyGen credential, not a crash (#4995)

Miguel Ángel32d2bc6fe030
diff --git a/skills-manifest.json b/skills-manifest.json
index 339bfe34a8..0b2c8a84fe 100644
--- a/skills-manifest.json
+++ b/skills-manifest.json
@@ -54,7 +54,7 @@
"files": 1
},
"media-use": {
- "hash": "1e767e3b7e2992a2",
+ "hash": "5d688d039d31df92",
"files": 104
},
"motion-graphics": {
diff --git a/skills/media-use/audio/scripts/lib/heygen.mjs b/skills/media-use/audio/scripts/lib/heygen.mjs
index f1ec536f4a..8f98d99c7b 100644
--- a/skills/media-use/audio/scripts/lib/heygen.mjs
+++ b/skills/media-use/audio/scripts/lib/heygen.mjs
@@ -5,7 +5,7 @@ import { fetchMedia } from "../../../scripts/lib/media-fetch.mjs";
// credentials (oauth → Bearer, else api_key → X-Api-Key; $HEYGEN_CONFIG_DIR
// overrides the dir). Vendored so the skill ships standalone. Pure node.
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join, resolve } from "node:path";
@@ -63,8 +63,14 @@ export function heygenCredential() {
if (envKey) return { headers: { "X-Api-Key": envKey } };
const file = join(process.env.HEYGEN_CONFIG_DIR || join(homedir(), ".heygen"), "credentials");
- if (!existsSync(file)) return null;
- const raw = readFileSync(file, "utf8").trim();
+ // Callers only probe for a credential, so any path that cannot be read (missing, a folder, a locked ~/.heygen)
+ // is none. Read without checking first, so the file cannot change between a check and the read.
+ let raw;
+ try {
+ raw = readFileSync(file, "utf8").trim();
+ } catch {
+ return null;
+ }
if (!raw) return null;
if (!raw.startsWith("{")) return { headers: { "X-Api-Key": raw } };
diff --git a/skills/media-use/audio/scripts/lib/heygen.test.mjs b/skills/media-use/audio/scripts/lib/heygen.test.mjs
index 0098240c8e..9ee60ec7c2 100644
--- a/skills/media-use/audio/scripts/lib/heygen.test.mjs
+++ b/skills/media-use/audio/scripts/lib/heygen.test.mjs
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { heygenAuthHeaders, heygenAuthMethod, loadEnvFromDir } from "./heygen.mjs";
@@ -115,3 +115,29 @@ test("loadEnvFromDir skips a .env folder and loads the .env file above it", () =
rmSync(root, { recursive: true, force: true });
}
});
+
+test("heygenAuthMethod returns null when the credentials path is a folder", () => {
+ withCleanHeygenEnv(() => {
+ const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
+ try {
+ mkdirSync(join(dir, "credentials"));
+ process.env.HEYGEN_CONFIG_DIR = dir;
+ assert.equal(heygenAuthMethod(), null);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});
+
+test("heygenAuthMethod returns null when the credentials path is a symlink loop", () => {
+ withCleanHeygenEnv(() => {
+ const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
+ try {
+ symlinkSync(join(dir, "credentials"), join(dir, "credentials"));
+ process.env.HEYGEN_CONFIG_DIR = dir;
+ assert.equal(heygenAuthMethod(), null);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});