Skip to content

Scope Runs API by session key - #42459

Closed
necoweb3 wants to merge 1 commit into
NousResearch:mainfrom
necoweb3:fix/runs-session-key-scope
Closed

Scope Runs API by session key#42459
necoweb3 wants to merge 1 commit into
NousResearch:mainfrom
necoweb3:fix/runs-session-key-scope

Conversation

@necoweb3

@necoweb3 necoweb3 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This stores the creating request's X-Hermes-Session-Key for each /v1/runs run and enforces that owner key on the run follow-up endpoints.

Why

The API server allows multiple clients to share one API_SERVER_KEY while using X-Hermes-Session-Key as the per-user/channel boundary. POST /v1/runs already parses and forwards that key, but the follow-up endpoints only checked the bearer token and run_id. A caller with the same API key and a different session key could read another run's status, attach to events, resolve approvals, or stop the run if it knew the run_id.

Wrong-key requests now return 404 so the run's existence is not disclosed.

Changes

  • Add a run_id -> X-Hermes-Session-Key owner map for API runs.
  • Check the owner key in:
    • GET /v1/runs/{run_id}
    • GET /v1/runs/{run_id}/events
    • POST /v1/runs/{run_id}/approval
    • POST /v1/runs/{run_id}/stop
  • Clean up the owner map with the existing run lifecycle cleanup.
  • Add regression coverage for wrong-key status, events, approval, and stop attempts.

Tests

python -m pytest tests/gateway/test_api_server_runs.py -k "session_key or RunStatus or RunEvents or StopRun" -q --timeout-method=thread
19 passed, 7 deselected

@liuhao1024

Copy link
Copy Markdown
Contributor

LGTM. The run-scoping mirrors the session-scoping pattern from #42460 cleanly:

  • _authorize_run_session_key correctly returns None (allow) when the run has no owner key, preserving backward compatibility for unauthenticated callers.
  • The owner key is stored alongside the run on creation and cleaned up on completion — no stale entries.
  • Authorization is checked on all three run-specific endpoints (status, events, approval).
  • The 404 response (not 403) is the right choice — it doesn't leak the existence of runs the caller can't access.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/auth Authentication, OAuth, credential pools labels Jun 9, 2026
@necoweb3
necoweb3 force-pushed the fix/runs-session-key-scope branch from 3c5dda2 to 484cb08 Compare June 26, 2026 16:25
@necoweb3

Copy link
Copy Markdown
Contributor Author
Rebased this PR onto current `origin/main` and reran the focused Runs API coverage.

Validation:

```text
python -m pytest tests/gateway/test_api_server_runs.py -q --timeout-method=thread
26 passed

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

Labels

area/auth Authentication, OAuth, credential pools comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants