T09 · Insecure Skill Coding Practices
- Location
scripts/generate-from-template.js:428- Finding
Unsanitized Symbol Name Allows Path Traversal and Unauthorized File Overwrites
- Content
View full analysis
"$symbolset_dir/Contents.json" <- Remediation
View remediation
&2 exit 1 fi ``` 2. **Enforce destination containment** Resolve the asset root and each destination to absolute paths, then verify that every destination remains beneath the resolved root before creating or writing files: ```javascript const resolvedAssetsDir = path.resolve(assetsDir); const symbolsetDir = path.resolve( resolvedAssetsDir, `${symbolName}.symbolset` ); if (!symbolsetDir.startsWith(`${resolvedAssetsDir}${path.sep}`)) { throw new Error('Destination escapes the asset directory.'); } const svgPathOut = path.resolve(symbolsetDir, `${symbolName}.svg`); if (!svgPathOut.startsWith(`${symbolsetDir}${path.sep}`)) { throw new Error('SVG destination escapes the symbolset directory.'); } ``` Use canonicalized paths and equivalent containment checks in the shell script. 3. **Prevent unintended overwrites** Refuse to replace an existing symbolset unless the user supplies an explicit `--force` option. For JavaScript writes, use exclusive creation flags where appropriate: ```javascript fs.writeFileSync(svgPathOut, outputSvg, { flag: 'wx' }); ``` 4. **Escape output according to its format** XML-escape any value inserted into SVG text. Generate JSON using a JSON serializer rather than interpolati ...[truncated 672 chars]
