fix(security): block path traversal in skill_view file_path parameter#221
fix(security): block path traversal in skill_view file_path parameter#221Farukest wants to merge 1 commit into
Conversation
skill_view accepts a file_path parameter to read files within a skill directory, but did not validate the path. Passing file_path="../../.env" allowed reading arbitrary files outside the skill directory, including API keys and other sensitive data. Added path traversal checks matching the existing pattern in skill_manager_tool.py: reject ".." in path components and verify the resolved path stays within the skill directory.
skill_view accepted arbitrary file_path values like '../../.env' and would read files outside the skill directory, exposing API keys and other sensitive data. Added two layers of defense: 1. Reject paths with '..' components (fast, catches obvious traversal) 2. resolve() containment check with trailing '/' to prevent prefix collisions (catches symlinks and edge cases) Fix approach from PR #242 (@Bartok9). Vulnerability reported by @Farukest (#220, PR #221). Tests rewritten to properly mock SKILLS_DIR. Closes #220
|
Thanks for reporting the vulnerability and providing a fix @Farukest! Your test approach (mocking We went with PR #242's code fix because it includes a trailing Fixed in commit 1cb2311. |
Makes sense, the trailing slash guard is a better approach. Thanks for the credit @teknium1 👍 |
Starting WorkBranch: Plan
|
Fixed ✓Commit: Changes Made
VerificationTests: 448 passing ✓
Acceptance Criteria
Note: The Railway deployment has the API configured, so it correctly shows AI options. In local dev without API key, users will see "Templates only (AI not configured)" instead of the misleading AI options. |
…usResearch#220) skill_view accepted arbitrary file_path values like '../../.env' and would read files outside the skill directory, exposing API keys and other sensitive data. Added two layers of defense: 1. Reject paths with '..' components (fast, catches obvious traversal) 2. resolve() containment check with trailing '/' to prevent prefix collisions (catches symlinks and edge cases) Fix approach from PR NousResearch#242 (@Bartok9). Vulnerability reported by @Farukest (NousResearch#220, PR NousResearch#221). Tests rewritten to properly mock SKILLS_DIR. Closes NousResearch#220
…usResearch#220) skill_view accepted arbitrary file_path values like '../../.env' and would read files outside the skill directory, exposing API keys and other sensitive data. Added two layers of defense: 1. Reject paths with '..' components (fast, catches obvious traversal) 2. resolve() containment check with trailing '/' to prevent prefix collisions (catches symlinks and edge cases) Fix approach from PR NousResearch#242 (@Bartok9). Vulnerability reported by @Farukest (NousResearch#220, PR NousResearch#221). Tests rewritten to properly mock SKILLS_DIR. Closes NousResearch#220
…usResearch#220) skill_view accepted arbitrary file_path values like '../../.env' and would read files outside the skill directory, exposing API keys and other sensitive data. Added two layers of defense: 1. Reject paths with '..' components (fast, catches obvious traversal) 2. resolve() containment check with trailing '/' to prevent prefix collisions (catches symlinks and edge cases) Fix approach from PR NousResearch#242 (@Bartok9). Vulnerability reported by @Farukest (NousResearch#220, PR NousResearch#221). Tests rewritten to properly mock SKILLS_DIR. Closes NousResearch#220
skill_viewaccepts afile_pathparameter to read files within a skill directory, but does not validate the path for traversal.skill_view("any-skill", file_path="../../.env")reads~/.hermes/.envcontaining API keys.Changes
Added path traversal checks to
tools/skills_tool.pymatching the existing pattern inskill_manager_tool.py:..in path componentsresolve()containment checkTests
Added
tests/tools/test_skill_view_traversal.pywith 4 tests:../../.envis blockedreferences/../../.envis blockedfile_pathstill worksAll 4 tests pass.
Closes #220