fix: use timing-safe comparison for social account token validation#1179
Open
steinkel wants to merge 1 commit into16.next-cake5from
Open
fix: use timing-safe comparison for social account token validation#1179steinkel wants to merge 1 commit into16.next-cake5from
steinkel wants to merge 1 commit into16.next-cake5from
Conversation
Member
steinkel
commented
Apr 12, 2026
- Replace === with hash_equals() in SocialAccountBehavior::validateAccount() to prevent timing attacks on the token comparison
- Add tests for partial and empty token rejection
- Fix UsersFixture missing tableAlias causing _schemaFromReflection to resolve a generic Table instead of UsersTable, which skips the json type override for additional_data
- Correct schema.php discrepancies against migrations: users.active default, users.secret length, users.secret_verified default, social_accounts.avatar type and social_accounts.link type
- Replace === with hash_equals() in SocialAccountBehavior::validateAccount() to prevent timing attacks on the token comparison - Add tests for partial and empty token rejection - Fix UsersFixture missing tableAlias causing _schemaFromReflection to resolve a generic Table instead of UsersTable, which skips the json type override for additional_data - Correct schema.php discrepancies against migrations: users.active default, users.secret length, users.secret_verified default, social_accounts.avatar type and social_accounts.link type
There was a problem hiding this comment.
Pull request overview
This PR hardens social account token validation against timing attacks by switching to a timing-safe comparison, and updates the test suite/fixture schema to better reflect current expectations.
Changes:
- Use
hash_equals()for token comparison inSocialAccountBehavior::validateAccount(). - Add behavior tests to ensure partial and empty tokens are rejected.
- Update test fixtures/schema metadata (including
UsersFixturealiasing) to correct schema mismatches and improve JSON handling.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Model/Behavior/SocialAccountBehavior.php |
Switch token equality check to hash_equals() for timing-safe comparison. |
tests/TestCase/Model/Behavior/SocialAccountBehaviorTest.php |
Add regression tests for partial/empty token rejection. |
tests/Fixture/UsersFixture.php |
Add explicit table alias to ensure the correct Table class/schema overrides are used. |
tests/schema.php |
Adjust test schema metadata for several columns/types/defaults to better match expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ->first(); | ||
|
|
||
| if (!empty($socialAccount) && $socialAccount->token === $token) { | ||
| if (!empty($socialAccount) && hash_equals((string)$socialAccount->token, (string)$token)) { |
| 'avatar' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], | ||
| 'description' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], | ||
| 'link' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], | ||
| 'link' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null], |
| 'activation_date' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], | ||
| 'secret' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null], | ||
| 'secret_verified' => ['type' => 'boolean', 'length' => null, 'null' => true, 'default' => false, 'comment' => '', 'precision' => null], | ||
| 'secret' => ['type' => 'string', 'length' => 32, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.