fix(gateway): reject path-unsafe session_id on /v1/runs#71120
Open
fangliquanflq wants to merge 1 commit into
Open
fix(gateway): reject path-unsafe session_id on /v1/runs#71120fangliquanflq wants to merge 1 commit into
fangliquanflq wants to merge 1 commit into
Conversation
POST /v1/runs forwarded client session_id into AIAgent task_id without the entry-boundary path guard used by chat/session create, so Docker persistent sandboxes could makedirs outside the sandbox root.
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.
What does this PR do?
Reject path-unsafe, control-character, and oversized
session_idvalues onPOST /v1/runsbefore a run is accepted. Client-supplied IDs were passed through asAIAgenttask_id, and Docker persistent sandboxes joinget_sandbox_dir()/docker/task_idthenos.makedirs, so../could create directories outside the sandbox root.Bug Cause
/v1/chat/completions(X-Hermes-Session-Id) andPOST /api/sessionsalready guard withgateway.session._is_path_unsafeplus control-char and length checks.POST /v1/runstookbody.session_id(or a stored id fromprevious_response_id) with no equivalent check, then seteffective_task_id = session_idforagent.run_conversation.Reproduction Steps
terminal.backendto Docker with persistent sandboxes.POST /v1/runswith JSON{"input": "hello", "session_id": "../../pwned"}..../docker/) when the agent starts a Docker environment.Expected: HTTP 400
invalid_session_id, no agent start, no sandbox dirs outside the docker sandbox root.Before fix: run accepted (202);
task_idwith../reaches Dockermakedirsoutside the sandbox root.Fix
APIServerAdapter._reject_unsafe_session_id(control chars +_is_path_unsafe+_MAX_SESSION_HEADER_LEN)./v1/runs, session create, and chatX-Hermes-Session-Idthrough the shared helper so the guard cannot drift.Out of scope:
POST /api/sessions/{id}/forkstill lacks the path-unsafe guard (sibling finding); follow-up PR.Related Issue
No issue - discovered via bug-hunter finding BUG-2 (api_server
/v1/runssession_id path traversal).Type of Change
Changes Made
gateway/platforms/api_server.py- shared_reject_unsafe_session_id; wire create, chat header, and/v1/runstests/gateway/test_api_server_runs.py- reject path-unsafe / control-char / oversizedsession_idHow to Test
POST /v1/runswithsession_id../../pwnedshould return 400 and not create dirs outside the sandbox root.scripts/run_tests.sh tests/gateway/test_api_server_runs.py tests/gateway/test_session_api.py -q scripts/run_tests.sh tests/gateway/test_api_server.py -k "traversal_session_id or provided_session_id" -qChecklist
Code
scripts/run_tests.shon relevant tests and they passDocumentation and Housekeeping
cli-config.yaml.exampleif I added/changed config keys - or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - or N/A_is_path_unsafe)