GitHub Security Advisory: GHSA-9q5m-jfc4-wc92
Package: github.com/steveiliop56/tinyauth (GO)
Severity: HIGH (CVSS 7.7)
CWE: CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
Vulnerable versions: < 1.0.1-0[PII_REDACTED]0714-fc1d4f2082a5
Patched in: 1.0.1-0[PII_REDACTED]0714-fc1d4f2082a5

Summary: Tinyauth has OAuth account confusion via shared mutable state on singleton service instances

Details:
### Summary

All three OAuth service implementations (`GenericOAuthService`, `GithubOAuthService`, `GoogleOAuthService`) store PKCE verifiers and access tokens as mutable struct fields on singleton instances shared across all concurrent requests. When two users initiate OAuth login for the same provider concurrently, a race condition between `VerifyCode()` and `Userinfo()` causes one user to receive a session with the other user's identity.

### Details

The [`OAuthBrokerService.GetService()`](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/service/oauth_broker_service.go#L70-L72) returns a single shared instance per provider for every request. The OAuth flow stores intermediate state as struct fields on this singleton:

**Token storage** — [`generic_oauth_service.go` line 96](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/service/generic_oauth_service.go#L96):
```go
generic.token = token  // Shared mutable field on singleton
```

**Verifier storage** — [`generic_oauth_service.go` line 81](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/service/generic_oauth_service.go#L81):
```go
generic.verifier = verifier  // Shared mutable field on singleton
```

In the callback handler [`oauth_controller.go` lines 136–143](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/controller/oauth_controller.go#L136-L143), the code calls:
```go
err = service.VerifyCode(code)                       // line 136 — stores token on singleton
// ... race window ...
user, err := controller.broker.GetUser(req.Provider)  // line 143 — reads token from singleton
```

Between these two calls, a concurrent request's `VerifyCode()` can overwrite the `token` field, causing `GetUser()` → `Userinfo()` to fetch the **wrong user's** identity claims.

The same pattern exists in all three implementations:
- [`github_oauth_service.go` lines 34–39, 77, 86–99](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/service/github_oauth_service.go#L34-L39)
- [`google_oauth_service.go` lines 22–27, 65, 73–87](https://github.com/steveiliop56/tinyauth/blob/592b7ded24959013f8af63ab9930254c752c8c8e/internal/service/google_oauth_service.go#L22-L27)

### PoC

**Race scenario** (two concurrent OAuth callbacks):

1. User A and User B both click "Login with GitHub" on the same tinyauth instance
2. Both are redirected to GitHub, authorize, and GitHub redirects both back with authorization codes
3. Both callbacks arrive at tinyauth nearly simultaneously:

```
Timeline:
  t0: Request A → service.VerifyCode(codeA) → singleton.token = tokenA
  t1: Request B → service.VerifyCode(codeB) → singleton.token = tokenB  (overwrites tokenA)
  t2: Request A → broker.GetUser("github")  → Userinfo() reads singleton.token = tokenB
  t3: Request A receives User B's identity (email, name, group