Skip to content

fix(gateway): validate user authorization before auto-resume - #56347

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-87d0ec60
Jul 1, 2026
Merged

fix(gateway): validate user authorization before auto-resume#56347
teknium1 merged 2 commits into
mainfrom
hermes/hermes-87d0ec60

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Auto-resume of restart-interrupted gateway sessions now validates the session owner against the current allowlist before synthesizing a recovery turn. Previously the resume path dispatched a full agent turn with no authorization check, so a session whose owner was removed from TELEGRAM_ALLOWED_USERS (or created before the allowlist existed) still received a full agent response on gateway restart (#23778).

Salvage of #47761 by @ygd58 (itself a rebase of the earlier #23800), re-applied at the current _schedule_resume_pending_sessions site and covered with tests.

Changes

  • gateway/run.py _schedule_resume_pending_sessions: check _is_user_authorized(source) before auto-resuming. Unauthorized owners are skipped with a warning log; a raising auth check fails closed (session skipped, not resumed). The gate runs after the adapter-ready check and before the _running_agents slot claim, so a skipped session never claims a slot or persists one.
  • tests/gateway/test_restart_resume_pending.py: two tests — unauthorized owner is skipped (no slot claimed, nothing persisted) and a raising auth check fails closed.

Root cause

The normal inbound path enforces auth (run.py drop-in-active-session guard and the main dispatch gate), but the auto-resume path (startup + platform-reconnect) synthesizes an internal MessageEvent and runs a full turn directly — bypassing that gate. The merged adapter-level hardening (#28492) covers real inbound messages, not this synthetic-event path.

Validation

Result
Targeted suite 80/80 pass (tests/gateway/test_restart_resume_pending.py)
E2E — authorized scheduled=1, turn dispatched (unchanged behavior)
E2E — unauthorized scheduled=0, no slot claimed, nothing persisted, warning logged
E2E — auth raises scheduled=0, fail-closed

Fixes #23778 (auto-resume auth bypass). Closes #47761@ygd58's fix commit authorship preserved via rebase-merge.

Infographic

Auto-resume auth gate

ygd58 and others added 2 commits July 1, 2026 04:28
Auto-resume of restart-interrupted sessions bypassed auth checks.
The session owner was never validated against TELEGRAM_ALLOWED_USERS
(or equivalent) before the synthetic resume event was dispatched. An
attacker with an active session before the allowlist was configured
could receive a full agent response on gateway restart (issue #23778).

Clean rebase of #23800 onto current main (egilewski flagged a merge
conflict in gateway/run.py on the old branch).

Fix: check _is_user_authorized() for the session owner before
scheduling auto-resume. Unauthorized sessions are skipped with a
warning log instead of silently resuming.

Fixes #23778 (partial - auto-resume auth bypass)
Two tests for the auto-resume authorization gate: an unauthorized session
owner is skipped without claiming a _running_agents slot or persisting one,
and a raising auth check fails closed (session skipped, not resumed).
@alt-glitch alt-glitch added type/security Security vulnerability or hardening comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter area/auth Authentication, OAuth, credential pools P1 High — major feature broken, no workaround sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data labels Jul 1, 2026
@teknium1
teknium1 merged commit 04eed93 into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-87d0ec60 branch July 1, 2026 11:54
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 P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway auth bypass — unauthorized user messages processed despite "Unauthorized" log

3 participants