T05 · Unauthorized Access and Privilege Escalation
- Location
index.js:22- Finding
Allowed-Path Validation Can Be Bypassed to Read Unauthorized Files
- Content
View full analysis
filePath.startsWith(root))) { return { error: '路径不在允许范围内' }; } // 根据扩展名选择读取方式 switch (ext) { case '.txt': case '.md': case '.json': return readTextFile(filePath); case '.docx': return await readDocx(filePath); case '.pdf': return await readPdf(filePath); default: return { error: '不支持的文件格式' }; } }; ``` ### Technical Analysis The authorization check applies `String.prototype.startsWith()` directly to an attacker-controlled path. It does not normalize or canonicalize the target before comparing it with an allowed root. This permits several forms of authorization bypass: - **Directory traversal:** A path such as `/workspace/../secret.json` begins with `/workspace` as a string but resolves outside that directory. - **Prefix collision:** If `/workspace` is allowed, a path such as `/workspace-backup/secret.txt` also passes the prefix check. - **Symbolic-link traversal:** A symbolic link located under the workspace can refer to a file outside it. The submitted path passes the string comparison while the filesystem resolves it to an unauthorized target. - **Undefined workspace behavior:** If `OPENCLAW_WORKSPACE` is unset, JavaScript converts the `undefined` search value to the string `"undefined"` when evaluating `startsWith(undefined)`. The implementation therefore does not reliably fail closed. - **Overly broad hard-coded authorization:** The fixed `D:\个人` root grants access independently of the configured workspace and withou ...[truncated 1670 chars]- Remediation
View remediation
