toptal / haste-server

open source pastebin written in node.js
https://www.toptal.com/developers/hastebin/about
2.94k stars 795 forks source link

Where are the keys saved? #388

Closed DelphiCoder closed 3 years ago

DelphiCoder commented 3 years ago

I've run haste-server using the default files option to kick the tires on it. I can see that files are indeed being saved to the ./data directory, but there are no keys apparently being saved there. I can also open the saved files using notepad and can observe that these are the raw text files with no additions such as any keystore.

I didn't select any database, but checked my MongoDB using Compass anyway to insure that they are not getting put there somehow. Again, no keystore. I thought perhaps this is a memory only keystore, but when I close and restart the server, everything continues to work including the keys to the saved files. So they must be stored somewhere. I even used a directory changes monitoring app and noticed that the only directory/file changes are the saved files themselves and the generated application.min.js file.

Anyone know what is being used as the keystore and where it is being persisted? I've looked at the source code, but it is a little confusing as haste-server has many persistence mechanisms. Thank you!

DelphiCoder commented 3 years ago

Well I slowly ran the server through a debugger and got my answer on line 45 of file.js. He is running the keys through an MD5 hash to generate the filenames. That is the link between the keys and the files.