security: fix O(n) timing attack in findByToken #52
No reviewers
Labels
No labels
P1
P2
P3
PHP
agent-ready
bug
clotho
discovery
docs
epic
refactor
review
security
testing
athena
athena-gemini
audit
clotho
clotho-gemini
codex
darbs-claude
security
wiki
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: core/php-tenant#52
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/fix-token-timing-attack"
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?
Summary
Fixes #9 — eliminates O(n) timing attack surface in
WorkspaceInvitation::findByToken.token_hashcolumn (SHA-256 of the raw token) toworkspace_invitationsfor O(1) indexed SQL lookupfindByToken()andfindPendingByToken()to query bytoken_hashfirst, then verify withHash::check()(single bcrypt call instead of up to 1000)updatingmodel event so re-invites also populatetoken_hashHashInvitationTokenscommand to backfilltoken_hashfor existing rowsSecurity
The previous implementation loaded up to 1000 invitation records and ran
Hash::check()(bcrypt, ~100ms each) sequentially against each. This created:The fix uses SHA-256 for fast candidate lookup (non-sensitive, just an index key) and bcrypt only once for final verification.
Test plan
WorkspaceInvitationTesttests pass (findByToken, findPendingByToken, acceptInvitation, verify token)tokenandtoken_hashcolumnstoken_hashwhen token is regenerated🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.