aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-common/src')
-rw-r--r--packages/meshbay-common/src/meshbay_common/handshake.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/meshbay-common/src/meshbay_common/handshake.py b/packages/meshbay-common/src/meshbay_common/handshake.py
index dedfeb1..992fe8a 100644
--- a/packages/meshbay-common/src/meshbay_common/handshake.py
+++ b/packages/meshbay-common/src/meshbay_common/handshake.py
@@ -269,6 +269,7 @@ def authorize_token(
hosted_groups: Any | None = None,
denylist: DenylistLike | None = None,
require_scope: str | None = "user",
+ node_pk_b64: str | None = None,
) -> AuthorizedPeer:
"""
Everything decided from the JWT, before any proof is exchanged.
@@ -276,6 +277,13 @@ def authorize_token(
Raises HandshakeError with a peer-safe message. Deliberately strict about
`group_id`: it used to be optional, and omitting it skipped the membership
check entirely and fell back to the node's first group (M1).
+
+ `node_pk_b64` binds the token to **this** node (E10). The MNP token names
+ the node it was minted for (`node` claim), so a member's token captured by
+ the operator of one node cannot be replayed to another node the member also
+ belongs to — not even to reach the pre-proof window there. A node always
+ passes its own key; a caller that passes `None` (a unit test not exercising
+ this) skips the check.
"""
try:
decoded = jwt.decode(token, hub_pk_pem, algorithms=["EdDSA"],
@@ -294,6 +302,17 @@ def authorize_token(
if require_scope is not None and decoded.get("scope", "user") != require_scope:
raise HandshakeError("Wrong token scope")
+ # The token names the node it was minted for (`node` claim). A member's real
+ # client always binds it to the node it is reaching, so a token captured by
+ # that node's operator and replayed to a *second* node the member also uses
+ # is refused here — before the pre-proof window can serve anything (E10).
+ # A token that names no node is not refused: the hub only ever mints one for
+ # the authenticated requester, so an unbound token grants nothing across
+ # accounts, and this keeps older or non-binding callers working.
+ node_claim = decoded.get("node", "")
+ if node_pk_b64 is not None and node_claim and node_claim != node_pk_b64:
+ raise HandshakeError("Token is not for this node", code="wrong_node")
+
user_id = decoded.get("sub", "")
jti = decoded.get("jti", "")
if not user_id: