-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Closed
Copy link
Description
According to CVE-2013-5958, long passwords increase the time to compute a hash. To protect systems, Symfony adds a hard limit of 4096 characters for the maximum length of a password.
But Symfony can't guarantee that this will be the unique and last problem on strings to encode.
I wonder if the patch can be moved to a decorator:
class LenghtSafeEncoder implements PasswordEncoderInterface
{
private $encoder;
private $length;
public function __construct(PasswordEncoderInterface $encoder, $length = 4096)
{
$this->encoder = $encoder;
$this->length = $length;
}
public function encodePassword($raw, $salt)
{
if ($this->isPasswordTooLong($raw)) {
throw new BadCredentialsException('Invalid password.');
}
return $this->encoder->encodePassword($raw, $salt);
}
public function isPasswordValid($encoded, $raw, $salt)
{
if ($this->isPasswordTooLong($raw)) {
return false;
}
return $this->encoder->isPasswordValid($encoded, $raw, $salt);
}
private function isPasswordTooLong($password)
{
return strlen($password) > $this->length;
}
}
Of course, the documentation should recommend the use of the decorator as "best practices", for developers who want to protect their systems.
This way the encoders remain clean and future patches can be also added as decorators.
Metadata
Metadata
Assignees
Labels
No labels