Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

localstorage should not share folder with other accounts #15

Closed skylord123 closed 2 years ago

skylord123 commented 2 years ago

This was a design flaw I accidentally caused. The folder matrix-local-storage is used across every matrix client created when instead it should have a unique folder per client.

I ran into an issue where my Node-RED instance was crashing and come to find out it's because my client was trying to access a key from the other client which caused an exception that could not be recovered from.

We need to move each client to their own folder. This will be a BC break only for people that run multiple matrix clients (and the fix isn't great and will most likely need all clients to have their keys reset).

skylord123 commented 2 years ago

Just an extra note: It's a security issue to have clients using the same directory since then clients will have access to keys they weren't supposed to.

skylord123 commented 2 years ago

Here is an error that occurs when the master key is found for another account/matrix client:

1 Sep 20:43:51 - [error] [matrix-server-config:@testbot2:hempsterinc.com] Error: Mismatched user ID @testbot:hempsterinc.com in master key from @testbot2:hempsterinc.com
    at CrossSigningInfo.setKeys (/home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/CrossSigning.js:400:15)
    at /home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/index.js:421:33
    at LocalStorageCryptoStore.getCrossSigningKeys (/home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/store/localStorage-crypto-store.js:357:5)
    at /home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/index.js:416:24
    at LocalStorageCryptoStore.doTxn (/home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/store/localStorage-crypto-store.js:374:28)
    at Crypto.init (/home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/crypto/index.js:415:28)
    at async MatrixClient.initCrypto (/home/skylar/Projects/node-red-contrib-matrix-chat/node_modules/matrix-js-sdk/lib/client.js:939:5)
    at async run (/home/skylar/Projects/node-red-contrib-matrix-chat/src/matrix-server-config.js:166:25)

Moving to separate folders will fix this. I already have the code written to do the upgrade. We will create the new config folders and copy the old one into each of the new server config folders. The above error will still happen but it doesn't look to be a show-stopper.