Skip to content

Commit 045b3a7

Browse files
committed
Use Redis GETDEL when reading a one time password
A get followed by delete left a race where two clients could both retrieve the same secret. GETDEL fetches and removes the key in one step.
1 parent 464ca34 commit 045b3a7

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

snappass/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ def get_password(token):
174174
If not, the password is simply returned as is.
175175
"""
176176
storage_key, decryption_key = parse_token(token)
177-
password = redis_client.get(storage_key)
178-
redis_client.delete(storage_key)
177+
# Atomically get and delete so two clients cannot both read the secret
178+
# (requires Redis 6.2+ / redis-py getdel).
179+
password = redis_client.getdel(storage_key)
179180

180181
if password is not None:
181182

0 commit comments

Comments
 (0)