Skip to content

Commit 6e306c8

Browse files
committed
fix(agents): prevent path traversal in AgentTool config_path resolution
Absolute config_path values were accepted unconditionally, and relative paths were joined without boundary validation, allowing traversal outside the agent directory via "../../../etc/passwd" style inputs. Fix: reject absolute paths; normalize and verify the resolved path stays within the parent agent's directory before loading.
1 parent 5ee51fd commit 6e306c8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

core/src/main/java/com/google/adk/agents/ConfigAgentUtils.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,18 @@ private static BaseAgent resolveSubAgentFromConfigPath(
247247
BaseAgentConfig.AgentRefConfig subAgentConfig, Path configDir) throws ConfigurationException {
248248

249249
String configPath = subAgentConfig.configPath().trim();
250-
Path subAgentConfigPath;
251250

252251
if (Path.of(configPath).isAbsolute()) {
253-
subAgentConfigPath = Path.of(configPath);
254-
} else {
255-
subAgentConfigPath = configDir.resolve(configPath);
252+
throw new ConfigurationException(
253+
"Absolute paths are not allowed in AgentTool config_path: " + configPath);
254+
}
255+
256+
Path subAgentConfigPath = configDir.resolve(configPath).normalize().toAbsolutePath();
257+
Path canonicalConfigDir = configDir.normalize().toAbsolutePath();
258+
259+
if (!subAgentConfigPath.startsWith(canonicalConfigDir)) {
260+
throw new ConfigurationException(
261+
"Path traversal detected: config_path resolves outside agent directory: " + configPath);
256262
}
257263

258264
if (!Files.exists(subAgentConfigPath)) {

0 commit comments

Comments
 (0)