mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(docs): escape catalog preview values and the install command's --vars argument The catalog preview embeds variable values as JSON that cannot close a script element or attribute, accepts value messages only from the page that embeds it, and reads only declared ids with primitive values from the link. The install command shell-quotes its --vars JSON and keeps only variable-id keys with primitive values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(core): fold CSS line endings before decoding escapes in the SVG sanitizer A browser folds CR LF, CR and form feed into one newline before it reads CSS escapes, so the whitespace after a hex escape can be a CR LF pair. The sanitizer now does the same, so an escaped function name split by a line ending is checked under its real name. The media-use bundle is regenerated from the source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(lint): match template ids and CSS rules in linear time A getElementById template literal is matched against document ids with an in-order indexOf scan instead of a regex of joined wildcards, so the time no longer grows with the number of placeholders. The CSS rule scanners only start a match at the beginning of a brace-free run, which finds the same rules without rescanning long brace-less text. Lint results on every HTML file in the repository are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(parsers): keep GSAP writer output inside its script element String literals and quoted keys the GSAP writers emit now encode a script closer or comment opener as \u003c, so a value can no longer end the inline script that holds the timeline. Strings without those sequences are written exactly as before. The writers also refuse a tween method outside set, to, from and fromTo, and a motion path whose coordinates or curviness are not numbers, since both are emitted as code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scripts): confine registry asset hosting to files inside the item The asset hosting script now refuses a manifest path that leaves the item directory or reaches its file through a symlink, before anything is read, staged, uploaded or removed. A repository test fails when the registry tracks a symlink or a manifest path that leaves its item. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(registry): pin the map blocks' d3 and atlas files to exact versions The five map blocks load d3 7.9.2, the build the d3@7 range serves today, with a subresource integrity hash, and fetch us-atlas 3.0.1 and world-atlas 2.0.2, the files their ranges serve today. The bytes are unchanged, so the blocks render the same. A repository test fails when a registry item names an npm CDN package by range, tag or no version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(registry): pin map blocks to d3 7.9.0 7.9.0 has been the stable release since 2024; 7.9.1 and 7.9.2 were published days ago. Pin the long-standing version, with its subresource integrity hash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(registry): keep the map block PR source-only and formatted Restore the generated catalog pages and payloads, which the catalog publish job regenerates from the item sources. Name the us-atlas URL in us-map-flow so the call fits on one line and formatting is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scripts): check registry asset containment with one prefix test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(lint): scan simple CSS rules in linear time The two CSS-rule scans in the gsap rules took a body that could cross '{', so a closed style of many '{' with no '}' rescanned to its end from every brace. A scanner now returns the same selector and body pairs and remembers the next '}', so each scan is linear. Findings are identical on every tracked HTML file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(core): label the form-feed sanitizer case as a guard Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
134 lines
5.7 KiB
TypeScript
134 lines
5.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import fs from "node:fs";
|
|
import { syncBuiltinESMExports } from "node:module";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
import { test } from "node:test";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
const repoRoot = resolve(import.meta.dirname, "..");
|
|
|
|
async function fixture() {
|
|
const root = fs.realpathSync(fs.mkdtempSync(join(tmpdir(), "hf-host-assets-")));
|
|
const item = join(root, "registry/blocks/test-item");
|
|
fs.mkdirSync(item, { recursive: true });
|
|
fs.mkdirSync(join(root, "scripts"));
|
|
for (const name of ["host-registry-assets.ts", "entrypoint.ts"]) {
|
|
fs.copyFileSync(join(repoRoot, "scripts", name), join(root, "scripts", name));
|
|
}
|
|
for (const name of ["packages", "node_modules"]) {
|
|
fs.symlinkSync(join(repoRoot, name), join(root, name), "junction");
|
|
}
|
|
const source = join(item, "asset.png");
|
|
const manifestPath = join(item, "registry-item.json");
|
|
const bytes = Buffer.from("original asset bytes");
|
|
fs.writeFileSync(source, bytes);
|
|
const manifest = JSON.stringify({ name: "test-item", files: [{ path: "asset.png" }] });
|
|
fs.writeFileSync(manifestPath, manifest);
|
|
const { main } = await import(pathToFileURL(join(root, "scripts/host-registry-assets.ts")).href);
|
|
return { root, source, manifestPath, manifest, bytes, main };
|
|
}
|
|
|
|
test("staged bytes match their key, dry-run is unchanged, and no-upload preserves sources", async () => {
|
|
const f = await fixture();
|
|
try {
|
|
await f.main(["test-item", "--dry-run"]);
|
|
assert.equal(fs.readFileSync(f.manifestPath, "utf8"), f.manifest);
|
|
assert.equal(fs.existsSync(join(f.root, ".registry-assets-staging")), false);
|
|
await f.main(["test-item", "--no-upload"]);
|
|
const key = `${createHash("sha256").update(f.bytes).digest("hex").slice(0, 16)}.png`;
|
|
assert.deepEqual(fs.readFileSync(join(f.root, ".registry-assets-staging", key)), f.bytes);
|
|
assert.deepEqual(fs.readFileSync(f.source), f.bytes);
|
|
const manifest = JSON.parse(fs.readFileSync(f.manifestPath, "utf8"));
|
|
assert.equal(
|
|
manifest.files[0].url,
|
|
`https://static.heygen.ai/hyperframes-oss/registry-assets/${key}`,
|
|
);
|
|
} finally {
|
|
fs.rmSync(f.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("source replacement between planning and staging aborts before manifest publication", async (t) => {
|
|
const f = await fixture();
|
|
const copy = fs.copyFileSync;
|
|
t.mock.method(fs, "copyFileSync", (...args: Parameters<typeof copy>) => {
|
|
if (args[0] === f.source) fs.writeFileSync(f.source, "replacement bytes");
|
|
return copy(...args);
|
|
});
|
|
syncBuiltinESMExports();
|
|
try {
|
|
await assert.rejects(f.main(["test-item", "--no-upload"]), /Asset changed while staging/);
|
|
assert.equal(fs.readFileSync(f.manifestPath, "utf8"), f.manifest);
|
|
assert.equal(fs.readFileSync(f.source, "utf8"), "replacement bytes");
|
|
assert.deepEqual(fs.readdirSync(join(f.root, ".registry-assets-staging")), []);
|
|
} finally {
|
|
t.mock.restoreAll();
|
|
syncBuiltinESMExports();
|
|
fs.rmSync(f.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("a manifest path outside the item is refused before anything is staged or removed", async () => {
|
|
const f = await fixture();
|
|
try {
|
|
const outside = join(f.root, "registry/blocks/secret.png");
|
|
fs.writeFileSync(outside, "outside bytes");
|
|
fs.writeFileSync(
|
|
f.manifestPath,
|
|
JSON.stringify({ name: "test-item", files: [{ path: "../secret.png" }] }),
|
|
);
|
|
await assert.rejects(f.main(["test-item", "--no-upload"]), /outside the item/);
|
|
assert.equal(fs.readFileSync(outside, "utf8"), "outside bytes");
|
|
assert.equal(fs.existsSync(join(f.root, ".registry-assets-staging")), false);
|
|
} finally {
|
|
fs.rmSync(f.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("an asset that is a symlink is refused before its target is read", async () => {
|
|
const f = await fixture();
|
|
try {
|
|
const outside = join(f.root, "secret.txt");
|
|
fs.writeFileSync(outside, "outside bytes");
|
|
fs.rmSync(f.source);
|
|
fs.symlinkSync(outside, f.source);
|
|
const manifest = fs.readFileSync(f.manifestPath, "utf8");
|
|
await assert.rejects(f.main(["test-item", "--no-upload"]), /symlink/);
|
|
assert.equal(fs.readFileSync(f.manifestPath, "utf8"), manifest);
|
|
assert.equal(fs.readFileSync(outside, "utf8"), "outside bytes");
|
|
assert.equal(fs.existsSync(join(f.root, ".registry-assets-staging")), false);
|
|
} finally {
|
|
fs.rmSync(f.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("the registry tracks no symlinks and every manifest path stays inside its item", () => {
|
|
const listing = execFileSync("git", ["ls-files", "-s", "-z", "registry"], {
|
|
cwd: repoRoot,
|
|
encoding: "utf-8",
|
|
maxBuffer: 64 * 1024 * 1024,
|
|
});
|
|
const entries = listing.split("\0").filter(Boolean);
|
|
const symlinks = entries.filter((entry) => entry.startsWith("120000 "));
|
|
assert.deepEqual(symlinks, []);
|
|
const escaping = entries
|
|
.map((entry) => entry.slice(entry.indexOf("\t") + 1))
|
|
.filter((file) => file.endsWith("/registry-item.json") && fs.existsSync(join(repoRoot, file)))
|
|
.flatMap((file) => {
|
|
const itemDir = join(repoRoot, dirname(file));
|
|
const manifest = JSON.parse(fs.readFileSync(join(repoRoot, file), "utf8")) as {
|
|
files?: Array<{ path: string }>;
|
|
};
|
|
return (manifest.files ?? [])
|
|
.filter(({ path }) => {
|
|
const rel = relative(itemDir, resolve(itemDir, path));
|
|
return rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel);
|
|
})
|
|
.map(({ path }) => `${file}: ${path}`);
|
|
});
|
|
assert.deepEqual(escaping, []);
|
|
});
|