fix(#2182): harden registry rendering + validation against injection (review)
Addresses findings from the orthogonal /code-review + /security-review passes: - Markdown-injection (CRITICAL/HIGH): escape untrusted free-text (name, description, license, author, eos axes) with mdInline() and size install/uninstall code fences dynamically so a crafted entry cannot inject phishing links, break the summary table, or escape the code fence in the committed, GitHub-rendered catalog. - validateEntries no longer throws on a null/non-object array element (kept the --json contract); rejects control characters in free-text fields; caps field lengths and entry count; tightens the discussion and license regexes so neither admits Markdown metacharacters / newlines. - gen-registry treats a missing capabilities.json as an error (only eos.json is optional pre-PR2); disambiguated from gen-capability-registry.cjs. - Renders the required 'author' field (was captured but never shown). - Adds tests for every fix: escaping/link-hijack/fence, null guard, control chars, length + entry caps, tightened regexes, eos render path, interactions guards. Refs #2182 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,15 @@
|
||||
* from the corresponding source JSON, via registry-schema.cjs#renderMarkdown.
|
||||
* Issue #2182.
|
||||
*
|
||||
* NOT to be confused with `scripts/gen-capability-registry.cjs`: that script
|
||||
* generates the RUNTIME capability manifest consumed by the host at runtime
|
||||
* (`gsd-core/bin/lib/capability-registry.cjs`, built from every
|
||||
* `capabilities/<id>/capability.json` declaration). THIS script instead
|
||||
* generates the human-facing DOCUMENTATION catalog pages
|
||||
* (`docs/registries/*.md`) from the third-party discoverability registry
|
||||
* source JSON (`docs/registries/{capabilities,eos}.json`). The two pipelines
|
||||
* are independent — do not conflate them.
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/gen-registry.cjs # print rendered markdown(s) to stdout
|
||||
* node scripts/gen-registry.cjs --write # write the *-registry.md file(s)
|
||||
@@ -46,8 +55,14 @@ function getRegistriesDir() {
|
||||
|
||||
/**
|
||||
* Render the markdown for a single registry type from its committed source
|
||||
* JSON. Returns null if the source JSON does not exist (e.g. eos.json before
|
||||
* PR2 ships) — callers treat that as "nothing to do" rather than an error.
|
||||
* JSON.
|
||||
*
|
||||
* Only `eos.json` is optional (pre-PR2, before that source JSON ships) —
|
||||
* an absent `eos.json` returns null and callers treat that as "nothing to
|
||||
* do". `capabilities.json` is the primary registry source: a missing
|
||||
* `capabilities.json` is ALWAYS an error (never a silent "up to date"
|
||||
* pass), mirroring the type distinction in `scripts/validate-registry.cjs`
|
||||
* (`type === 'eos' && !exists → continue`).
|
||||
*
|
||||
* @param {'capability'|'eos'} type
|
||||
* @returns {string|null}
|
||||
@@ -57,7 +72,13 @@ function renderFor(type) {
|
||||
if (!source) throw new Error(`gen-registry: unknown registry type "${type}"`);
|
||||
|
||||
const jsonPath = path.join(getRegistriesDir(), source.jsonFile);
|
||||
if (!fs.existsSync(jsonPath)) return null;
|
||||
if (!fs.existsSync(jsonPath)) {
|
||||
if (type === 'eos') return null;
|
||||
throw new ExitError(
|
||||
1,
|
||||
`${source.jsonFile} does not exist at ${jsonPath}. Run:\n node scripts/gen-registry.cjs --write\n(after adding docs/registries/${source.jsonFile})`,
|
||||
);
|
||||
}
|
||||
|
||||
const entries = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
||||
return renderMarkdown(entries, { type, sourceFile: source.jsonFile });
|
||||
|
||||
Reference in New Issue
Block a user