Skip to content

fix : ensure encryption key is always bytes in PrivacyManager - #1331

Open
tmdeveloper007 wants to merge 1 commit into
komalharshita:mainfrom
tmdeveloper007:#1326
Open

fix : ensure encryption key is always bytes in PrivacyManager#1331
tmdeveloper007 wants to merge 1 commit into
komalharshita:mainfrom
tmdeveloper007:#1326

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Fixed the encryption key initialization in src/utils/privacy.py to ensure the key is always bytes before passing to Fernet().

The previous code used os.getenv("ENCRYPTION_KEY", Fernet.generate_key()). Since os.getenv() always returns a string (or None), if ENCRYPTION_KEY is set as an environment variable, Fernet(string_key) would crash with a TypeError. Fernet.generate_key() returns bytes, but only when the env var is NOT set.

Changes Made

  • src/utils/privacy.py: Changed key initialization to explicitly handle string env vars by encoding them to bytes:
raw_key = os.getenv("ENCRYPTION_KEY")
if raw_key is None:
    self.encryption_key = Fernet.generate_key()
elif isinstance(raw_key, str):
    self.encryption_key = raw_key.encode()
else:
    self.encryption_key = raw_key

Impact it Made

  • Prevents crash when ENCRYPTION_KEY environment variable is set as a string
  • Ensures consistent bytes-based key for Fernet regardless of how the key is provided
  • Maintains backward compatibility with existing code

Note

Please assign this PR to the tmdeveloper007 account.

Closes #1326

@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@tmdeveloper007 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : store certificate fields copy instead of assessment reference in certification.py

1 participant