Skip to content

Commit 5d9b6d2

Browse files
committed
feature symfony#46118 [Security] Don't allow empty username or empty password (bikalbasnet)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [Security] Don't allow empty username or empty password | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | symfony#46100 | License | MIT | Doc PR | - <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against the latest branch. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Reopened from symfony#46109 into `6.1` branch as this is not a bug rather a security feature Commits ------- db5afbd [Security] Don't allow empty username or empty password
2 parents 2949e9c + db5afbd commit 5d9b6d2

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

UPGRADE-6.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Security
2020
* Add maximum username length enforcement of 4096 characters in `UserBadge` to
2121
prevent [session storage flooding](https://symfony.com/blog/cve-2016-4423-large-username-storage-in-session)
2222
* Deprecate the `Symfony\Component\Security\Core\Security` class and service, use `Symfony\Bundle\SecurityBundle\Security\Security` instead
23+
* Passing empty username or password parameter when using `JsonLoginAuthenticator` is not supported anymore
2324

2425
Validator
2526
---------

src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ private function getCredentials(Request $request)
161161
throw new BadRequestHttpException(sprintf('The key "%s" must be provided.', $this->options['password_path']), $e);
162162
}
163163

164+
if ('' === $credentials['username'] || '' === $credentials['password']) {
165+
trigger_deprecation('symfony/security', '6.2', 'Passing an empty string as username or password parameter is deprecated.');
166+
}
167+
164168
return $credentials;
165169
}
166170
}

src/Symfony/Component/Security/Http/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

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

1011
6.0
1112
---

src/Symfony/Component/Security/Http/Tests/Authenticator/JsonLoginAuthenticatorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Tests\Authenticator;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1718
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -26,6 +27,8 @@
2627

2728
class JsonLoginAuthenticatorTest extends TestCase
2829
{
30+
use ExpectDeprecationTrait;
31+
2932
private $userProvider;
3033
/** @var JsonLoginAuthenticator */
3134
private $authenticator;
@@ -126,6 +129,26 @@ public function provideInvalidAuthenticateData()
126129
yield [$request, 'Username too long.', BadCredentialsException::class];
127130
}
128131

132+
/**
133+
* @dataProvider provideEmptyAuthenticateData
134+
*
135+
* @group legacy
136+
*/
137+
public function testAuthenticationForEmptyCredentialDeprecation($request)
138+
{
139+
$this->expectDeprecation('Since symfony/security 6.2: Passing empty string for username or password is deprecated and will be removed in 7.0');
140+
$this->setUpAuthenticator();
141+
142+
$this->authenticator->authenticate($request);
143+
}
144+
145+
public function provideEmptyAuthenticateData()
146+
{
147+
$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "", "password": "notempty"}');
148+
yield [$request];
149+
150+
}
151+
129152
public function testAuthenticationFailureWithoutTranslator()
130153
{
131154
$this->setUpAuthenticator();

0 commit comments

Comments
 (0)