Skip to content

fix(evaluation): Prevent path traversal in local eval managers#5039

Open
shivan4030 wants to merge 3 commits intogoogle:mainfrom
shivan4030:main
Open

fix(evaluation): Prevent path traversal in local eval managers#5039
shivan4030 wants to merge 3 commits intogoogle:mainfrom
shivan4030:main

Conversation

@shivan4030
Copy link
Copy Markdown

This commit adds a strict validation regex (^[a-zA-Z0-9_-.]+$) and explicit .. checks for app_name, eval_set_id, eval_case_id, and eval_set_result_id in LocalEvalSetsManager and LocalEvalSetResultsManager. By sanitizing path parameters, this prevents directory traversal attacks when the FastAPI endpoints attempt to read or modify evaluation JSON files on the local filesystem.

Problem:
The LocalEvalSetsManager and LocalEvalSetResultsManager classes inside src/google/adk/evaluation/ were missing input sanitization for various path routing IDs (app_name, eval_set_id, eval_case_id, and eval_set_result_id). Because these values were blindly passed into os.path.join() when executing operations via adk web endpoints (like GET /apps/{app_name}/eval-sets/{eval_set_id}...), an attacker could craft malicious directory traversal patterns (e.g., ../..) allowing them to traverse out of the target evaluation directory. This introduces a vulnerability where unauthorized users could read or delete sensitive evaluation records (.evalset.json / .evalset_result.json files) belonging to other applications on the server's filesystem.

Solution:
A new _validate_id() logic enforcement was introduced across the board in LocalEvalSetsManager and LocalEvalSetResultsManager. This restricts parameters using a rigid regex pattern (^[a-zA-Z0-9_\-\.]+$) that allows necessary characters like hyphens and floating-point timestamps (which are natively appended to result IDs), but explicitly rejects payloads containing double dots (..). This ensures the adk web router endpoints can strictly read, update, or delete payloads within their expected hierarchical folder paths, permanently patching the unauthenticated scope leakage risk.

@adk-bot adk-bot added the eval [Component] This issue is related to evaluation label Mar 28, 2026
@shivan4030
Copy link
Copy Markdown
Author

@mbalandat @siddharthab, could you please review this PR and approve the CI workflows?

@siddharthab
Copy link
Copy Markdown

Sorry, did you mean to tag me?

@rohityan rohityan self-assigned this Mar 30, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

Hi @shivan4030 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing mypy-diff tests. Also can you fix the formatting errors. You can use autoformat.sh

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 30, 2026
shivan4030 and others added 2 commits March 31, 2026 20:11
This commit adds a strict validation regex (^[a-zA-Z0-9_\-\.]+$) and explicit `..` checks for app_name, eval_set_id, eval_case_id, and eval_set_result_id in LocalEvalSetsManager and LocalEvalSetResultsManager. By sanitizing path parameters, this prevents directory traversal attacks when the FastAPI endpoints attempt to read or modify evaluation JSON files on the local filesystem.
Replaces `hashlib.md5` with `hashlib.sha256` for session key generation
in `mcp_session_manager.py` to mitigate security risks associated with
weak cryptographic hashes. Updated the corresponding unit test to
expect SHA256 hashes.
@shivan4030
Copy link
Copy Markdown
Author

I've updated the PR with the formatting fixes and addressed the mypy issues. Ready for another look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval [Component] This issue is related to evaluation request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants