security: fix path traversal in collaborative scanner session loading#30
Merged
zakirkun merged 1 commit intoMay 7, 2026
Conversation
…ive scanner
The `_load_session()` method constructed a file path by interpolating the
`session_id` parameter directly into `Path('data/sessions') / f"{session_id}.json"`
without any validation. A malicious session ID containing path traversal
characters (e.g., `../../etc/config`) could read arbitrary `.json` files
from the operator's filesystem.
This commit:
- Adds `_validate_session_id()` that enforces the expected format: exactly
16 lowercase hex characters (matching `_generate_session_id()` output)
- Rejects any session_id that doesn't match, with a warning log
- Prevents path traversal by ensuring no `/`, `\`, `..`, or other
filesystem metacharacters can appear in the session_id
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
_load_session()used unsanitizedsession_idin file path construction../../etc/configcould read arbitrary.jsonfiles from the operator's filesystemSecurity Impact
_load_session("../../etc/something")would attempt to readdata/sessions/../../etc/something.json^[a-f0-9]{16}$is rejected with a warningChanges
modules/collaboration/collaborative_scanner.py: Added_validate_session_id()static method, applied before file path construction in_load_session()Test plan
../../etc/passwdas session_id returnsNoneand logs warning🤖 Generated with Claude Code