Skip to content

agent: 限制工具资源并收紧网络信任边界 - #5

Open
wen227 wants to merge 1 commit into
boluochoufeng:mainfrom
wen227:optimize/resource-safety
Open

agent: 限制工具资源并收紧网络信任边界#5
wen227 wants to merge 1 commit into
boluochoufeng:mainfrom
wen227:optimize/resource-safety

Conversation

@wen227

@wen227 wen227 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

变更

  • 将 Bash 的 stdout/stderr 改为并发流式排空,每路只保留前 20 KB,同时记录完整字节数和截断状态。
  • Unix 下为 Bash 命令建立独立进程组,在超时或任务取消时终止普通后代进程。
  • read_file 改为有界单行读取;超长行只保留 2 KB 前缀,但仍排空并校验完整 UTF-8 内容。
  • 禁止 WebFetch 使用系统代理,确保所有目标地址继续经过 DNS/SSRF 检查。
  • CLI 不再隐式加载工作区 .env,并同步更新依赖和 README。
  • 将任意非 UTF-8 文件名测试限定到 Linux,恢复 macOS 测试基线。

行为变化

  • API Key 需要由 shell、终端配置或可信进程管理器注入;工作区 .env 不再自动加载。
  • WebFetch 始终直接连接目标,不再遵循 HTTP_PROXYHTTPS_PROXYALL_PROXY

验证

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo check --workspace --all-targets
  • cargo doc --workspace --no-deps
  • cargo test --workspace:741 passed,4 ignored,0 failed

新增回归覆盖超大双流输出、超长/跳过行、跨缓冲区 UTF-8、超时/取消后代清理,以及代理环境隔离。

Copilot AI lite review requested due to automatic review settings August 9, 2026 01:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens the agent’s trust boundary and resource limits across tools, focusing on preventing untrusted workspace configuration from influencing network/runtime behavior and ensuring tool outputs are bounded and safely drained.

Changes:

  • Disable implicit workspace .env loading in the CLI and document the new expectation for injecting API keys.
  • Force web_fetch to ignore system proxy environment variables so DNS/SSRF checks remain effective end-to-end, and add regression coverage.
  • Harden tool I/O: bound read_file line retention while still draining/validating full UTF-8, and make bash output draining concurrent with output caps and descendant cleanup.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Documents that .env is no longer implicitly loaded and recommends trusted env injection.
crates/kuncode-cli/src/main.rs Removes dotenvy auto-loading from the CLI entrypoint.
crates/kuncode-cli/Cargo.toml Drops dotenvy dependency from the CLI crate.
crates/kuncode-agent/src/tool/web_fetch/tests.rs Adds regression test ensuring system proxy env vars are ignored.
crates/kuncode-agent/src/tool/web_fetch/address.rs Removes proxy-host exemption logic from the guarded resolver.
crates/kuncode-agent/src/tool/web_fetch.rs Disables proxy discovery and uses the direct-only guarded resolver.
crates/kuncode-agent/src/tool/filesystem/read_file.rs Implements bounded per-line retention with full drain + UTF-8 validation; adds tests.
crates/kuncode-agent/src/tool/filesystem/ls.rs Restricts non-UTF-8 filename test to Linux to match platform behavior.
crates/kuncode-agent/src/tool/filesystem/glob.rs Restricts non-UTF-8 filename test to Linux to match platform behavior.
crates/kuncode-agent/src/tool/bash.rs Concurrently drains stdout/stderr with caps, records truncation, and kills Unix process groups on timeout/cancel; adds tests.
Cargo.lock Removes dotenvy from the resolved dependency graph.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +263 to +268
impl Drop for ManagedChild {
fn drop(&mut self) {
if self.cleanup_armed {
self.signal_termination();
}
}
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.

2 participants