-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
Avoid Username/Email is passed as clear GET Parameter to CheckEmailAction on password reset process #1693
Avoid Username/Email is passed as clear GET Parameter to CheckEmailAction on password reset process #1693
Changes from all commits
dd914f4
30900bf
78e9df7
7ef270f
b1a793f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,32 +15,107 @@ | |
|
||
use Sonata\AdminBundle\Admin\Pool; | ||
use Sonata\AdminBundle\Templating\TemplateRegistryInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Twig\Environment; | ||
use TypeError; | ||
|
||
final class CheckEmailAction | ||
{ | ||
|
||
private Pool $adminPool; | ||
private TemplateRegistryInterface $templateRegistry; | ||
private int $tokenTtl; | ||
|
||
/** | ||
* NEXT_MAJOR: Remove `$tokenTtlDeprecated` argument and only allow first types of arguments. | ||
* | ||
* @param Environment $twig | ||
* @param Pool $adminPool | ||
* @param TemplateRegistryInterface $templateRegistry | ||
* @param int $tokenTtl | ||
* @param null $tokenTtlDeprecated | ||
*/ | ||
public function __construct( | ||
private Environment $twig, | ||
private UrlGeneratorInterface $urlGenerator, | ||
private Pool $adminPool, | ||
private TemplateRegistryInterface $templateRegistry, | ||
private int $tokenTtl | ||
Pool|UrlGeneratorInterface $adminPool, | ||
TemplateRegistryInterface|Pool $templateRegistry, | ||
int|TemplateRegistryInterface $tokenTtl, | ||
?int $tokenTtlDeprecated = null, | ||
) { | ||
} | ||
// NEXT_MAJOR: Remove all checks and use constructor property promotion instead | ||
if ($adminPool instanceof UrlGeneratorInterface) { | ||
if (!$templateRegistry instanceof Pool) { | ||
throw new \TypeError(sprintf( | ||
'Argument 3 passed to %s() must be an instance of %s, %s given.', | ||
__METHOD__, | ||
Pool::class, | ||
\get_class($templateRegistry) | ||
)); | ||
} | ||
$this->adminPool = $templateRegistry; | ||
|
||
public function __invoke(Request $request): Response | ||
{ | ||
$username = $request->query->get('username'); | ||
if (!$tokenTtl instanceof TemplateRegistryInterface) { | ||
throw new \TypeError(sprintf( | ||
'Argument 4 passed to %s() must be an instance of %s, %s given.', | ||
__METHOD__, | ||
TemplateRegistryInterface::class, | ||
\get_class($tokenTtl) | ||
Check failure on line 63 in src/Action/CheckEmailAction.php
|
||
)); | ||
} | ||
$this->templateRegistry = $tokenTtl; | ||
|
||
if (!is_int($tokenTtlDeprecated)) { | ||
throw new \TypeError(sprintf( | ||
'Argument 5 passed to %s() must be type of %s, %s given.', | ||
__METHOD__, | ||
'integer', | ||
\gettype($tokenTtlDeprecated) | ||
)); | ||
} | ||
$this->tokenTtl = $tokenTtlDeprecated; | ||
|
||
if (null === $username) { | ||
// the user does not come from the sendEmail action | ||
return new RedirectResponse($this->urlGenerator->generate('sonata_user_admin_resetting_request')); | ||
@trigger_error(sprintf( | ||
'Passing an instance of %s as argument 2 to "%s()" is deprecated since sonata-project/user-bundle 5.x and will only accept an instance of %s in version 6.0.', | ||
UrlGeneratorInterface::class, | ||
__METHOD__, | ||
Pool::class | ||
), \E_USER_DEPRECATED); | ||
} else { | ||
$this->adminPool = $adminPool; | ||
if (!$templateRegistry instanceof TemplateRegistryInterface) { | ||
throw new \TypeError(sprintf( | ||
'Argument 3 passed to %s() must be an instance of %s, %s given.', | ||
__METHOD__, | ||
TemplateRegistryInterface::class, | ||
\get_class($templateRegistry) | ||
)); | ||
} | ||
$this->templateRegistry = $templateRegistry; | ||
|
||
if (!is_int($tokenTtl)) { | ||
throw new \TypeError(sprintf( | ||
'Argument 4 passed to %s() must be type of %s, %s given.', | ||
__METHOD__, | ||
'integer', | ||
\gettype($tokenTtl) | ||
)); | ||
} | ||
$this->tokenTtl = $tokenTtl; | ||
|
||
if (null !== $tokenTtlDeprecated) { | ||
throw new \TypeError(sprintf( | ||
'Argument 5 passed to %s() must be %s, %s given.', | ||
__METHOD__, | ||
'NULL', | ||
\gettype($tokenTtlDeprecated) | ||
)); | ||
} | ||
} | ||
} | ||
|
||
public function __invoke(): Response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For BC, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I don't think so. There won't be any error if you pass an extra param There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, i misunderstand the errors there, it was only Psalm/PHPStan complaining, not a real PHP error. |
||
{ | ||
return new Response($this->twig->render('@SonataUser/Admin/Security/Resetting/checkEmail.html.twig', [ | ||
'base_template' => $this->templateRegistry->getTemplate('layout'), | ||
'admin_pool' => $this->adminPool, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a BC break.
If someone does
new CheckEmailAction($twig, $urlGenerator, $adminPool, ...)
it will now crash.We have to keep a BC signature. You can get inspiration from https://github.com/sonata-project/SonataUserBundle/blob/4.x/src/GoogleAuthenticator/RequestListener.php#L58-L88