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"

@hemasekhar-p hemasekhar-p self-assigned this Jun 1, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @adilburaksen, thank you for your contribution! We appreciate you taking the time to submit this pull request. I noticed some formatting inconsistencies in the test cases. could you please address these issues and run the full Maven build without skipping the test cases to ensure everything is compliant?

@hemasekhar-p hemasekhar-p added the waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. label Jun 1, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

@adilburaksen, Thank you for your quick response. As per contribution policy, please ensure your PR consists of a single commit. Could you please change your commits accordingly?

@hemasekhar-p hemasekhar-p added waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. and removed waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. labels Jun 1, 2026
@adilburaksen adilburaksen force-pushed the fix/local-skill-source-path-traversal branch from b0f2e30 to 8752425 Compare June 1, 2026 11:39
@adilburaksen

Copy link
Copy Markdown
Author

Thanks for the review @hemasekhar-p. I've applied google-java-format to the test file so it matches the project style now, and I squashed everything down into a single commit as requested.

I also ran the full build with tests enabled (no skips) and it passes, including LocalSkillSourceTest (16 tests, all green). Let me know if anything else is needed.

@hemasekhar-p

Copy link
Copy Markdown
Contributor

Thank you for your update @adilburaksen, Currently this PR is under review by our team, we will keep you posted if any additional information is required. thank you.

@hemasekhar-p

Copy link
Copy Markdown
Contributor

@sherryfox, Could you please review this.

@hemasekhar-p hemasekhar-p added needs review and removed waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. labels Jun 1, 2026
LocalSkillSource resolved the caller-supplied skillName and resourcePath
directly against skillsBasePath with Path.resolve(), which does not
normalize or reject ".." segments. A skill name or resource path such as
"../../etc" / "passwd" therefore escaped skillsBasePath, allowing
arbitrary file read (e.g. /etc/passwd) and directory listing outside the
configured base.

Validate each caller-supplied component against its base directory in
findResourcePath, listResources, and findSkillMdPath: reject absolute
paths and any component whose normalized resolution leaves the base.
Adds tests covering skillName and resourceDirectory traversal.
@adilburaksen adilburaksen force-pushed the fix/local-skill-source-path-traversal branch from 8752425 to 0cac4e9 Compare June 9, 2026 13:11
@adilburaksen

Copy link
Copy Markdown
Author

Rebased onto current main — this is now a clean 2-file diff (the earlier large diff was a stale-branch artifact from an old base). validatePathWithinBase rejects absolute paths and any .. escape, applied in findResourcePath, listResources, and findSkillMdPath, with tests covering skillName and resourceDirectory traversal. PTAL @sherryfox @hemasekhar-p — happy to adjust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants