Skip to content

Commit 98f9bd8

Browse files
Mention possible timing attack on session validation (#1802)
1 parent 5dbdccc commit 98f9bd8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pages/lucia-v3/migrate.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We ultimately came to the conclusion that it'd be easier and faster to just impl
1414

1515
Replacing Lucia v3 with your own implementation should be a straight-forward path, especially since most of your knowledge will still be very useful. No database migrations are necessary.
1616

17-
If you're fine with invalidating all sessions (and signing out everyone), consider reading through the [new implementation guide](/sessions/basic).
17+
If you're fine with invalidating all sessions (and signing out everyone), consider reading through the [new implementation guide](/sessions/basic). The new API is more secure and patches out a very impractical timing attack (see code below for details).
1818

1919
### Sessions
2020

@@ -46,6 +46,13 @@ export function createSession(dbPool: DBPool, userId: number): Promise<Session>
4646

4747
export function validateSession(dbPool: DBPool, sessionId: string): Promise<Session | null> {
4848
const now = Date.now();
49+
50+
// This may be vulnerable to a timing attack where an attacker can measure the response times
51+
// to guess a valid session ID.
52+
// A more common pattern is a string comparison against a secret using the === operator.
53+
// The === operator is not constant time and the same can be said about SQL = operators.
54+
// Some remote timing attacks has been proven to be possible but there hasn't been a successful
55+
// recorded attack on real-world applications targeting similar vulnerabilities.
4956
const result = dbPool.executeQuery(
5057
dbPool,
5158
"SELECT id, user_id, expires_at FROM session WHERE id = ?",

pages/sessions/basic.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: "Basic session implementation"
66

77
## Overview
88

9-
Sessions are stored in a database with their ID and hash of the secret. The secret is hashed before storage to minimize the impact of breaches and leaks. Once a token is lost, the server cannot re-issue it.
9+
Sessions have an ID and secret. We're using a separate ID and secret to prevent any possibility of a timing attacks. The secret is hashed before storage to minimize the impact of breaches and leaks.
1010

1111
```ts
1212
interface Session {
@@ -16,7 +16,7 @@ interface Session {
1616
}
1717
```
1818

19-
Tokens issued to clients include both the ID and secret:
19+
Tokens issued to clients include both the ID and un-hashed secret.
2020

2121
```
2222
<SESSION_ID>.<SESSION_SECRET>

0 commit comments

Comments
 (0)