Hash OAuth client secrets with one round, not a million #138
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
CrowderSoup/vTodo!138
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/fast-client-secret-hash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Token refreshes from clients that have a secret (the claude.ai connector, Google's clients) take 1.0-2.6 s. The token endpoint's wall-clock profile in Pyroscope shows 80% of that time in
PBKDF2PasswordHasher.verify.django-oauth-toolkit hashes client secrets with Django's password hasher, which runs over a million PBKDF2 rounds to slow down guessing passwords people chose. Our client secrets are 128 random characters we generate, so those rounds add no security.
What changes
apps/api/hashers.py:ClientSecretHasheris PBKDF2-SHA256 with one round, salted. It's set asCLIENT_SECRET_HASHERand appended toPASSWORD_HASHERS. Django's own hasher stays first, so user passwords are untouched.FastClientSecrets(validator mixin): after a client authenticates with its secret, a hash made by an older hasher is replaced with the fast one. That's the only moment we have the plaintext. The update is conditional on the stored value, so a concurrent change wins.Locally a secret check goes from about 140 ms to under 0.1 ms; on the droplet it's 1-3.5 s down to roughly nothing. The first refresh per existing client still pays the old cost once.
Tests:
test_client_secrets.pycovers new secrets, rehashing via basic and body auth, wrong secrets, and current hashes. The full suite passes.🤖 Generated with Claude Code