PradyumnaKrishna / enigma-protocol

An end to end encrypted messenger using Flask, SocketIO, and Vue.js
https://protocol.onpy.in
MIT License
19 stars 34 forks source link

Error when opening a chat with an expired cookie #92

Closed Tizzz-555 closed 6 months ago

Tizzz-555 commented 6 months ago

In the list of my chats, I have 4 chats now, 3 that I just created today and 1 that has been automatically saved from a previous session. This last one crashes the app with this error when clicked: Screenshot 2023-10-11 at 10 11 37

Here we crash if given an invalid key. Our expired chat doesn't have a cookie associated with it anymore, therefore its publicKey value is null. Screenshot 2023-10-11 at 11 03 29

Proposal:

1. Graceful Error Handling:

Before using the publicKey in any operations, check if it's valid. If it's not valid (e.g., null or not a string), handle the error gracefully:

if (!publicKey || typeof publicKey !== 'string') {
    console.error('Invalid publicKey for user:', this.to);
    this.toastmsg = "Error: Invalid chat session.";
    this.toastType = "error";
    setTimeout(() => {
        this.toastmsg = "";
        this.toastType = "";
    }, 2000);
    return;
} 

2. Cleanup or Repair:

When loading the chat list, cross-check each chat session with the cookies. If a chat session doesn't have an associated cookie (or the cookie has an invalid value), remove it from the chat list.

this.users = this.users.filter(user => {
    const publicKey = this.$cookies.get(user);
    return publicKey && typeof publicKey === 'string';
});
PradyumnaKrishna commented 6 months ago

Thank you for reporting this issue, let me think about it.

Tizzz-555 commented 6 months ago

Sure thing! Let me know 🙏

Tizzz-555 commented 6 months ago

@PradyumnaKrishna Were you able to check this out? Can you replicate the bug on your end? I worked on it a bit yesterday and found a workaround, I would like to show you

PradyumnaKrishna commented 6 months ago

@PradyumnaKrishna Were you able to check this out? Can you replicate the bug on your end? I worked on it a bit yesterday and found a workaround, I would like to show you

Yeah sure show me.

PradyumnaKrishna commented 6 months ago

I was thinking what if the client can verify all the public keys and users, when the browsers loads the chat. Or, verify the public key and user when someone open the that chat.