fix(skills): prevent path traversal in LocalSkillSource#1228
Open
adilburaksen wants to merge 1 commit into
Open
fix(skills): prevent path traversal in LocalSkillSource#1228adilburaksen wants to merge 1 commit into
adilburaksen wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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"