mirror of
https://github.com/addyosmani/agent-skills.git
synced 2026-10-26 15:05:04 +00:00
security: validate --behavioral skillName to prevent path traversal
The skillName argument from --behavioral has zero validation and is used directly in path.join() for reading .json files, reading SKILL.md, and WRITING .grading.json results. A value like '../../etc/passwd' traverses outside the project directory for both reads and writes. Fix: Validate skillName against /^[a-z0-9]+(-[a-z0-9]+)*$/ before any filesystem operations. This matches the existing KEBAB_CASE validation in skill-lint.js.
This commit is contained in:
1 parent
bdf76c7c6b
commit
4b3122e65f
1 file changed
+9
@@ -443,7 +443,16 @@ function parseGrading(raw) {
|
||||
return ok ? g : null;
|
||||
}
|
||||
|
||||
// Skill name must be a valid kebab-case identifier — no path separators,
|
||||
// no "..", no absolute paths. Without this, --behavioral "../../x" would
|
||||
// resolve to files outside the project tree for both reads and writes.
|
||||
const VALID_SKILL_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
||||
|
||||
function runBehavioral(skillName, dryRun) {
|
||||
if (!skillName || !VALID_SKILL_NAME.test(skillName)) {
|
||||
console.error(`Invalid skill name: "${skillName}" — must be kebab-case (e.g. "my-skill")`);
|
||||
process.exit(1);
|
||||
}
|
||||
const caseFile = path.join(CASES_DIR, `${skillName}.json`);
|
||||
if (!fs.existsSync(caseFile)) {
|
||||
console.error(`No eval case file for "${skillName}"`);
|
||||
|
||||
Reference in new issue
Block a user