Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Don't allow empty username or empty password #46118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Security
* Add maximum username length enforcement of 4096 characters in `UserBadge` to
prevent [session storage flooding](https://symfony.com/blog/cve-2016-4423-large-username-storage-in-session)
* Deprecate the `Symfony\Component\Security\Core\Security` class and service, use `Symfony\Bundle\SecurityBundle\Security\Security` instead
* Passing empty username or password parameter when using `JsonLoginAuthenticator` is not supported anymore

Validator
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ private function getCredentials(Request $request)
throw new BadRequestHttpException(sprintf('The key "%s" must be provided.', $this->options['password_path']), $e);
}

if ('' === $credentials['username'] || '' === $credentials['password']) {
trigger_deprecation('symfony/security', '6.2', 'Passing an empty string as username or password parameter is deprecated.');
}

return $credentials;
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/Security/Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* Add maximum username length enforcement of 4096 characters in `UserBadge`
* Add `#[IsGranted()]`
* Deprecate empty username or password when using when using `JsonLoginAuthenticator`

6.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Http\Tests\Authenticator;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand All @@ -26,6 +27,8 @@

class JsonLoginAuthenticatorTest extends TestCase
{
use ExpectDeprecationTrait;

private $userProvider;
/** @var JsonLoginAuthenticator */
private $authenticator;
Expand Down Expand Up @@ -126,6 +129,26 @@ public function provideInvalidAuthenticateData()
yield [$request, 'Username too long.', BadCredentialsException::class];
}

/**
* @dataProvider provideEmptyAuthenticateData
*
* @group legacy
*/
public function testAuthenticationForEmptyCredentialDeprecation($request)
{
$this->expectDeprecation('Since symfony/security 6.2: Passing empty string for username or password is deprecated and will be removed in 7.0');
$this->setUpAuthenticator();

$this->authenticator->authenticate($request);
}

public function provideEmptyAuthenticateData()
{
$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "", "password": "notempty"}');
yield [$request];

}

public function testAuthenticationFailureWithoutTranslator()
{
$this->setUpAuthenticator();
Expand Down