Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message encryption shouldn't catch/mask errors #729

Open
brassy-endomorph opened this issue Oct 31, 2024 · 0 comments
Open

Message encryption shouldn't catch/mask errors #729

brassy-endomorph opened this issue Oct 31, 2024 · 0 comments

Comments

@brassy-endomorph
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

As the title says, we shouldn't mask critical errors like this:

hushline/hushline/crypto.py

Lines 107 to 121 in 1128ace

def encrypt_message(message: str, user_pgp_key: str) -> str | None:
current_app.logger.info("Encrypting message for user with provided PGP key")
try:
# Load the user's PGP certificate (public key) from the key data
recipient_cert = Cert.from_bytes(user_pgp_key.encode())
# Encode the message string to bytes
message_bytes = message.encode("utf-8")
# Assuming there is no signer (i.e., unsigned encryption).
# Adjust the call to encrypt by passing the encoded message
return encrypt([recipient_cert], message_bytes) # Use message_bytes
except Exception as e:
current_app.logger.error(f"Error during encryption: {e}")
return None

It has a single usage here:

hushline/hushline/routes.py

Lines 229 to 238 in 1128ace

try:
encrypted_content = encrypt_message(full_content, uname.user.pgp_key)
if not encrypted_content:
flash("⛔️ Failed to encrypt message.", "error")
return redirect(url_for("profile", username=username))
content_to_save = encrypted_content
except Exception as e:
app.logger.error("Encryption failed: %s", str(e), exc_info=True)
flash("⛔️ Failed to encrypt message.", "error")
return redirect(url_for("profile", username=username))

Describe the solution you'd like

  1. Don't catch the exceptions in the function
  2. Don't even attempt to catch the exception in the endpoint. The user doesn't care that the message couldn't be encrypted. They only care that their message wasn't submitted. The current error doesn't make it clear whether or not the message is sitting on the server a) at all or b) unencrypted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant