Secure way of encrypting payload in Javascript for user authentification

After talking with my colleague @owengot, here is a more detailed description of the problem.

There is a Vue.js based web application that does not have its own active server-side component. It rather is a standalone web application that uses the Discourse API, so in a way Discourse is the server. Use cases include standalone polls or forms, where the content is posted to Discourse topics under the user’s account. Being able to create such a software without custom server-side components seemed like a nice architecture for these uses, so ideally we’d want to avoid doing anything “server side”.

Now, obtaining a User-API key works as intended, but @owengot discovered that the step of generating a private key in JavaScript takes a long time (up to 10 seconds, it’s just inefficient in JavaScript …). Then he discovered the hack that the same private key can be used for multiple users, so he stored it in a file on the web host that also serves the other static files of the web application (JS, CSS etc.). That makes it fast … but now that private key is (1) a shared one and (2) stored out in the open, with a publicly accessible URL. That seems, umh, frightening :fearful:

So I said, we have to ask the Discourse team about the security implications are of this hack. I see two basic alternatives:

  • If that private key is “only” used for payload encryption then we could live with this because we also have the communication encrypted via SSL / HTTPS.

  • But if knowing that private key somehow allows to compute the resulting User-API key that is later used for posting under somebody’s Discourse account, it would of course make this hack unacceptable.