Timing attack possible in \Phalcon\Security::checkToken #12418

Closed
kristofferingemansson opened this Issue Nov 22, 2016 · 2 comments

Projects

None yet

2 participants

@kristofferingemansson
Contributor
kristofferingemansson commented Nov 22, 2016 edited

In \Phalcon\Security::checkToken, comparison of supplied and expected tokens are done with simple "==" and is thus subject to a timing attack.
https://github.com/phalcon/cphalcon/blob/v3.0.1/phalcon/security.zep#L400

This is somewhat mitigated by the fact that tokens usually are regenerated.

Comparison should preferably be done using PHP's hash_equals if it exists (PHP >= 5.6.0) and then maybe use comparison algorithm from \Phalcon\Security::checkHash as fallback?
https://github.com/phalcon/cphalcon/blob/v3.0.1/phalcon/security.zep#L300

@sergeyklay
Collaborator

I'll try to backport hash_equals from PHP 5.6

@sergeyklay sergeyklay referenced this issue in phalcon/zephir Dec 1, 2016
Merged

Introduced HashEqualsOptimizer #1365

@sergeyklay sergeyklay added this to the 3.0.3 milestone Dec 1, 2016
@sergeyklay sergeyklay self-assigned this Dec 1, 2016
@sergeyklay
Collaborator

Fixed in the 3.0.x branch.

@sergeyklay sergeyklay closed this Dec 2, 2016
@sergeyklay sergeyklay assigned sergeyklay and unassigned sergeyklay Dec 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment