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

Skip to content

[Security] Enforce maximum username length in UserBadge #46584

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
Jun 7, 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
6 changes: 6 additions & 0 deletions UPGRADE-6.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
UPGRADE FROM 6.1 to 6.2
=======================

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)

Validator
---------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Http\EventListener\UserProviderListener;
Expand All @@ -27,6 +28,8 @@
*/
class UserBadge implements BadgeInterface
{
public const MAX_USERNAME_LENGTH = 4096;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps out of context but why reintroducing username here? Why not user identifier?

Copy link
Member

Choose a reason for hiding this comment

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

We need a more advanced BC layer for that. I'm going to work on getting rid of that "username" leftovers in a dedicated PR if we don't do it here (there's also Security::LAST_USERNAME)


private string $userIdentifier;
/** @var callable|null */
private $userLoader;
Expand All @@ -47,6 +50,10 @@ class UserBadge implements BadgeInterface
*/
public function __construct(string $userIdentifier, callable $userLoader = null)
{
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
throw new BadCredentialsException('Username too long.');
}

$this->userIdentifier = $userIdentifier;
$this->userLoader = $userLoader;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Security/Http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Add maximum username length enforcement of 4096 characters in `UserBadge`

6.0
---

Expand Down