fix(skills): prevent path traversal in LocalSkillSource#1228
fix(skills): prevent path traversal in LocalSkillSource#1228adilburaksen wants to merge 1 commit into
Conversation
|
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? |
|
@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? |
b0f2e30 to
8752425
Compare
|
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. |
|
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. |
|
@sherryfox, Could you please review this. |
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.
8752425 to
0cac4e9
Compare
|
Rebased onto current |
Summary
LocalSkillSourceresolves caller-suppliedskillNameandresourcePathstrings directly onto the file system without validating that the resulting
path remains within
skillsBasePath. A crafted value such as../../../etc/passwdpasses theFiles.exists()check (the OSstatcallfollows
..segments) and is returned as a valid resource path, enablingarbitrary file reads from the host.
Affected methods:
findResourcePath,listResources,findSkillMdPath.Fix
Added a private
validatePathWithinBase(Path base, String component)helperthat rejects:
/etc/passwd)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:testLoadResource_pathTraversalInSkillName../other-dirSkillSourceException"Path traversal detected"testLoadResource_pathTraversalInResourcePath../../../etc/passwdSkillSourceException"Path traversal detected"testLoadResource_absoluteResourcePath/etc/passwdSkillSourceException"Absolute paths are not allowed"testListResources_pathTraversalInSkillName../../etcSkillSourceException"Path traversal detected"testListResources_pathTraversalInResourceDirectory../other-skillSkillSourceException"Path traversal detected"