Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(frontmatter): tag extraction keeps scalar tags only (alias-bomb hardening)
garrytan1fc5f45f1f95
diff --git a/src/core/markdown.ts b/src/core/markdown.tsindex 4087c0c2cd..b920a04a0f 100644--- a/src/core/markdown.ts+++ b/src/core/markdown.ts@@ -1193,7 +1193,8 @@ function inferSlug(filePath?: string): string {function extractTags(frontmatter: Record<string, unknown>): string[] {const tags = frontmatter.tags;if (!tags) return [];- if (Array.isArray(tags)) return tags.map(String);+ // Only scalar items are tags: stringifying a nested array would expand a YAML alias bomb.+ if (Array.isArray(tags)) return tags.filter(t => t instanceof Date || (t !== null && typeof t !== 'object')).map(String);if (typeof tags === 'string') return tags.split(',').map(t => t.trim()).filter(Boolean);return [];}diff --git a/test/frontmatter-alias-bomb.test.ts b/test/frontmatter-alias-bomb.test.tsindex 9d75b98dab..c736965748 100644--- a/test/frontmatter-alias-bomb.test.ts+++ b/test/frontmatter-alias-bomb.test.ts@@ -36,6 +36,16 @@ describe('frontmatter alias bomb (W5.1 security review)', () => {expect(performance.now() - started).toBeLessThan(1000);});+ // Pre-existing on master (not from #6157): tag extraction stringified nested+ // tag arrays, which expands the same bomb. Only scalar tags are kept.+ test('parsing a tags: bomb returns fast; nested tag arrays are not tags', () => {+ const started = performance.now();+ const parsed = parseMarkdown(page(bomb('tags')));+ expect(performance.now() - started).toBeLessThan(1000);+ expect(parsed.tags).toEqual([]);+ expect(parseMarkdown(page('tags: [yc, 2025, "w25"]')).tags).toEqual(['yc', '2025', 'w25']);+ });+test('the alias limit counts aliases outside quotes only', () => {expect(yamlAliasesWithinLimit(bomb('tags'))).toBe(false);expect(yamlAliasesWithinLimit('base: &b {a: 1}\nother: *b\nnote: "a *star* in a string"')).toBe(true);