fix(skills): prevent path traversal in LocalSkillSource via normalize + boundary check#1311
Open
herdiyana256 wants to merge 1 commit into
Open
Conversation
The startsWith("references/") prefix check in LoadSkillResourceTool is
bypassed by payloads like "references/../../../../etc/passwd" — the
string prefix matches while the resolved path escapes skillsBasePath.
Fix by calling Path.normalize() on the resolved path and asserting that
it still starts with the expected base directory before any filesystem
access in both findResourcePath() and listResources().
Fixes CWE-22 (Path Traversal).
f0a8a8c to
30ba017
Compare
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
LoadSkillResourceToolvalidatesresourcePathwith a string prefix check(
startsWith("references/"),startsWith("assets/"),startsWith("scripts/")),but this check is trivially bypassed:
"references/../../../../etc/passwd".startsWith("references/") == true // bypassed!
LocalSkillSource.findResourcePath()then resolves the raw path againstskillsBasePathwithout callingPath.normalize()or asserting a boundary,so the OS resolves
..components atFiles.exists()time — resulting inarbitrary file reads outside
skillsBasePath.The same issue exists in
listResources()for theresourceDirectoryparameter.Fix
In
LocalSkillSource.findResourcePath()andlistResources():.normalize()on the resolved pathfile.startsWith(base)— reject if the resolved path escapes the skill directoryThe correct enforcement point is the filesystem layer after resolution,
not a string prefix check on raw user input.
Files Changed
core/src/main/java/com/google/adk/skills/LocalSkillSource.javafindResourcePath(): normalize + boundary checklistResources(): normalize + boundary check onresourceDirectoryTesting