T09 · Insecure Skill Coding Practices
- Location
index.js:36- Finding
Backup Name Path Traversal Enables Writes Outside the Backup Directory
- Content
View full analysis
Vulnerability Details
File Location:
index.js, lines 36-42
Vulnerability Type: Unvalidated path component and directory traversal
Risk Level: Highjavascript // Generate backup name const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const backupName = name || `backup-${timestamp}`; const backupPath = path.join(backupDir, backupName); if (fs.existsSync(backupPath)) { return { success: false, error: 'Backup with this name already exists', ...result }; } fs.mkdirSync(backupPath, { recursive: true }); result.backup_path = backupPath;Technical Analysis
The caller-controlled
namevalue is passed directly topath.join()without requiring it to be a single safe directory name. A value containing..path segments can causebackupPathto resolve outsidebackupDir.The subsequent backup process creates this directory and copies selected workspace files into it. These files can include
MEMORY.md,SOUL.md,IDENTITY.md,AGENTS.md,USER.md,HEARTBEAT.md, andTOOLS.md, as well as content from thememoryandlogsdirectories.Checking whether the resulting path already exists does not establish that it is inside the authorized backup directory.
Attack Path
- An attacker or untrusted caller invokes
createBackup()with a crafted name, such as:javascript createBackup({ name: '../../attacker-output' }); path.join(backupDir, name)resolves the traversal sequence outside the configured backup directory.fs.mkdirSync()creates the attacker-selected destination.- The backup operation copies sensitive workspace files into that out-of-scope location.
- Anyone with access to the destination can read the copied workspace data.
Impact Assessment
An attacker able to control backup options can create directories and write backup data anywhere permitted by the process account. The exposed data may include identi ...[truncated 264 chars]
- An attacker or untrusted caller invokes
- Remediation
View remediation
Remediation Suggestions
- Require
nameto be a single basename with a strict allowlist, such as letters, digits, underscores, and hyphens. - Reject absolute paths, path separators, empty names,
.entries, and..entries. - Resolve both paths and verify containment before performing any write:
javascript const root = path.resolve(backupDir); const destination = path.resolve(root, backupName); if ( destination === root || !destination.startsWith(root + path.sep) ) { throw new Error('Invalid backup name'); } - Do not rely solely on prefix checks without appending
path.sep, because sibling paths can share textual prefixes. - Use restrictive directory and file permissions when creating backups.
- Add tests covering
../, nested traversal, absolute paths, alternate separators, empty names, and sibling-prefix bypasses.
- Require
