refactor: enhance security comments and error handling across multiple modules

This commit is contained in:
Rightup
2026-05-27 22:07:34 +01:00
parent a5355f188d
commit 60ca184dbd
11 changed files with 30 additions and 23 deletions
+6 -3
View File
@@ -1715,11 +1715,14 @@ class SQLiteHandler:
except Exception as e:
logger.error(f"Failed to generate transport key using get_auto_key_for: {e}")
# Fallback to a transport-compatible random 16-byte key if derivation fails.
# Fallback to a transport-compatible random key if derivation fails.
try:
random_bytes = secrets.token_bytes(16)
fallback_length = max(1, int(key_length_bytes))
random_bytes = secrets.token_bytes(fallback_length)
key = base64.b64encode(random_bytes).decode("utf-8")
logger.warning(f"Using fallback random key generation for '{name}'")
logger.warning(
f"Using fallback random key generation for '{name}' with {fallback_length} bytes"
)
return key
except Exception as fallback_e:
logger.error(f"Fallback key generation also failed: {fallback_e}")