Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor: derive deterministic key id from secret itself (#11905)

Hiep Le59ca8bd9a825
diff --git a/openhands/app_server/utils/encryption_key.py b/openhands/app_server/utils/encryption_key.py
index 5815bce20e..62224e1da1 100644
--- a/openhands/app_server/utils/encryption_key.py
+++ b/openhands/app_server/utils/encryption_key.py
@@ -1,3 +1,4 @@
+import hashlib
import os
from datetime import datetime
from pathlib import Path
@@ -30,8 +31,14 @@ def get_default_encryption_keys(workspace_dir: Path) -> list[EncryptionKey]:
"""Generate default encryption keys."""
master_key = os.getenv('JWT_SECRET')
if master_key:
+ # Derive a deterministic key ID from the secret itself.
+ # This ensures all pods using the same JWT_SECRET get the same key ID,
+ # which is critical for multi-pod deployments where tokens may be
+ # created by one pod and verified by another.
+ key_id = base62.encodebytes(hashlib.sha256(master_key.encode()).digest())
return [
EncryptionKey(
+ id=key_id,
key=SecretStr(master_key),
active=True,
notes='jwt secret master key',