Skip to content

Security hardening: path validation, permission hardening, dialog timeout, CI fix#1

Merged
dreamor merged 9 commits into
mainfrom
fix/security-hardening
Jun 18, 2026
Merged

Security hardening: path validation, permission hardening, dialog timeout, CI fix#1
dreamor merged 9 commits into
mainfrom
fix/security-hardening

Conversation

@dreamor

@dreamor dreamor commented Jun 18, 2026

Copy link
Copy Markdown
Owner

安全加固 PR

变更概览

补丁 描述
0001 新增 SafePath 路径验证工具函数
0002 强化 Unix socket (0600) 和目录权限 (0700)
0003 文件读写操作强制路径验证
0004 dialog.handle_next 添加超时防资源泄漏
0005 oneShotScrape 改用参数化 evaluate 防注入
0006 CI release.yml 使用 secrets.NPM_TOKEN
0007 安全测试 + 审计报告

文件变更

  • src/utils/safepath.ts — 新增 SafePath 验证模块
  • src/daemon/server.ts — socket/dir 权限 + 路径验证
  • src/daemon/methods/dialog.ts — 超时机制
  • src/daemon/methods/eval.ts — 参数化 evaluate
  • src/one-shot.ts — 参数化 evaluate
  • src/output.ts / src/utils/paths.ts — 路径验证
  • .github/workflows/release.yml — NPM_TOKEN
  • tests/unit/safepath.test.ts — 安全测试
  • SECURITY_AUDIT_REPORT.md — 审计报告

测试

  • SafePath 单元测试覆盖(正常路径、越界、符号链接、Windows 边界)
  • CI 运行全绿

合规

  • Code review 通过
  • CI build + test 通过

🤖 Generated with Claude Code

wangyeping.wyp and others added 9 commits June 18, 2026 10:03
- validateWritePath: blocks writes to /etc, /proc, /sys, /dev, /boot, /sbin,
  ~/.ssh, ~/.gnupg, ~/.config/systemd
- validateReadPath: blocks reads from /proc, /sys, /dev, ~/.ssh, ~/.gnupg
- Both resolve and normalize paths to prevent traversal attacks (../)

Addresses audit finding H-3 (arbitrary file write) and H-1 (eval_file path traversal)

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
- ensureRoot: create ~/.cloak with mode 0700 (owner-only access)
- server: chmod socket file to 0600 after creation
- server: implement proper stale socket detection via connect probe
  before removing existing socket (was previously deleting blindly)
- server: throw DAEMON_ALREADY_RUNNING if another daemon is active

Addresses audit findings H-2 (socket auth) and M-4 (stale socket race)

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
- output.ts: writeBinaryOut now validates path via validateWritePath()
  before writing screenshots, PDFs, and other binary outputs
- eval.ts: page.eval_file now validates path via validateReadPath()
  before reading and executing file contents in browser context

Addresses audit findings H-1 and H-3

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
…leak

- Default 30s timeout, configurable via 'timeout' param
- On timeout: removes event listener and rejects with TIMEOUT error
- Prevents indefinite Promise hang and listener accumulation

Addresses audit finding M-3

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
- Replace string-concatenated JS with Playwright's parameterized
  evaluate API, passing selector/multi/attr via argument channel
- Eliminates code injection pattern even though JSON.stringify was safe

Addresses audit finding M-1

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
- NODE_AUTH_TOKEN was set to empty string, causing publish failures
- Now references GitHub Actions secret for proper npm authentication

Addresses audit finding M-5

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
- 29 test cases covering write/read path validation
- Tests for sensitive directory blocking, path traversal prevention,
  home directory protection, and safe path allowlisting
- Include full security audit report (SECURITY_AUDIT_REPORT.md)

Co-authored-by: Aone-Agent <aone-agent@alibaba-inc.com>
GitHub Actions jobs don't share workspace by default. E2E job
needs dist/ artifacts from npm run build, but only ran npm ci.
This caused E2E tests to fail with ERR_MODULE_NOT_FOUND for dist/cli.js.
Node 22 ESM requires JSON imports to have 'with { type: "json" }'.
The previous import-from-package.json pattern with moduleResolution:
Bundler doesn't emit this attribute, causing BOOT_ERROR on Node 22.
Switch to createRequire which is JSON-safe without attribute syntax.
@dreamor dreamor merged commit 01070b5 into main Jun 18, 2026
6 checks passed
dreamor added a commit that referenced this pull request Jun 18, 2026
…eout, CI fixes

## 安全加固 + CI 修复

### 安全修复
- 新增 SafePath 路径验证模块(目录遍历防护)
- Unix socket 权限 0600 + 目录权限 0700
- 文件读写强制路径验证
- dialog.handle_next 超时防资源泄漏
- oneShotScrape 参数化 evaluate 防注入

### CI 修复
- E2E job 增加 build 步骤(job 间不共享工作区)
- 修复 Node 22 JSON import 兼容性(createRequire)
- release.yml 使用 secrets.NPM_TOKEN

### 测试
- ✅ Type Check
- ✅ Build
- ✅ Unit Tests (Node 20/22)
- ✅ E2E Tests
- ✅ Lint
- ✅ 新增 SafePath 单元测试覆盖

Closes #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant