T09 · Insecure Skill Coding Practices
- Location
scripts/scan.mjs:267- Finding
Unrestricted miniprogramRoot Allows Scanning Outside the Selected Project
- Content
View full analysis
Vulnerability Details
File Location:
scripts/scan.mjs:267-272
Vulnerability Type: Path traversal leading to unauthorized file reads
Risk Level: MediumVulnerable Code
js if (json && typeof json.miniprogramRoot === "string" && json.miniprogramRoot.trim()) { miniprogramRoot = json.miniprogramRoot.replace(/^\.\//, ""); } const ign = json && json.packOptions && json.packOptions.ignore; if (Array.isArray(ign)) packIgnore = ign; } const mpAbs = path.resolve(absRoot, miniprogramRoot);Technical Analysis
The scanner treats
project.config.jsonas project-controlled input and uses itsminiprogramRootvalue to derive the directory it will inspect. Removing a leading./does not prevent either an absolute path or traversal sequences such as../../.path.resolve(absRoot, miniprogramRoot)normalizes such input but does not enforce that the result remains beneathabsRoot. Later scanner operations usempAbsto locateapp.json, page configuration files, and recursively scanned.wxml,.wxss,.less,.js,.ts, and.wxsfiles.Consequently, a project author can redirect the scanner outside the project directory selected by the user. Relevant source snippets and paths may subsequently appear in scanner JSON and the generated
MIGRATION-MAP.md.Attack Path
-
An attacker prepares a project containing a
project.config.jsonwith a value such as:json { "miniprogramRoot": "../../other-project" } -
The user or Agent invokes the documented scan against the attacker-controlled project:
bash node scripts/scan.mjs <program-root> -
The scanner resolves the configured value to a location outside the selected project root without checking containment.
-
If that external location contains a suitable
app.json, the scanner reads its configuration and recursively examines supported source files. -
Findings containing external file paths, line numbers, source snippet ...[truncated 865 chars]
-
- Remediation
View remediation
Remediation Suggestions
-
Reject absolute
miniprogramRootvalues. -
Resolve and canonicalize both the selected project root and candidate Mini Program root, including symlinks.
-
Require the canonical candidate to equal the canonical project root or remain beneath it:
js const canonicalRoot = fs.realpathSync(absRoot); const candidate = path.resolve(canonicalRoot, miniprogramRoot); const canonicalCandidate = fs.realpathSync(candidate); if ( canonicalCandidate !== canonicalRoot && !canonicalCandidate.startsWith(canonicalRoot + path.sep) ) { return fail("miniprogramRoot escapes the selected project root"); } const mpAbs = canonicalCandidate; -
Apply equivalent containment checks to configured ignore paths and any future project-controlled paths before filesystem access.
-
Add regression tests covering
../, nested traversal, absolute paths, and symlink-based escapes. -
Return a structured blocker instead of following a path that falls outside the authorized project.
-
