fix: address Copilot review round 5 on #2248
**A cyclic YAML alias crashed the tool.** `meta: &m [*m]` parses cleanly into a self-referential array, and the frontmatter comparison is a recursive walk, so a hostile server could take down `--verify` or the TUI with a stack overflow instead of receiving a finding. Verified before fixing: it really did raise `RangeError: Maximum call stack size exceeded`. Rejected at the parse, so no consumer has to be cycle-safe on its own, and it becomes an ordinary `frontmatter-unparsable` finding. Detection is per-PATH rather than per-graph — `seen` unwinds on the way back up — so an alias reused across siblings, which is ordinary YAML and represents fine in JSON, is not mistaken for a cycle. A depth bound closes the same hole by its other door: a legal, acyclic but absurdly nested document exhausts the stack just as well, and a cycle check alone passes it. **The web frontmatter check was gated on the presentation MIME.** It ran off `previewParts`, which exists only when the displayed type is recognized as markdown — so a `SKILL.md` a server typed `text/plain`, or served as a base64 blob, skipped a mandatory comparison while the pane still read as clean. It now decodes the same fetched bytes the digest is taken over, which also stops the two answers describing different derivations of the payload. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ND46Ci64DC3tzBy9aG81Nc Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
799763543f
commit
916b08ba93
1 changed files with 178 additions and 10 deletions
|
|
@ -137,6 +137,50 @@ describe("parseSkillFrontmatter (#2248)", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("rejects a cyclic YAML alias instead of crashing on it", () => {
|
||||
// A YAML document is a graph and JSON is a tree: `&m [*m]` parses cleanly
|
||||
// into a self-referential array, and the field-by-field comparison is a
|
||||
// recursive walk — so this crashed `--verify` and the TUI with a stack
|
||||
// overflow rather than producing a finding. A hostile server taking the
|
||||
// tool down is a worse outcome than any wrong verdict (Copilot).
|
||||
const parsed = parseSkillFrontmatter("meta: &m [*m]");
|
||||
expect(parsed).toEqual({ error: expect.stringContaining("cyclic") });
|
||||
});
|
||||
|
||||
it("rejects a cycle through a mapping, not only an array", () => {
|
||||
expect(parseSkillFrontmatter("a: &a\n self: *a")).toEqual({
|
||||
error: expect.stringContaining("cyclic"),
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts a value that merely appears twice as a sibling", () => {
|
||||
// An alias reused across siblings is ordinary YAML and represents fine in
|
||||
// JSON — detection has to be per-path, not per-graph, or this would be
|
||||
// reported as a cycle.
|
||||
expect(parseSkillFrontmatter("base: &b [1, 2]\nx: *b\ny: *b")).toEqual({
|
||||
fields: { base: [1, 2], x: [1, 2], y: [1, 2] },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a frontmatter nested past the depth bound", () => {
|
||||
// The other door to the same crash: legal, acyclic, and still deep enough
|
||||
// to exhaust the stack, which a cycle check alone would let through.
|
||||
const deep =
|
||||
"a:\n" +
|
||||
Array.from({ length: 80 }, (_, i) => `${" ".repeat(i + 1)}a:`).join(
|
||||
"\n",
|
||||
);
|
||||
expect(parseSkillFrontmatter(deep)).toEqual({
|
||||
error: expect.stringContaining("nests deeper"),
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts ordinary nesting well inside the bound", () => {
|
||||
expect(parseSkillFrontmatter("a:\n b:\n c: 1")).toEqual({
|
||||
fields: { a: { b: { c: 1 } } },
|
||||
});
|
||||
});
|
||||
|
||||
it("reports invalid YAML with the parser's own message", () => {
|
||||
const parsed = parseSkillFrontmatter("a: [1,");
|
||||
expect("error" in parsed && parsed.error.length > 0).toBe(true);
|
||||
|
|
|
|||
Loading…
Reference in a new issue