T09 · Insecure Skill Coding Practices
- Location
hepan-cli/src/engine/computeCompat.js:15- Finding
Path Traversal in User-Controlled Rule Pack Resolution
- Content
View full analysis
Vulnerability Details
File Location:
hepan-cli/src/engine/computeCompat.js, lines 15–23
Vulnerability Type: Path traversal and unintended local file access
Risk Level: Mediumjs function loadRulePack(ruleVersion) { const segs = String(ruleVersion).split("/").filter(Boolean); if (segs.length < 1) throw new Error("rule_version empty"); const fileName = `${segs[segs.length - 1]}.json`; const dirs = segs.slice(0, -1); const full = path.join(RULES_ROOT, ...dirs, fileName); if (!fs.existsSync(full)) { throw new Error(`unknown rule_version: ${ruleVersion} (path ${full})`); } return JSON.parse(fs.readFileSync(full, "utf8")); }Technical Analysis
The
rule_versionvalue originates from the JSON input supplied to the CLI. The function splits this value into path components and passes them topath.join()without rejecting..components or verifying that the resolved path remains underRULES_ROOT.Although
path.join()normalizes the path, normalization does not enforce directory containment. An input containing traversal components can therefore resolve to a.jsonfile outside the intended rules directory. The function then performs an existence check and reads the resulting file.Exploitation is limited to files whose resolved names end in
.jsonand which are readable by the Node.js process. To complete normal scoring, the loaded JSON must also resemble the expected rule-pack schema. However, even incompatible JSON files can be probed because missing files, malformed JSON, and schema-related failures produce distinguishable errors. The error for a missing rule also discloses the resolved filesystem path.Attack Path
- An attacker obtains access to the CLI input channel or to an application that forwards requests to it.
- The attacker supplies otherwise acceptable
chart_aandchart_bobjects. - The attacker sets
rule_versionto a traversal valu ...[truncated 1078 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer an explicit allowlist that maps supported identifiers such as
compat/v1to fixed rule-pack paths. - Reject absolute paths and any path segment equal to
.or... - Resolve the candidate with
path.resolve()and verify that it remains below the canonical rules directory:js const rulesRoot = path.resolve(RULES_ROOT); const candidate = path.resolve(rulesRoot, ...dirs, fileName); if (!candidate.startsWith(`${rulesRoot}${path.sep}`)) { throw new Error("invalid rule_version"); } - Validate
rule_versionagainst a restrictive pattern such as^compat/v[0-9]+$if that matches the intended versioning model. - Validate the loaded JSON against a strict rule-pack schema before using it.
- Return generic client-facing errors and do not disclose resolved filesystem paths.
- Add regression tests covering
.., absolute paths, encoded traversal variants, empty segments, unsupported versions, and symlinks that point outside the rules directory.
- Prefer an explicit allowlist that maps supported identifiers such as
