diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py index e03839a..dab1982 100644 --- a/websockify/token_plugins.py +++ b/websockify/token_plugins.py @@ -1,5 +1,6 @@ import os import sys +import time class BasePlugin(): def __init__(self, src): @@ -127,6 +128,18 @@ class JWTTokenApi(BasePlugin): token = jwt.JWT(key=key, jwt=token.claims) parsed = json.loads(token.claims) + + if 'nbf' in parsed: + # Not Before is present, so we need to check it + if time.time() < parsed['nbf']: + print('Token can not be used yet!', file=sys.stderr) + return None + + if 'exp' in parsed: + # Expiration time is present, so we need to check it + if time.time() > parsed['exp']: + print('Token has expired!', file=sys.stderr) + return None return (parsed['host'], parsed['port']) except Exception as e: