fix: prevent namespace squatting via name-directory binding in skill discovery#356
Open
mmizutani wants to merge 3 commits intovercel-labs:mainfrom
Open
fix: prevent namespace squatting via name-directory binding in skill discovery#356mmizutani wants to merge 3 commits intovercel-labs:mainfrom
mmizutani wants to merge 3 commits intovercel-labs:mainfrom
Conversation
…discovery The skill installer was vulnerable to namespace squatting attacks where an attacker could submit a SKILL.md with a frontmatter name: field claiming another skills name from a directory that sorts alphabetically before the legitimate one. Combined with first-match-wins deduplication, this allowed silently shadowing legitimate skills. This vulnerability was actively being exploited in the openclaw/skills community repository with 100+ malicious skill variants. Changes: - Extract sanitizeName() to src/sanitize.ts to avoid circular imports - parseSkillMd(): validate that frontmatter name matches directory name (override to directory name on mismatch with stderr warning) - discoverSkills(): replace Set with Map for seenNames to track paths, warn on duplicate skill names showing both accepted and skipped paths - filterSkills(): prefer skills whose directory name matches the filter when multiple skills share the same frontmatter name - Update existing tests to use consistent name-directory bindings - Add comprehensive namespace-squatting test suite
…rruption - Introduced a local variable for skill name in parseSkillMd to avoid mutating data.name, preventing potential cache corruption when parsing identical SKILL.md content. - Updated discoverSkills to only warn about duplicate skill names when they originate from different directories, enhancing clarity in duplicate detection. - Added tests to ensure correct behavior when parsing identical content and to verify no warnings are emitted for same-path rediscoveries.
|
@mmizutani is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
74cd28d to
8ac553c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical namespace squatting vulnerability in skill discovery that allows attackers to shadow legitimate skills with malicious ones in community skill repositories.
parseSkillMd()— overrides YAML frontmattername:when it doesn't match the containing directory name (after sanitization)discoverSkills()— replaces silent first-match-wins dedupfilterSkills()as defense-in-depth — when multiple skills match a filter, prefers skills whose directory matches the requested namesanitizeName()tosrc/sanitize.tsto avoid circular dependency betweenskills.tsandinstaller.tsResolve #353
Motivation
The
npx skills addcommand is vulnerable to a namespace squatting attack where:aaa-attacker/bird-fake/with YAML frontmattername: bird(matching a legitimate skill atsteipete/bird/)discoverSkills()deduplicates by frontmattername:with first-match-wins, and filesystem traversal order (readdir()) typically processes alphabetically-earlier directories firstThis vulnerability is being actively exploited in the wild. As reported on Reddit, the
openclaw/skillscommunity repository contains 100+ malicious skill submissions from accounts includingsakaen736jih,gitgoodordietrying,dongsjoa-byte, and others. Reported payloads include C2 callbacks, SSH key injection, and binary downloads.Root cause
Two design flaws combine to enable the attack:
parseSkillMd()name:is trusted without validation against the directory namediscoverSkills()Changes
1.
parseSkillMd()— name-directory binding (src/skills.ts)Added an optional
basePathparameter. When provided (fromdiscoverSkills), comparessanitizeName(data.name)againstsanitizeName(basename(dirname(skillMdPath))). On mismatch, emits a warning and overrides the name to match the directory.Exceptions (no false positives):
dirname(skillMdPath) === basePath(e.g., a single-skill repo clone), validation is skipped since the dirname is a temp directory, not a skill identitysanitizeName("My Skill") === "my-skill"— the original frontmatter name is preserved when sanitized forms matchlistInstalledSkills()and other existing callers that don't passbasePathare unaffected (backward compatible)2.
discoverSkills()— duplicate detection (src/skills.ts)seenNamesfromSet<string>toMap<string, string>(name → path) for trackingbasePath: searchPathto allparseSkillMd()calls to activate name-directory validationThis applies at all three dedup sites: root skill, priority directory search, and fallback recursive search.
3.
filterSkills()— directory-name preference (src/skills.ts)When multiple skills match a user's filter input, prefers those whose
basename(skill.path)matches the input after sanitization. This is a defense-in-depth layer that resolves ambiguity in favor of the skill at the expected directory path.4.
sanitizeName()extraction (src/sanitize.ts)Extracted
sanitizeName()fromsrc/installer.tsto a newsrc/sanitize.tsmodule. Bothskills.tsandinstaller.tsnow import fromsanitize.ts. The original export frominstaller.tsis preserved via re-export for backward compatibility.How the fix neutralizes the attack
Test plan
Added
tests/namespace-squatting.test.tswith 12 test cases across 3 describe blocks:parseSkillMdname-directory validation (6 tests)discoverSkillsnamespace squatting prevention (2 tests)filterSkillsdirectory name preference (4 tests)Updated existing tests that relied on name-directory mismatches:
tests/plugin-manifest-discovery.test.ts— 5 test cases updated to use consistent name-directory bindingssrc/add.test.ts— 1 test case updated for consistent namingAll 299 applicable tests pass.
Files changed
src/sanitize.tssanitizeName()src/skills.tssrc/installer.tssanitizeNamefromsanitize.tstests/namespace-squatting.test.tstests/plugin-manifest-discovery.test.tssrc/add.test.tsSecurity considerations
namematches the directory (or matches after sanitization) are unaffectedparseSkillMd()that don't passbasePath(e.g.,listInstalledSkills()) retain original behaviorRelated
openclaw/skills