Skip to content

Commit

Permalink
fix: add try catch on fenet decrypt to prevent errors (langflow-ai#2660)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristhianzl authored Jul 12, 2024
1 parent 229b868 commit 8813143
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/base/langflow/services/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ def encrypt_api_key(api_key: str, settings_service=Depends(get_settings_service)

def decrypt_api_key(encrypted_api_key: str, settings_service=Depends(get_settings_service)):
fernet = get_fernet(settings_service)
decrypted_key = ""
# Two-way decryption
if isinstance(encrypted_api_key, str):
decrypted_key = fernet.decrypt(encrypted_api_key).decode()
try:
decrypted_key = fernet.decrypt(encrypted_api_key.encode()).decode()
except Exception:
decrypted_key = fernet.decrypt(encrypted_api_key).decode()
return decrypted_key

0 comments on commit 8813143

Please sign in to comment.