T05 · Unauthorized Access and Privilege Escalation
- Location
index.js:6- Finding
Path Traversal Enables Unauthorized Skill Execution with Inherited Agent Privileges
- Content
View full analysis
Vulnerability Details
File Location:
index.js, lines 6-39
Vulnerability Type: Path traversal and missing authorization for dynamic module execution
Risk Level: HighVulnerable Code
javascript function getSkillPath(skillName) { return path.join('/home/bosunjung/.openclaw/workspace/skills', skillName, 'index.js'); } // Main skill entry point export async function skill(args, context) { const message = args.message; if (!message || typeof message !== 'string' || !message.startsWith('run ')) { console.warn('[Skill Runner] Invalid message format. Expected "run <skill-name>".'); return { status: 'error', reason: 'invalid_message_format' }; } const skillToRun = message.substring(4).trim(); const skillFilePath = getSkillPath(skillToRun); if (!fs.existsSync(skillFilePath)) { console.error(`[Skill Runner] Target skill "${skillToRun}" not found at ${skillFilePath}.`); return { status: 'error', reason: 'skill_not_found', skill: skillToRun }; } try { const skillModule = await import(fileURLToPath(`file://${skillFilePath}`)); if (typeof skillModule.skill !== 'function') { console.error(`[Skill Runner] Target skill "${skillToRun}" does not export a 'skill' function.`); return { status: 'error', reason: 'invalid_skill_export', skill: skillToRun }; } console.log(`[Skill Runner] Executing target skill "${skillToRun}"...`); const result = await skillModule.skill(args, context);Technical Analysis
The skill name is extracted directly from an externally supplied message and inserted into a filesystem path without validating its syntax, canonicalizing the result, or checking that the resolved file remains beneath the intended skills directory.
path.join()normalizes traversal components such as... Consequently, an input such asrun ../../other-locationcan escape `/home/bosunjung/.openclaw/workspac ...[truncated 2816 chars]- Remediation
View remediation
Remediation Suggestions
-
Use an explicit allowlist. Map approved external identifiers to fixed module paths rather than deriving paths from user input:
javascript const APPROVED_SKILLS = new Map([ ['memory-enhancer', '/home/bosunjung/.openclaw/workspace/skills/memory-enhancer/index.js'], ]); const skillFilePath = APPROVED_SKILLS.get(skillToRun); if (!skillFilePath) { return { status: 'error', reason: 'skill_not_authorized' }; } -
Strictly validate identifiers. If dynamic discovery is required, accept only a narrow format such as
/^[a-z0-9][a-z0-9-]{0,63}$/. Reject slashes, backslashes, dots used as traversal segments, null bytes, encoded separators, and unexpected whitespace. -
Enforce the canonical directory boundary. Resolve both the root and candidate path, then verify that the candidate is a descendant of the root:
javascript const skillsRoot = path.resolve('/home/bosunjung/.openclaw/workspace/skills'); const candidate = path.resolve(skillsRoot, skillToRun, 'index.js'); if (!candidate.startsWith(skillsRoot + path.sep)) { return { status: 'error', reason: 'invalid_skill_path' }; } -
Defend against symbolic-link escapes. Use
fs.realpath()on the root and candidate and repeat the descendant check against their canonical paths before import. -
Add caller-level authorization. Verify that the requesting cron job, agent, or session is authorized to invoke the specific allowlisted skill. Message formatting is not an authorization control.
-
Apply least privilege to context delegation. Do not pass the complete runner context by default. Construct a restricted context exposing only the tools and scopes required by the approved target skill.
-
Separate trust domains. Execute target skills in isolated processes or sandboxes with restricted filesystem, network, environment, and tool access. Dynamic module impo ...[truncated 332 chars]
-
