[security] fix(api-server): scope run approvals by run id - #56129
Merged
Conversation
Collaborator
Salvage of #24212 by @Hinotoi-agent (commit re-anchored to current |
8 tasks
1 task
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
API-server
/v1/runsdangerous-command approval queues are now scoped by the generatedrun_id, so one API run can no longer resolve another run's pending approval.Root cause: the approval queue key was
gateway_session_key or session_id or run_id.session_idis caller-controllable continuity metadata that concurrent runs can intentionally share, so two runs with the samesession_idshared one approval queue — andresolve_all=trueon one run drained the other run's pending dangerous-command approval.Changes
gateway/platforms/api_server.py:approval_session_key = run_id(wasgateway_session_key or session_id or run_id). The two read sites (/v1/runs/{run_id}/approval, stream sweeper) already pull the stored key from_run_approval_sessions[run_id], so they inherit the fix.tests/gateway/test_api_server_runs.py: regression — two runs with the samesession_id, separate pending approvals,resolve_all=trueon the attacker run resolves exactly one and leaves the victim entry untouched.session_id/X-Hermes-Session-Keyremain the conversation/memory scope.once/session/always/denyall preserved, now scoped to the target run.Validation
resolve_all=trueon attacker runresolved: 2, victim unblockedresolved: 1, victim untouchedscripts/run_tests.sh tests/gateway/test_api_server_runs.py -q→ 23/23 passresolve_gateway_approval(run_id, resolve_all=True)against two seeded queues — attacker queue drained, victim's pending approvaleventstays unset.Salvaged from #24212 by @Hinotoi-agent; commit re-anchored to current
main(original diff was rooted at an older revision), authorship preserved.Infographic