T09 · Insecure Skill Coding Practices
- Location
src/progress.js:310- Finding
Unrestricted Caller-Controlled File Read and Write Paths
- Content
View full analysis
Vulnerability Details
File Location:
src/progress.js:310-344
Vulnerability Type: Arbitrary file read and overwrite through unrestricted path parameters
Risk Level: MediumVulnerable Code
javascript /** * Export sessions to JSON * @param {string} filePath - File path to export to * @returns {boolean} Success */ function export_to_file(filePath) { try { const data = { sessions, milestones, exportedAt: new Date().toISOString() }; fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); return true; } catch (error) { console.error('Export failed:', error); return false; } } /** * Import sessions from JSON file * @param {string} filePath - File path to import from * @returns {boolean} Success */ function import_from_file(filePath) { try { const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); if (data.sessions) sessions = data.sessions; if (data.milestones) milestones = data.milestones; return true; } catch (error) { console.error('Import failed:', error); return false; } }Technical Analysis
The public
export_to_file()andimport_from_file()functions pass a caller-supplied path directly tofs.writeFileSync()andfs.readFileSync(). There is no approved base directory, path canonicalization, traversal check, symbolic-link protection, file-size limit, or imported-data schema validation.Both functions are re-exported by
index.js, making them part of the skill's public API. Consequently, any application or agent workflow that allows an untrusted party to influence thefilePathargument can access paths outside the skill's intended storage area.The import operation requires the target content to be valid JSON before it is loaded into application state. Nevertheless, an attacker can read any accessible JSON file and subsequently expose impo ...[truncated 2008 chars]
- Remediation
View remediation
Remediation Suggestions
- Configure a dedicated progress-data directory and reject access outside it.
- Resolve both the approved directory and requested path with
path.resolve(), then verify that the requested path remains beneath the approved directory usingpath.relative(). - Reject absolute paths when only application-relative filenames are required.
- Restrict accepted filenames and extensions, such as allowing only simple
.jsonfilenames. - Use
fs.realpath()and appropriate no-follow or preflight checks where symbolic-link attacks are relevant. - Avoid silent overwrites. Require explicit overwrite authorization or use exclusive file-creation flags when creating new exports.
- Check file metadata before import and enforce a conservative maximum file size.
- Prefer asynchronous filesystem APIs to avoid blocking the event loop.
- Validate imported JSON against a strict schema before assigning
sessionsormilestones. - Validate field types, timestamp formats, array lengths, and numeric ranges, and reject unexpected properties.
- Return structured errors without exposing sensitive filesystem details in production logs.
- Ensure the hosting process runs with least-privilege filesystem permissions.
