Repository navigation
fix(validator): allowlisted skills only, not Object.prototype keys - #505
Conversation
`dirName in SECTION_EXEMPT_SKILLS` walks the prototype chain, and `constructor` satisfies KEBAB_CASE (the `*` quantifier permits a single word). A skill directory named `constructor` therefore resolved to Object.prototype.constructor and was silently exempt from every required-section check — `exempt: true`, zero errors, no sections. The bypass guard missed it for the same reason, since the resolved value is truthy. Both lookups now use Object.hasOwn, which is what the comment above the allowlist already promises: "Exemptions live HERE, not in skill frontmatter, so contributors cannot bypass the validator by editing their own skill file." Adds scripts/lib/skill-lint-test.js — skill-lint.js was the only validator without a test file. Confirmed the prototype-chain test goes red against main; the other six pass either way, so existing behaviour is unchanged. Scope kept to the exemption lookup: addyosmani#428 already rewrites frontmatter parsing and the cross-reference patterns, so this stays clear of both.
b0cbe0c to
c59c4b4
Compare
|
I've narrowed this substantially, and I owe an explanation. #428 already fixes two of the three things I originally reported here, and does it better. It was opened a month before this one and I should have read it before filing. Specifically it already handles block scalars with chomping indicators, comments, quoted scalars, malformed lines as errors, and nested collections; and it already makes the reference patterns case-tolerant ( So I've reverted both of those and rebased this down to the one thing #428 does not touch. What remains
The bypass guard misses it for the same reason: Both lookups now use I'll be straight that a skill named Verification
The other six pass either way, which is the check that existing behaviour is unchanged. The tests are deliberately narrow — no frontmatter or cross-reference assertions — so they don't collide with #428. All five validators still report If you'd rather fold this two-line change into #428 and close this, that's completely reasonable and I'd support it — @ayobamiseun got there first on the substantial part. |
addyosmani
left a comment
There was a problem hiding this comment.
Good catch, and the right fix. in walks the prototype chain, so a skill dir named constructor (which passes the kebab check) would resolve to Object.prototype.constructor and get silently exempted from the section checks. Object.hasOwn closes that. Test-merged clean, lint tests pass. Approving.
Resolves the add/add conflict on scripts/lib/skill-lint-test.js created when addyosmani#505 merged the same path first. The resolution is a union: addyosmani#505's exemption and guardrail cases, then addyosmani#444's fence cases. KNOWN gains 'portable-skill' so the fence fixtures resolve; skill-lint.js auto-merged with no conflict. 19 tests pass on the merged tree. Against main's pre-addyosmani#444 lint script, the five tilde/indented/longer-closer/unterminated cases go red, so the fence change stays load-bearing.
Three defects in
scripts/lib/skill-lint.js, each with a regression test. Also addsscripts/lib/skill-lint-test.js— this is the only validator without a test file, whilevalidate-versions,validate-commands,validate-reference-links,validate-artifact-pathsandrun-evalsall have one.Found while reading the linter after #437; these are in
parseFrontmatterand the exemption lookup, so they don't overlap with thestripFencedCodeBlockswork in #428 / #444.1. A legal YAML block scalar description is rejected
parseFrontmattersplit on the first colon of every line, so:parsed as
description = ">". The trigger check then failed on a skill whose description is legal YAML and does contain a trigger:Continuation lines were worse. Because every line was scanned for a colon, an indented
Use when: …became its own field — so a fold could inject a phantomUse whenkey.Keys are now recognised only when unindented at column zero, and
>/|blocks are gathered (folded joins with spaces, literal keeps newlines).2. A skill directory named
constructorbypasses every section checkinwalks the prototype chain, andconstructorsatisfiesKEBAB_CASE(the*quantifier permits a single word). So a skill with no sections at all validated clean:The "fail loud" guard missed it too, for the same reason —
SECTION_EXEMPT_SKILLS['constructor']is truthy. Both now useObject.hasOwn, which is what the comment above the allowlist already promises: "Exemptions live HERE, not in skill frontmatter, so contributors cannot bypass the validator by editing their own skill file."I'll be straight that a skill named
constructoris unlikely. I'd still rather the allowlist be the only thing granting exemptions, since that guarantee is stated in the file.3. A sentence-initial dead cross-reference is not reported
SKILL_REF_PATTERNSmatched lowercase verbs only, soSee \x`at the start of a sentence was invisible to the dead-reference check. This isn't hypothetical —skills/api-and-interface-design/SKILL.md:30` writes:That target exists, so nothing is wrong today; a dead reference written that way would simply go unwarned. The leading verb now accepts either case.
The captured name deliberately stays lowercase-only rather than adding an
iflag to the whole pattern: a case-insensitive capture would read prose like`Foo-Bar`as a skill name and invent dead references. Confirmed no new warnings on current content — still 24 skills, 0 errors, 0 warnings.Verification
Each of the five new failing cases was confirmed red against the unpatched rules first, by reverting only
skill-lint.jsand keeping the tests:The other seven tests pass either way, which is the check that existing behaviour is unchanged.
After the fix:
node --test scripts/lib/skill-lint-test.js— 12/1224 skills checked — 0 error(s), 0 warning(s) — PASSEDnode scripts/run-evals.js --min-rank1 80— 86% (67/78)If you'd like
skill-lint-test.jswired into.github/workflows/test-plugin-install.ymlalongside the othernode --teststeps, say so and I'll add it here rather than leaving it to a follow-up.