From dad2157ada303a45655d2919f62905369525636f Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Fri, 4 Sep 2026 03:03:47 +0200 Subject: fix: tolerate clock skew when verifying JWTs (leeway 60s) A client whose clock is a little fast could not connect at all: the MNP handshake verified the hub-issued token with no leeway, so a token whose `iat` was a few seconds ahead of the node's clock failed with "the token is not yet valid (iat)". Seen against a freshly-resumed VM guest. `meshbay_common.handshake.JWT_LEEWAY_SECONDS = 60` is the shared value; applied to the handshake, the node's own hub-token decode, revocation-token verification, and the hub's access-token decode. 60s absorbs NTP-level skew without meaningfully widening the window on a stolen token (they already carry a jti and an exp). Co-Authored-By: Claude Sonnet 5 --- packages/meshbay-hub/src/meshbay_hub/auth.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/meshbay-hub/src') diff --git a/packages/meshbay-hub/src/meshbay_hub/auth.py b/packages/meshbay-hub/src/meshbay_hub/auth.py index 2bf59db..34baf45 100644 --- a/packages/meshbay-hub/src/meshbay_hub/auth.py +++ b/packages/meshbay-hub/src/meshbay_hub/auth.py @@ -166,7 +166,9 @@ def decode_access_token(token: str) -> dict: """Verify and decode an access token. Raises on failure.""" if _hub_pk_pem is None: raise RuntimeError("Hub keypair not loaded") - return jwt.decode(token, _hub_pk_pem, algorithms=["EdDSA"]) + # Clock-skew tolerance (meshbay_common.handshake.JWT_LEEWAY_SECONDS): a + # client whose clock is a little fast must still be able to call the API. + return jwt.decode(token, _hub_pk_pem, algorithms=["EdDSA"], leeway=60) # ── Email encryption at rest ────────────────────────────────────────────────── -- cgit v1.2.3