Fix(systemutils): resolve missing filepath allowlist validation in read_config#450
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(systemutils): resolve missing filepath allowlist validation in read_config#450Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
Root cause: read_config accepted any filepath string including .env with no validation, returning credential-shaped mock content unconditionally. Solution: Introduce ALLOWED_CONFIG_PATHS frozenset at module level and raise ValueError for any filepath not in the allowlist before returning content. Impact: Deterministic rejection of sensitive paths (.env, arbitrary traversal). No change to behavior for permitted paths. Zero regression risk. Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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 #395
Adds filepath allowlist validation to
read_configinfinbot/mcp/servers/systemutils/server.py.Without this guard, sensitive files like
.envwere silently accepted and returnedcredential-shaped mock content training the LLM to expect secrets from config reads.
Problem
read_configaccepted any string asfilepathwith no validation. Calling it with.envreturned a mock response containing
DATABASE_URL,SECRET_KEY, and other credential fields.The tool's own docstring listed
.envas a suggested example path, reinforcing the behavior.Root Cause
No allowlist existed between receiving
filepathand returning the mock response.The tool passed the raw argument directly into the return payload:
Solution
1. Added
ALLOWED_CONFIG_PATHSfrozenset at module level2. Added guard at the top of
read_configbefore any content is returnedPermitted paths continue to work identically. All other paths including
.env,empty strings, and traversal attempts like
../../etc/passwdnow raiseValueError.Impact
ValueErroron invalid input standard Python conventionTesting
Tasks
read_configno filepath allowlist existedALLOWED_CONFIG_PATHSfrozenset at module level with legitimate config pathsValueErrorguard inread_configbefore mock content is returned.envand unlisted paths now raiseValueErrortest_su_cfg_001andtest_su_cfg_003pass