Skip to content

fix(skills): prevent path traversal in LocalSkillSource#1228

Open
adilburaksen wants to merge 1 commit into
google:mainfrom
adilburaksen:fix/local-skill-source-path-traversal
Open

fix(skills): prevent path traversal in LocalSkillSource#1228
adilburaksen wants to merge 1 commit into
google:mainfrom
adilburaksen:fix/local-skill-source-path-traversal

Conversation

@adilburaksen
Copy link
Copy Markdown

Summary

LocalSkillSource resolves caller-supplied skillName and resourcePath
strings directly onto the file system without validating that the resulting
path remains within skillsBasePath. A crafted value such as
../../../etc/passwd passes the Files.exists() check (the OS stat call
follows .. segments) and is returned as a valid resource path, enabling
arbitrary file reads from the host.

Affected methods: findResourcePath, listResources, findSkillMdPath.

Fix

Added a private validatePathWithinBase(Path base, String component) helper
that rejects:

  • absolute path components (e.g. /etc/passwd)
  • components whose normalized, absolute resolution escapes base
    (e.g. ../../secret)

The check mirrors the boundary enforcement already present in the Go
implementation (filesystem_source.go).

Tests

Five new test cases in LocalSkillSourceTest:

Test Input Expected
testLoadResource_pathTraversalInSkillName skillName ../other-dir SkillSourceException "Path traversal detected"
testLoadResource_pathTraversalInResourcePath resourcePath ../../../etc/passwd SkillSourceException "Path traversal detected"
testLoadResource_absoluteResourcePath resourcePath /etc/passwd SkillSourceException "Absolute paths are not allowed"
testListResources_pathTraversalInSkillName skillName ../../etc SkillSourceException "Path traversal detected"
testListResources_pathTraversalInResourceDirectory resourceDirectory ../other-skill SkillSourceException "Path traversal detected"

Add input validation to LocalSkillSource to ensure skill names and
resource paths cannot escape the skills base directory via path
traversal sequences (e.g. "../../../etc/passwd") or absolute paths
(e.g. "/etc/passwd").

The new validatePathWithinBase() helper normalizes and resolves each
caller-supplied path component against its parent directory, then
checks that the result still starts with that parent. This mirrors
the boundary check already present in the Go implementation
(filesystem_source.go).

Affected methods: findResourcePath, listResources, findSkillMdPath.
Corresponding tests added for all traversal and absolute-path cases.
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.

1 participant