Forward secrecy (plausible deniability) and storing messages

How do messengers, like signal or XMPP-omemo messengers, store their messages? Since, the session key is only valid for the current session, how can such extensions like MAM (message archiving on XMPP server) or storing the messages encrypted on the disk work? Futher, you often want plausible deniability with malleable encryption and publishing your MAC-Keys. If this happens, how can u be sure that integrity and authentication is still valid?

Are there any security concerns with storing private keys in browser’s javascript?

I’m working on a web app, and I know little about security/cryptography (for now, still learning) but I’m trying to set up a front-end where:

At the very beginning, the user puts in their private key.

The key is stored as a variable in javascript.

Any time the user does anything to interact with the backend, the key is used to sign or encrypt whatever data it needs to, the data is sent, and when the user is done with everything, they close the browser.

Is this a secure way of doing this? Can anything but my JS code access this key in the process?

(P.S. it’s gonna be RSA or ECC so asymmetric, private key is only known by front end user)

Storing $K$ numbers with ordering

Let $ S$ be a sequence of $ k$ many numbers. The position of the number in the $ S$ matters. In the $ S$ there are only $ j$ many different numbers are there means $ S$ contains many duplicates. Position is a query which needed to be answered, position(i) returns the element at position $ i$ in $ S$ .

Trivial way to store them is using array which will takes $ O(S)$ space and position can be solved in $ O(1)$ time.

I am looking for a representation that takes $ O(j)$ space (or somewhere near to it) and such that position can be solved in $ O(1)$ (even in more time is also ok)?

Please suggest some papers also.

Can I avoid storing data on the web by emailing it?

My client wants to gather some sensitive info via an app. I don’t want to store it on the server. Is this a good plan?

  1. Encrypt it on the phone using a public key embedded in the app.
  2. Send it to the server.
  3. Without saving it, email it to the client.
  4. They copy the base64 into a desktop app that decrypts it using a private key stored on the machine.

They already have such data in-house. So I figure this wouldn’t be any less secure.

Storing encrypted tokens in LocalStorage

I am building a JavaScript application that will run in a web browser but also as a pseudo-native mobile application via Apache Cordova. It communicates via API to a separate backend service.

The app requires that the user be prompted for some kind of identifying information whenever it is launched, but for ease of use this need not be their full username and password. Password entry in particular (and especially on mobile devices) will be too cumbersome to make this feasible. Therefore, we are considering a once-off login procedure where the full credentials are supplied, followed by a “setup” step where the user creates a PIN for future access. This could, in future, be extended to allow a fingerprint/face scan to also “unlock” the app on supported devices.

We are also hoping to avoid the use of cookies. Doing so subsequently avoids CSRF concerns but also, support for cookies in Cordova applications appears to be either non-existent or at least unreliable.

My initial thoughts on implementation are:

  • The user submits a valid username/password combination to a login/ endpoint of the API and receives an “ID token” in response.
  • During the “setup” phase, the PIN chosen by the user is used to encrypt the ID token.
  • The encrypted ID token is stored in LocalStorage.
  • A secondary request is made to an authorise/ endpoint of the API, including the plaintext ID token. Assuming the token validates, a second token is issued to the app.
  • This second token is what is used in all subsequent requests to the API to prove the user is trusted, has a relatively short expiry, and is not stored in any persistent manner by the application.
  • Upon returning to the app at a later date, the user need only provide their chosen PIN.
  • It can be used to decrypt the stored ID token, which is then used in the authorise/ request to generate and return a new short-lived session token.

The internet abounds with articles advising against the use of LocalStorage for anything sensitive, due to its exposure in the event of XSS attacks. The threat is that a token in LocalStorage could be stolen when the same token in an httpOnly cookie could not. It is worth noting that in both cases, a malicious script running within the app could successfully issue fraudulent requests to the backend API.

I believe the XSS threat of the ID token being stolen is mitigated by it being encrypted under the user’s PIN, and neither the decrypted value nor the PIN itself being stored or used beyond the authorise/ request.

The session token is also vulnerable to being stolen by XSS. It is only stored in memory, but is obviously still accessible to JavaScript and thus to a malicious script. These tokens would be given short expiry times to mitigate this threat. Not to mention we would do our best to harden against XSS in the first place.

I think the above sounds like a secure way to implement our requirements, but I am no security expert. Am I missing any obvious weaknesses here? Does this actually sound secure?

Is storing a JWT secret as docker env variable acceptable?

I understand how JWTs work and that with my secret anyone can issue new tokens. I control the server that my node website runs on and am considering different options for hosting the key.

  1. In code – Not acceptable because my code is in a github repo
  2. ENV variable – seperate secrets for dev and production while not leaking to github
  3. Store in database – Seems more like #2 with more work, being that an on-machine attacker can find access to the db anyways

2 looks like the best method for a simple website (no super sensitive user info like credit cards or SSNs). Is this a good solution?

Storing the height of an AVL tree node in constant time

Starting at about 9:00 in this lecture Erik Demaine talks about calculating the height of a node in an AVL tree in terms of doing a constant time local operation on its children. He then goes on to talk about a general theorem for this pattern that would allow to store the height in constant time.

1) If you know what Erik is talking about, how is the height stored in constant time?

2) In a related question someone asked how to compute the height of AVL as efficiently as possible (Compute height of AVL tree as efficiently as possible). All answers except one agreed that the best possible way is in $ O(\lg n)$ , but that’s not constant time. The only answer that suggested storing the height was dismissed. Could someone explain why?

How do email clients “send later” without storing a password?

Email clients like Spark for macOS have a feature where a user can send an email later, at any given time, even when the computer is turned off. An SMTP server needs a password based authentication, though.

Does that mean that if I use Spark to send an email later, my password gets sent over to Spark servers in plaintext, so that they can authorize on the SMTP server later? Or is there a different method?

Is storing sensitive data in files safe?

Say I have a hypothetical PHP application which will store hashed passwords in a file in the same directory. At first, this seems like it would be very insecure, since one could guess at the name of the file and open it via a web browser (

However, I was wondering about the level of security this would provide using a few different methods:

  • Security through obscurity: giving the text file a nonsense name that would be hard to guess (hashed_password_wefhbweifvbewuivgbwueigfvu4gf.txt)
  • Giving the text file a certain file extension (hashed_password.secret), and instructing the web server to return a 403 when it is requested
  • Encrypting the text file with a key hard-coded into the PHP application
  • Storing the information in a commented-out part of a PHP file, so it can only be read from the back end (and will return a blank file in a web browser)

Compared to a database, are any of these methods more or less secure, and could they provide a reasonable level of security (about that of a database) against attackers?

Storing the master password in a keychain

I tend to avoid putting my master keychain password in the keychain itself (in OSX, for example), but sometimes with federation of accounts and things, it would be convenient to do so.

Am I right to avoid this? I can’t really think of a good reason. Perhaps if you have multiple federated systems with different keychains, storing them on multiple keychains for the convenience increases chances of a problem just by nature of having multiple storage places. But other than that?