Skip to content

fix: use timing-safe comparison for social account token validation#1179

Open
steinkel wants to merge 1 commit into16.next-cake5from
feature/timing-safe-social-account
Open

fix: use timing-safe comparison for social account token validation#1179
steinkel wants to merge 1 commit into16.next-cake5from
feature/timing-safe-social-account

Conversation

@steinkel
Copy link
Copy Markdown
Member

  • 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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in SocialAccountBehavior::validateAccount().
  • Add behavior tests to ensure partial and empty tokens are rejected.
  • Update test fixtures/schema metadata (including UsersFixture aliasing) 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],
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.

2 participants