Skip to content

fix: hash refresh tokens at rest in the database#113

Open
GitAddRemote wants to merge 1 commit intomainfrom
fix/ISSUE-96-hash-refresh-tokens
Open

fix: hash refresh tokens at rest in the database#113
GitAddRemote wants to merge 1 commit intomainfrom
fix/ISSUE-96-hash-refresh-tokens

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Tokens are now stored as SHA-256(raw_token) in the refresh_tokens table
  • The raw value is only ever returned to the caller at issue time — it is never persisted
  • All DB lookups (refreshAccessToken, revokeRefreshToken) hash the incoming token before querying
  • Existing plaintext tokens in the DB become invalid after deploy; users must re-login (acceptable per spec)

Why SHA-256 (not bcrypt)

Input has 256 bits of entropy so rainbow tables are infeasible. bcrypt is intentionally slow — this is a hot lookup path and the entropy argument makes the slowness unnecessary.

Test plan

  • Login issues a raw token to the client, DB shows its hash
  • Token refresh succeeds with the raw token
  • Logout revokes the token; subsequent refresh with the same token returns 401
  • Manually inspect refresh_tokens table — no plaintext tokens present

Closes #96

Store SHA-256(token) in the database instead of the raw token value.
The raw token is returned to the caller only; the hash is used for all
DB lookups and updates. Existing plaintext tokens become invalid on
deploy — users must re-login (acceptable per spec).

- Add private hashToken() helper using crypto.sha256
- generateRefreshToken: saves hash, returns raw value
- refreshAccessToken: hashes incoming token before lookup
- revokeRefreshToken: hashes incoming token before update

Closes #96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech Story: Hash refresh tokens at rest in the database

1 participant