# 漏洞总结 ## 漏洞概述 OpenClaw 的 SSH 沙箱上传功能存在安全漏洞,允许攻击者通过符号链接(symlinks)逃逸出沙箱环境。具体来说,当上传包含符号链接的目录时,如果符号链接指向沙箱外的路径,攻击者可以利用这些链接访问或修改沙箱外的文件。 ## 影响范围 - **受影响版本**:v2026.4.26-beta.1 及更早版本 - **影响组件**:SSH 沙箱上传功能 - **潜在风险**:攻击者可能通过符号链接逃逸出沙箱,访问或修改沙箱外的文件,导致数据泄露或系统被篡改。 ## 修复方案 1. **拒绝逃逸符号链接**:在上传过程中,拒绝任何指向沙箱外的符号链接。 2. **更新代码**:修改 `src/agents/sandbox/ssh.ts` 文件中的 `uploadDirectoryToSshTarget` 函数,确保在上传前检查并拒绝逃逸符号链接。 3. **添加测试用例**:在 `src/agents/sandbox/ssh.test.ts` 中添加测试用例,验证修复后的代码能够正确拒绝逃逸符号链接。 ## POC 代码 以下是修复后的代码片段,展示了如何拒绝逃逸符号链接: ```typescript async function assertSafeUploadSymlinks(localDir: string): Promise { const rootDir = path.resolve(localDir); await walkDirectory(rootDir); async function walkDirectory(currentDir: string): Promise { const entries = await fs.readdir(currentDir, { withFileTypes: true }); for (const entry of entries) { const entryPath = path.join(currentDir, entry.name); if (entry.isSymbolicLink()) { try { const resolvedPath = await resolvedBoundaryPath({ absolutePath: entryPath, rootPath: rootDir, boundaryLabel: "SSH sandbox upload tree", }); if (resolvedPath !== entryPath) { const relativePath = path.relative(rootDir, entryPath).split(path.sep).join("/"); throw new Error(`SSH sandbox upload refuses symlink escaping the workspace: ${relativePath}`, { cause: error }); } } catch (error) { continue; } } if (entry.isDirectory()) { await walkDirectory(entryPath); } } } } ``` 此代码通过 `assertSafeUploadSymlinks` 函数检查上传目录中的所有符号链接,确保它们不指向沙箱外的路径。如果检测到逃逸符号链接,则抛出错误。