fix(security): sanitize user-supplied IDs to prevent path traversal#307
Open
warren618 wants to merge 1 commit into666ghj:mainfrom
Open
fix(security): sanitize user-supplied IDs to prevent path traversal#307warren618 wants to merge 1 commit into666ghj:mainfrom
warren618 wants to merge 1 commit into666ghj:mainfrom
Conversation
simulation_id, project_id, report_id, and platform parameters from API requests are used directly in os.path.join() to construct file paths. An attacker can use values like "../../etc" to read/write files or create directories outside the intended data directory. Added validation: reject any ID that differs from its os.path.basename(), which catches path separators and traversal sequences.
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
Fixes #306
User-supplied
simulation_id,project_id,report_id, andplatformare passed directly toos.path.join(), enabling path traversal attacks.Fix
Added validation in all
_get_*_dirmethods: reject any ID whereos.path.basename(id) != id, which catches path separators and..sequences.Changes
backend/app/services/simulation_manager.py—_get_simulation_dir+get_profilesbackend/app/models/project.py—_get_project_dirbackend/app/services/report_agent.py—_get_report_folder3 files, 16 insertions, 4 deletions.