# GHSA-V4X7-WWMQ-FXJG: Race condition allows reuse of passwordless login tokens

- Database: GitHub
- Severity: CVSS 6.5 (Medium)
- Published: 2026-07-09
- Modified: 2026-08-19

## Affected versions

- auth/pwdless/logintoken.go (Go): fixed in 2026-07-08

## Description

### Summary
The passwordless login flow allows a single login token to be redeemed more than once when concurrent requests submit the same token at nearly the same time.

A magic-link login token is expected to be single-use. However, the application checks the token and deletes it in separate lock operations. This creates a race condition where multiple requests can validate the same token before it is removed.

As a result, one magic-link login token can create multiple valid authenticated sessions.

### Affected Component

`auth/pwdless/logintoken.go`

Affected function:

```go
func (a *LoginTokenAuth) GetAccountID(token string) (int, error) {
	lt, exists := a.get(token)
	if !exists || time.Now().After(lt.Expiry) {
		return 0, errTokenNotFound
	}
	a.delete(lt.Token)
	return lt.AccountID, nil
}
```
#### Root Cause

GetAccountID() performs token lookup and token deletion separately:

1. a.get(token) checks whether the token exists.
2. The lock is released.
3. a.delete(lt.Token) deletes the token later.

#### Expected Behavior
A magic-link login token should be accepted only once.
#### Actual Behavior
The same magic-link login token can be accepted multiple times under concurrent redemption.

### Race Condition Explanation
The login token is meant to be used only once. The problem is that the application checks the token and deletes it in two separate steps.
If two requests arrive at almost the same time with the same login token, both requests can check the token before either one deletes it.
#### Example:
```
Request A submits token AbC123xy
Request B submits token AbC123xy at the same time

Request A: checks token -> token exists, so it is valid
Request B: checks token -> token still exists, so it is also valid

Request A: deletes token
Request A: receives JWT access token + refresh token

Request B: tries to delete token
Request B: still continues because it already passed validation
Request B: receives JWT access token + refresh token
So the issue is not that the JWT secret is leaked or guessed. The server itself creates the JWTs after both requests pass the login-token check.
```
Because lookup and deletion are not atomic, two concurrent requests can both observe the same login token as valid before either request deletes it.
#### Result
```
One passwordless login token can produce multiple authenticated JWT sessions.
```

### Proof of Concept : Simple Root-Cause Test
[logintoken_simple_race_test.txt](https://github.com/user-attachments/files/29794090/logintoken_simple_race_test.txt)
I have attached a POC text file, rename it: `logintoken_simple_race_test.go` put it at `/auth/pwdless/`

This PoC does not modify the production code. It uses the original functions from `auth/pwdless/logintoken.go`:

- `NewLoginTokenAuth()`
- `CreateToken()`
- `GetAccountID()`

The test creates one login token using the original `CreateToken()` function, then tries to redeem that same token from many goroutines at the same time using the original `GetAccountID()` function.

A login token should only be accepted once. If the same token is accepted more than once, the test fails.

Run:
```go
go test -v ./auth/pwdless -run TestLoginTokenCanBeUsedMoreThanOnce -count=5
```
#### Observed vulnerable result:
<img width="1579" height="795" alt="Screenshot from 2026-07-08 15-09-32" src="https://github.com/user-attachments/assets/0ea0a8c5-d6a7-4188-a447-acd5f77b2cdf" />
```
--- FAIL: TestLoginTokenCanBeUsedMoreThanOnce
    logintoken_simple_race_test.go:34: one login token was accepted 2 times
FAIL
```
This demonstrates that the same token can be accepted more than once by the original CreateToken() and GetAccountID() logic.


### Impact

- A single magic-link token can create multiple valid sessions.
- The intended one-time-use login guarantee is bypassed.

### Suggested Fix
Make token lookup, expiry validation, and deletion atomic by holding the write lock for the full operation:
```go
func (a *LoginTokenAuth) GetAccountID(token string) (int, error) {
	a.mux.Lock()
	defer a.mux.Unlock()

	lt, exists := a.token[token]
	if !exists || time.Now().After(lt.Expiry) {
		return 0, errTokenNotFound
	}

	delete(a.token, token)
	return lt.AccountID, nil
}
```
This ensures only one request can redeem a login token successfully.

## References

- https://github.com/dhax/go-base/security/advisories/GHSA-v4x7-wwmq-fxjg

Page: https://cve.now/GHSA-V4X7-WWMQ-FXJG

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
