Skip to content

fix(agui,harness): propagate runtime context and harden shell working_directory - #1780

Closed
guslegend0510 wants to merge 5 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1777-shell-namespace-escape
Closed

guslegend0510 wants to merge 5 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1777-shell-namespace-escape

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

What

  • 为 AGUI 请求链路补上 RuntimeContext 透传,避免通过 AGUI 进入时丢失会话上下文。
  • 收紧 ShellExecuteTool 的 working_directory,拒绝绝对路径和 .. 逃逸,并对 cd 参数做 shell quoting。

Why

Tests

  • mvn -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui,agentscope-harness -am -DskipITs test "-Dtest=AguiAgentAdapterTest,AguiRequestProcessorTest,ShellExecuteToolTest"

@guslegend0510
guslegend0510 requested a review from a team June 16, 2026 14:43
@codecov

codecov Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.29412% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gentscope/harness/agent/tool/ShellExecuteTool.java 77.27% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan area/ext/integration External protocols & middleware integrations area/harness agentscope-harness (test/runtime support) labels Jun 17, 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

This PR adds RuntimeContext propagation through the AGUI request pipeline and hardens ShellExecuteTool against path traversal. The shell path validation correctly blocks absolute paths, .. traversal, and illegal characters. However, the RuntimeContext API plumbing is incomplete — no concrete Agent implementation overrides the new 3-parameter stream() method, so the runtime context is silently dropped by default. The default implementation also delegates to a @Deprecated(forRemoval=true) method, creating a future compilation hazard.

return sb.toString();
}

private static String validateWorkingDirectory(String workingDirectory) {

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.

[recommended] Missing null-byte injection protection. When workingDirectory contains \0, some shell/native layers may truncate the path (e.g., cd 'safe\0/../../etc'). Add a null-byte check before the Path.of() validation: if (workingDirectory.indexOf('\0') >= 0) throw new IllegalArgumentException("working_directory must not contain null bytes");

* @param runtimeContext Per-call runtime context, or {@code null}
* @return Flux of events emitted during execution
*/
default Flux<Event> stream(

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.

[recommended] RuntimeContext is silently dropped by default. No concrete Agent implementation overrides the new 3-parameter stream(List, StreamOptions, RuntimeContext). The default implementation delegates to the 2-parameter version, discarding the RuntimeContext. Document this clearly in the Javadoc: "Default implementation drops runtimeContext; concrete agents must override to enable propagation." Also note that the default delegates to a @Deprecated(forRemoval=true) method in StreamableAgent — when that interface is removed, this default will fail to compile.

@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

This PR adds RuntimeContext propagation through the AGUI request pipeline and hardens ShellExecuteTool against path traversal. The shell path validation correctly blocks absolute paths, .. traversal, and illegal characters. However, the RuntimeContext API plumbing is incomplete — no concrete Agent implementation overrides the new 3-parameter stream() method, so the runtime context is silently dropped by default. The default implementation also delegates to a @Deprecated(forRemoval=true) method, creating a future compilation hazard.

return sb.toString();
}

private static String validateWorkingDirectory(String workingDirectory) {

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.

[recommended] Missing null-byte injection protection. When workingDirectory contains \0, some shell/native layers may truncate the path (e.g., cd 'safe\0/../../etc'). Add a null-byte check before the Path.of() validation: if (workingDirectory.indexOf('\0') >= 0) throw new IllegalArgumentException("working_directory must not contain null bytes");

* @param runtimeContext Per-call runtime context, or {@code null}
* @return Flux of events emitted during execution
*/
default Flux<Event> stream(

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.

[recommended] RuntimeContext is silently dropped by default. No concrete Agent implementation overrides the new 3-parameter stream(List, StreamOptions, RuntimeContext). The default implementation delegates to the 2-parameter version, discarding the RuntimeContext. Document this clearly in the Javadoc: "Default implementation drops runtimeContext; concrete agents must override to enable propagation." Also note that the default delegates to a @Deprecated(forRemoval=true) method in StreamableAgent — when that interface is removed, this default will fail to compile.

@guslegend0510
guslegend0510 deleted the fix/issue-1777-shell-namespace-escape branch June 18, 2026 00:18
* @param runtimeContext Per-call runtime context, or {@code null}
* @return Flux of events emitted during execution
*/
default Flux<Event> stream(

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.

Event will gradually be replaced by AgentEvent, would you like to reimplement the AGUI integration with AgentEvent?

@guslegend0510 guslegend0510 Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这次 PR 只是在 deprecated 的 stream(..., RuntimeContext) 上补一个兼容 overload,目的是保持旧 API 行为一致,不打算在这里改 AGUI 的事件体系。AgentEvent 的 runtimeContext 版本已经在 ReActAgent#streamEvents(..., RuntimeContext) 和 HarnessAgent#streamEvents(..., RuntimeContext) 上实现了,AGUI 迁移会放到单独的 PR 里。
这个PR已经移动到#1814 ,这里面了
@chickenlj

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/ext/integration External protocols & middleware integrations 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.

4 participants