Skip to content

fix(pr1780): harden shell execute and stream context - #1814

Closed
guslegend0510 wants to merge 8 commits into
agentscope-ai:mainfrom
guslegend0510:pr-1780-main
Closed

guslegend0510 wants to merge 8 commits into
agentscope-ai:mainfrom
guslegend0510:pr-1780-main

Conversation

@guslegend0510

@guslegend0510 guslegend0510 commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

This PR hardens two areas highlighted in review feedback:

  • ShellExecuteTool now validates working_directory before building the shell command.

  • It rejects absolute paths, .. traversal, and null bytes.

  • It also quotes the directory path before prepending cd, which avoids shell parsing issues.

  • Added regression coverage for safe quoting and unsafe path rejection.

  • Agent adds a new default stream(List<Msg>, StreamOptions, RuntimeContext) overload.

  • The default implementation preserves backward compatibility by delegating to the legacy two-argument stream(...).

  • Added a regression test proving the new overload falls back to the old path.

Validation:

  • mvn -pl agentscope-harness,agentscope-core -Dtest=ShellExecuteToolTest,AgentStreamingTest test
  • mvn -pl agentscope-harness,agentscope-core spotless:check
  • mvn -pl agentscope-harness,agentscope-core spotless:apply

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Close #1777

@guslegend0510
guslegend0510 requested a review from a team June 17, 2026 23:59
@codecov

codecov Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gentscope/harness/agent/tool/ShellExecuteTool.java 95.65% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@guslegend0510

Copy link
Copy Markdown
Contributor Author

@AgentScopeJavaBot @AgentScopeTeam 麻烦检查一下代码

@guslegend0510

Copy link
Copy Markdown
Contributor Author

针对于前面的 #1780
image
image

已处理,ShellExecuteTool 已在路径校验前增加 NUL 字符保护,并补充了 Windows / UNC / 空字节 / .. 的回归测试;Agent.stream(List, StreamOptions, RuntimeContext) 也保留了默认回退实现,并在 Javadoc 中说明了行为,同时补了三参 stream 的回归测试。

@guslegend0510

Copy link
Copy Markdown
Contributor Author
image 已补充对应分支测试,ShellExecuteTool 的 workingDirectory 缺省、输出截断、空值校验和路径解析失败场景均已覆盖,PR 已更新。

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan area/harness agentscope-harness (test/runtime support) labels Jun 18, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

@guslegend0510

Copy link
Copy Markdown
Contributor Author

@chickenlj 麻烦您审核一下我这个PR,谢谢您

@guslegend0510

Copy link
Copy Markdown
Contributor Author
image 这个已经回复了

@chickenlj

Copy link
Copy Markdown
Collaborator

Thanks. See #1834

@chickenlj chickenlj closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Shell execution can escape LocalFilesystemWithShell RuntimeContext namespace

4 participants