T09 · Insecure Skill Coding Practices
- Location
scripts/lib/figma-artifact-writer.mjs:18- Finding
Path Traversal Through Untrusted Issue Identifier Allows Writes Outside the Artifact Root
- Content
View full analysis
Vulnerability Details
File Location:
scripts/lib/figma-artifact-writer.mjs, lines 18-20 and 376-378
Vulnerability Type: Path traversal and insufficient output-path containment
Risk Level: MediumVulnerable Code
js function issueRunName(issue) { return issue?.identifier || issue?.id || `manual-${new Date().toISOString().replace(/[:.]/g, '-')}`; }The resulting untrusted value is later used directly as a path component:
js const runName = issueRunName(issue); const runDir = path.join(artifactRoot, runName); await fs.mkdir(runDir, { recursive: true });Files and directories are subsequently created beneath this path:
js await writeUrlArtifacts(runDir, urlResult);js await writeJson(path.join(runDir, 'manifest.json'), manifest); await writeText(path.join(runDir, 'summary.md'), buildSummary({ urlResults: normalizedResults, manifest, emptyReason }));A recursively destructive operation can also occur beneath the derived path:
js const urlDir = path.join(runDir, urlResult.artifactDir); const artifactBytes = await directorySizeBytes(urlDir); if (artifactBytes > maxArtifactBytesPerUrl) { await fs.rm(urlDir, { recursive: true, force: true }); normalizedResults[index] = artifactBudgetFailure(urlResult, Math.floor(maxArtifactBytesPerUrl), artifactBytes); }Technical Analysis
The run directory name is derived from
issue.identifierorissue.id, which originates in the supplied issue JSON. The value is neither restricted to a safe filename grammar nor checked for path separators, absolute paths,.segments, or..traversal segments.path.join()normalizes traversal segments but does not enforce containment beneathartifactRoot. For example, ifartifactRootis/repo/.multica/figma-contextand the issue identifier is../../target, the resulting path resolves outside the configured artifact directory.The workflow then writes predictable files such as
manifest.json,summary.md, a ...[truncated 2147 chars]- Remediation
View remediation
Remediation Suggestions
- Do not use raw issue metadata as a directory name. Convert it to a safe slug with a strict allowlist, such as ASCII letters, digits, underscores, periods, and hyphens. Explicitly reject empty values,
.and...
js function safeRunName(issue) { const raw = String( issue?.identifier || issue?.id || `manual-${new Date().toISOString().replace(/[:.]/g, '-')}`, ); if (!/^[A-Za-z0-9._-]+$/.test(raw) || raw === '.' || raw === '..') { throw createStableError( 'artifact_run_name_invalid', 'Issue identifier cannot be used as an artifact directory name', ); } return raw; }- Resolve and verify containment before any filesystem operation.
js function resolveContainedRunDir(artifactRoot, runName) { const root = path.resolve(artifactRoot); const runDir = path.resolve(root, runName); const relative = path.relative(root, runDir); if ( relative.length === 0 || relative.startsWith(`..${path.sep}`) || relative === '..' || path.isAbsolute(relative) ) { throw createStableError( 'artifact_path_invalid', 'Artifact run directory escapes the artifact root', ); } return runDir; }-
Repeat containment validation immediately before recursive deletion. Destructive operations should not rely solely on an earlier check.
-
Consider using an internal generated identifier. A random UUID or timestamp can be used for the physical directory while the original issue identifier remains metadata inside the manifest.
-
Add regression tests covering:
../target../../target- Absolute paths
- POSIX and Windows path separators
.and..- Empty or whitespace-only identifiers
- Encoded or mixed-separator traversal attempts
- Verification that recursive deletion cannot target a directory outside
artifactRoot
-
Use non-overwriting creation semantics where practical or explicitly handle existing run ...[truncated 65 chars]
- Do not use raw issue metadata as a directory name. Convert it to a safe slug with a strict allowlist, such as ASCII letters, digits, underscores, periods, and hyphens. Explicitly reject empty values,
