Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

BA-JBI
Copy link
Contributor

@BA-JBI BA-JBI commented Aug 22, 2024

Subject

Avoid Username/Email is passed as clear GET Parameter to CheckEmailAction on password reset process as discussed in #1692

I am targeting this branch, because this fixes an privacy issue and doesn't break anything.

Closes #1692.

Changelog

Removed

  • After requesting new passwort the username isn't passed to CheckEmailAction anymode

BA-JBI added 2 commits August 22, 2024 11:03
Remove passing username as get Parameter to sonata_user_admin_resetting_check_email as discussed in #1692 (comment)
Copy link
Contributor

@Hanmac Hanmac left a comment

Choose a reason for hiding this comment

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

need to update about changed parameters

->set('sonata.user.action.check_email', CheckEmailAction::class)
->public()
->args([
service('twig'),
service('router'),
service('sonata.admin.pool'),
service('sonata.admin.global_template_registry'),
abstract_arg('token ttl'),
])

@BA-JBI
Copy link
Contributor Author

BA-JBI commented Aug 23, 2024

Sorry, I forgot the service definitions because I'm already way too spoiled by Symfony's autowiring technology

@Hanmac
Copy link
Contributor

Hanmac commented Aug 23, 2024

Ugh, I forgot another location again:

$container->getDefinition('sonata.user.action.check_email')
->replaceArgument(4, $config['token_ttl']);

@Hanmac
Copy link
Contributor

Hanmac commented Aug 26, 2024

@VincentLanglet I think this MR is ready to run the Tests?

use Twig\Environment;

final class CheckEmailAction
{
public function __construct(
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
Copy link
Member

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

public function __construct(
    private Environment $twig,
    Pool|UrlGeneratorInterface $adminPool,
    TemplateRegistryInterface|Pool $templateRegistry,
    int|TemplateRegistryInterface $tokenTtl,
    ?int $tokenTtl = null,
) {
    if ($adminPool instanceof UrlGeneratorInterface) {
            if (!$templateRegistry instanceof Pool) {
                throw new TypeError(...);
            }
            $this->adminPool = $templateRegistry;

            @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;
        }
        
        // And so on
}

@Hanmac
Copy link
Contributor

Hanmac commented Aug 26, 2024

@VincentLanglet about the native_function_invocation Lint, should I make an MR for this, or should a bot handle that?

@VincentLanglet
Copy link
Member

A rebase should solve the issues

@BA-JBI
Copy link
Contributor Author

BA-JBI commented Aug 26, 2024

Tried to apply the backward compatibility as good as possible similar to the suggested code.
Hope this matches the expected solution


public function __invoke(): Response
Copy link
Contributor

Choose a reason for hiding this comment

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

For BC, the Request $request param probably needs to be optional.
(with Deprecate Warning)

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@VincentLanglet
Copy link
Member

I rebased fixed and merged in #1695.

Thanks !

@BA-JBI
Copy link
Contributor Author

BA-JBI commented Aug 27, 2024

Yey cool
Thank You !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Username/Email is passed as clear GET Parameter to CheckEmailAction on password reset process
3 participants