示例工程 62-workspace-shell-sandbox

62-workspace-shell-sandbox/app/README.md

markdown · 1.4 KB

# 62-workspace-shell-sandbox / app

工作区边界与 Shell 沙箱:路径规范化、绝对路径拒绝、`../` 越界、符号链接逃逸、
命令白名单、元字符拦截、超时与输出上限、10 条审计与 10 项自检。离线。

## 运行

```bash
pnpm --filter @tutorial/62-workspace-shell-sandbox-app start
pnpm --filter @tutorial/62-workspace-shell-sandbox-app smoke
pnpm --filter @tutorial/62-workspace-shell-sandbox-app shots
```

## smoke 输出

```json
{"evt":"smoke","ok":true,"score":100,"checks":10,"passed":10,
 "scenarios":10,"audit":10,
 "inside":true,"outside":true,"absolute":true,"symlink":true,
 "blocked":true,"metachar":true,"timeout":true,"truncated":true}
```

## 结构

- `shared/sandbox.ts`:路径规范化、realpath 模拟、命令白名单、超时与输出上限
- `main/index.ts`:场景执行、审计、10 项自检
- `src/App.ts`:工作区卡、Shell 策略卡、审计表

## testid

| testid | 用途 |
| --- | --- |
| `root-path` / `symlinks` | 工作区与链接 |
| `path-scenarios` / `last-path` | 路径场景与结果 |
| `allowlist` / `shell-scenarios` / `last-shell` | 命令策略与结果 |
| `audit` / `audit-row` | 审计 |
| `checks` / `check-row` | 自检 |

## 已知限制

- 不访问真实文件系统,符号链接与路径解析为纯字符串模拟。
- 命令执行为模拟输出,不启动子进程。
- 审计在内存里,重启即清空。