diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-12 09:47:34 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-12 16:36:54 +0200 |
| commit | bf7ff9ec311660318c8562abe03ef4db62475c98 (patch) | |
| tree | 2fd49c42c59e1207574bcf2842b726e4aec82c90 /packages/meshbay-hub/src/meshbay_hub/api/signaling.py | |
| parent | 4cce50f09a73739387d5058a6f8183ebac65ae2c (diff) | |
| download | meshbay-bf7ff9ec311660318c8562abe03ef4db62475c98.tar.gz | |
fix: bound what one member can cost the others
An availability review, prompted by the group claim above: a participant
supplies input — who else bears the cost? Six answers where the cost fell on
someone other than the sender, and none of them needs an attacker.
AV3 `chat_notify` carried a `group_id` the hub believed, so any connected
node could write a notification to every member of any group on the
hub, carrying a display string of its choosing, with its account
having no relation to that group. This is the group claim again, two
hundred lines further down the same socket. Gated on what the node is
registered for, and metered: the fan-out is one write per member. The
budget expires by time rather than on disconnect, or reconnecting
would refill it and a node token is good for an hour.
AV4 A swarm source named its own `endpoint` as free text documented as
"ip:port", so an account could publish a third party's address — H6's
`peer_ip` defect, never applied here. Nothing dials a swarm source
today, which is the only reason it was not already a reflection
primitive. It is a transport and a port now, never a host, and the
number of hashes one account may claim is bounded: rows were keyed
(hash, account) with no cap at all.
AV5 `handle_webrtc_answer` resolved any pending `peer_id` from any node's
socket. The answer is the SDP a browser then connects to. That this
had not happened rested on a uuid4 being unguessable.
AV6 `relay_register` had no authentication of any kind: it compared
`pk_relay` against the approved value, which is a *public* key, so
anyone who could read it could rewrite where the hub tells nodes to
send relayed traffic. The module docstring promised signed JWTs and
`jwt` was imported and never used.
AV7 The node held unlimited peer connections and kept one that never
completed a handshake for the life of the daemon. H6 bounded what one
unauthenticated peer costs; the hub's cap is three offers in flight
per *account*, a limit on each caller and not on the machine, so an
operator's exposure grew with the size of their groups.
AV8 `invite-notify` put a request-supplied `group_name` into the subject
of an email the hub sends under its own domain, to any account, with
no rate limit. The name comes from the group row now.
The tests are two accounts each, in one file that says why: a one-member test
proves a one-member property, and every finding here needed a second person
to exist at all. Each was checked against the unfixed code. Two did not
survive that check and were rewritten — one re-enacted the disconnect path
instead of running it (hence `forget_node`), the other called the reaper
itself and would have passed with the call removed from `handle_offer`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4YmK41VsEURWFdop4EEeT
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/signaling.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/api/signaling.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/signaling.py b/packages/meshbay-hub/src/meshbay_hub/api/signaling.py index a8feae8..b4be3f2 100644 --- a/packages/meshbay-hub/src/meshbay_hub/api/signaling.py +++ b/packages/meshbay-hub/src/meshbay_hub/api/signaling.py @@ -34,6 +34,9 @@ log = logging.getLogger(__name__) router = APIRouter(prefix="/v1/nodes", tags=["signaling"]) _webrtc_answers: dict[str, asyncio.Future] = {} +# peer_id → the node the offer was relayed to. An answer is only accepted +# from that node (see handle_webrtc_answer). +_answer_owner: dict[str, str] = {} class WebRTCOfferRequest(BaseModel): @@ -133,6 +136,7 @@ async def webrtc_offer( peer_id = str(uuid.uuid4()) answer_future: asyncio.Future = asyncio.get_event_loop().create_future() _webrtc_answers[peer_id] = answer_future + _answer_owner[peer_id] = node_id _pending_per_user[current_user.id] = _pending_per_user.get(current_user.id, 0) + 1 try: @@ -157,6 +161,7 @@ async def webrtc_offer( ) finally: _webrtc_answers.pop(peer_id, None) + _answer_owner.pop(peer_id, None) remaining = _pending_per_user.get(current_user.id, 1) - 1 if remaining > 0: _pending_per_user[current_user.id] = remaining @@ -164,13 +169,26 @@ async def webrtc_offer( _pending_per_user.pop(current_user.id, None) -def handle_webrtc_answer(msg: dict) -> None: - """Called from the node WebSocket message loop when a webrtc_answer arrives.""" +def handle_webrtc_answer(msg: dict, node_id: str) -> None: + """Called from the node WebSocket message loop when a webrtc_answer arrives. + + `node_id` is the socket this arrived on, and the answer is accepted only for + a `peer_id` the hub issued to **that** node. The answer carries the SDP the + browser then connects to, so without the check any connected node could + resolve any pending offer and stand in for the node the client asked for. + That it had not happened rested on a uuid4 being unguessable, which is a + reason it was hard, not a reason it was refused. + """ peer_id = msg.get("peer_id") if not peer_id: log.warning("webrtc_answer without peer_id") return + if _answer_owner.get(peer_id) != node_id: + log.warning("Node %s answered an offer it was never sent (peer=%s)", + (node_id or "?")[:8], str(peer_id)[:8]) + return + future = _webrtc_answers.get(peer_id) if future and not future.done(): future.set_result({ |