Skip to content

Commit a96320c

Browse files
minor #59558 [Security] Unset token roles when serializing it and user implements EquatableInterface (nicolas-grekas)
This PR was merged into the 7.3 branch. Discussion ---------- [Security] Unset token roles when serializing it and user implements EquatableInterface | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT When the user object implement EquatableInterface, we never read the roles stored in the token object that wraps the user in the session storage. This PR ensures we don't store these roles either - they're just wasting space. Commits ------- b7c55c87bcb [Security] Unset token roles when serializing it and user implements EquatableInterface
2 parents 21449b8 + 0950773 commit a96320c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Firewall/ContextListener.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ private static function hasUserChanged(UserInterface $originalUser, TokenInterfa
308308
}
309309
}
310310

311-
$userRoles = array_map('strval', $refreshedUser->getRoles());
311+
$refreshedRoles = array_map('strval', $refreshedUser->getRoles());
312+
$originalRoles = $refreshedToken->getRoleNames(); // This comes from cloning the original token, so it still contains the roles of the original user
312313

313314
if (
314-
\count($userRoles) !== \count($refreshedToken->getRoleNames())
315-
|| \count($userRoles) !== \count(array_intersect($userRoles, $refreshedToken->getRoleNames()))
315+
\count($refreshedRoles) !== \count($originalRoles)
316+
|| \count($refreshedRoles) !== \count(array_intersect($refreshedRoles, $originalRoles))
316317
) {
317318
return true;
318319
}

0 commit comments

Comments
 (0)