Score:1

Protect long-lived session token with One Time Password, fast verification of OTP

kr flag

We have a classic web application, and when a user sign in, we return a session token (UUIDv4). The user can choose if the session should expire when the browser/app is closed or if he prefer to always be connected (1 year at least).

If an attacker get the session token, I want a way to mitigate the possibility to uses it.

A solution could be to also add a One Time Password in each API client call. On the server side, if the session token is correct we also need to check that the OTP is good.

We uses micro-services in FaaS/workers where the CPU time is limited, it's why we also search the fastest method to verify an OTP.

Which kind of OTP could I use please? I suppose HOTP isn't good because of the nature of TCP/IP where some requests couldn't be correctly acknowledged and de-sync the counters from the client / server. I suppose TOTP isn't good too because the client time is not necessarily in sync with the server (or, we also need to send the current client time, but I'm afraid this creates a bias in the protection )

[EDIT] May be my question wasn't precise enough, so I've posted my idea of a One-Time-Password based on HMAC + SHA1 + timestamp: https://security.stackexchange.com/questions/268882/protection-against-user-session-attacks-hijack-replay-tampering-csrf-xss

If you have a better suggestion (faster OTP verification / better session protection), I invite you to share it.

lakano avatar
kr flag
The goal is to have a second factor in each API call, and this 2nd factor need to be recalculate in the client-side before each call (depending of a secret shared with the server side)
knaccc avatar
es flag
What's the point of having a session token as well as the OTP?
lakano avatar
kr flag
@knaccc The session token is returned to the client after a successful sign in ( login/password ) and permit us to known who is it, his authorizations and even to revoke the token when needed. It's the classic scheme of session token of web application. The one-time password is a key is a 2nd layer of security in case of MITM interception, as our session token could be stored for long time, we increase the risk of interception of the session token. But if the attacker got it (or even the last OTP), he can't uses it because he don't known the shared-secret to create the next OTP.
Meir Maor avatar
in flag
note UUID is designed to be unique, not designed to be unguessable. A random number from a secure PRNG could be much better from a security perspective.
lakano avatar
kr flag
@MeirMaor First, thank you for your typo corrections in my post (I'm still learning english). About your suggestion of random number, the Crypto interface of browser seems to have a PRNG suitable for cryptographic purposes named getRandomValues(), and also propose a randomUUID() function that in theory uses getRandomValues(). The v4 UUID includes 122 bits of random values. Do you believe it's not safe enough and I should uses 128 bits of random values only?
Meir Maor avatar
in flag
Maybe I'm not up to date on v4, 122 random bits should be fine.
Maarten Bodewes avatar
in flag
@MeirMaor [Here you go](https://www.rfc-editor.org/rfc/rfc4122#section-4.4). Doesn't include any specific requirements for the RNG, but if a good DRBG is used then it should be fine.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.