Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions core/src/main/java/com/google/adk/skills/LocalSkillSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ public LocalSkillSource(Path skillsBasePath) {

@Override
public Single<ImmutableList<String>> listResources(String skillName, String resourceDirectory) {
Path skillDir = skillsBasePath.resolve(skillName);
Path skillDir = skillsBasePath.resolve(skillName).normalize();
if (!isDirectory(skillDir)) {
return Single.error(
new SkillSourceException("Skill not found: " + skillName, SKILL_NOT_FOUND));
}
Path resourceDir = skillDir.resolve(resourceDirectory);
Path resourceDir = skillDir.resolve(resourceDirectory).normalize();
// Prevent path traversal: the resolved resource directory must remain inside
// the skill's own directory. A raw string prefix check on the input is not
// sufficient because "references/../../../../etc" bypasses it.
if (!resourceDir.startsWith(skillDir)) {
return Single.error(
new SkillSourceException(
"Path traversal detected in resource directory: " + resourceDirectory,
RESOURCE_NOT_FOUND));
}
if (!isDirectory(resourceDir)) {
return Single.error(
new SkillSourceException(
Expand Down Expand Up @@ -96,7 +105,17 @@ protected Flowable<SkillMdPath<Path>> listSkills() {

@Override
protected Single<Path> findResourcePath(String skillName, String resourcePath) {
Path file = skillsBasePath.resolve(skillName).resolve(resourcePath);
Path base = skillsBasePath.resolve(skillName).normalize();
Path file = base.resolve(resourcePath).normalize();
// Enforce boundary: the resolved path must remain inside the skill's base
// directory. Without this check, a payload like
// "references/../../../../etc/passwd" passes the startsWith("references/")
// prefix check in LoadSkillResourceTool but resolves outside skillsBasePath.
if (!file.startsWith(base)) {
return Single.error(
new SkillSourceException(
"Path traversal detected: " + resourcePath, RESOURCE_NOT_FOUND));
}
if (!Files.exists(file)) {
return Single.error(
new SkillSourceException("Resource not found: " + file, RESOURCE_NOT_FOUND));
Expand Down