CWE-61
- Location
src/zip.mjs:38- Finding
Skill Upload Packaging Follows Symbolic Links Outside the Selected Directory ## Remediation Suggestions 1. Use `lstat` to identify and reject symbolic links before recursion or file reads. Reject unsupported filesystem entry types. 2. Resolve the selected root and each candidate’s canonical path, then enforce containment using path-component-aware comparisons. 3. Address replacement races between validation and reading. Use no-follow file-opening options where supported and verify the opened file’s metadata. 4. Build a complete upload manifest before transmission. Present included files and total size for approval; reject entries outside the intended root. 5. Add file-count, individual-size, total-size, and recursion-depth limits. These also mitigate excessive traversal and memory consumption. 6. Add regression tests for external file links, external directory links, cyclic links, and links replaced during packaging. Apply the same protections to uploads and updates.
- Content
View full analysis
Vulnerability Details
File Location:
src/zip.mjs:38–47, 56–69; upload callers atsrc/tools.mjs:464–472, 1296–1302; network upload atsrc/api.mjs:331–343
Vulnerability Type: Improper Symbolic Link Resolution; Unintended File Disclosure (CWE-61)
Risk Level: MediumVulnerable Code
Directory collection follows symbolic links without validating the resolved target:
js function collectFiles(dir, base, out = []) { for (const entry of readdirSync(dir)) { if (SKIP_DIRS.has(entry)) continue const abs = join(dir, entry) const st = statSync(abs) if (st.isDirectory()) collectFiles(abs, base, out) else if (st.isFile()) out.push({ abs, rel: relative(base, abs).split(sep).join('/') }) } return out }The ZIP writer reads the collected paths:
js const files = collectFiles(dir, dir)js for (const f of files) { const data = readFileSync(f.abs) const entryName = Buffer.from(`${name}/${f.rel}`, 'utf8') const crc = crc32(data)The upload caller sends the resulting archive:
js const { buffer, rootName, files } = zipDirectory(resolvePath(a.path), { rootName: pf.rootName }) const json = await api.skillUpload(buffer, `${rootName}.zip`, { scope, repo: repoFull, agent_type: a.agent_type, tags: a.tags || '', summary: a.summary || pf.description.slice(0, 200), change_note: a.change_note || '', })Technical Analysis
statSync()follows symbolic links. Consequently, a link inside an otherwise valid skill directory is classified according to its target. File links are subsequently read withreadFileSync(), and directory links are traversed recursively.Neither operation checks whether the resolved target remains inside the selected skill directory. The archive filename is constructed from the unresolved, in-directory path, so an external file’s contents appear in the ZIP as an ordinary skill asset.
Frontmatter preflight validation does not prevent this behavior. Both skill upload ...[truncated 1620 chars]
