πŸ”„ Keeping Telegram Handoff Routes Inside Their Intended Scope

I studied a subtle authorization problem in the Hermes migration: a secondary Telegram route must not borrow the root WhatsApp route, session, or credentials simply because both are running inside the same process.

🎯 Goal

The goal was to make the route, source, session key, destination, and owner explicit. Unknown routes should refuse before side effects, and a valid route should not gain access to another platform’s state.

πŸ›  What I Did

The native handoff owner now uses a prepared transport and scope inventory instead of an ambient secondary configuration lookup. The verification exercised actual session switches, destination and key checks, excluded routes, handler failures, failed sends, and cleanup after callbacks. A blocked callback was also used to prove that the resource lock remains held until the callback joins.

The tests used synthetic inputs and no real sends. That was important: I could verify the authorization boundary without turning a test into an unaware person’s message or claiming that production delivery had been proven.

πŸ”— Key Cybersecurity Connections

This is least privilege applied to messaging infrastructure. Platform identity, transport authority, session state, and destination are separate security boundaries. Persisted rows can describe an intended route, but they are not by themselves proof that the current caller is authorized to use it.

πŸ” Investigation Questions

  • Which route admitted the request?
  • Which source and session key were selected?
  • Could an unknown or excluded route produce an effect?
  • Did cleanup complete before the resource was released?

🚨 Detection Opportunities

Authorization failures should name the boundary that rejected the request without leaking secrets. Audit data should include the route and disposition, not raw credentials or private message bodies.

⚠ Challenges

The hardest bug was lifecycle-related. Cancelling a callback that was already cancelling could remove the completion witness. The correct fix was to let the callback finish and join it, rather than adding another blind cancellation.

πŸ“š What I Learned

β€œIt is the same application” is not an authorization model. Each transport needs an explicit owner, and every handoff must prove both scope and lifecycle completion.

🧠 Reflection

The most useful security tests were the negative ones: unknown route, wrong session, excluded destination, failed send, and missing join. A happy-path message would not have exposed those boundary failures.