Skip to content

Conversation

pquerner
Copy link
Contributor

@pquerner pquerner commented Sep 17, 2025

Description (*)

This pull request moved the email address validity check to the top, which means that invalid email addresses are no longer saved nor checked in the database, before making sure it is even a valid email address.

Fixed Issues (if relevant)

Manual testing scenarios (*)

  1. Go to password reset page in frontend
  2. Enter invalid email address (disable frontend javascript validation by removing the CSS classes)
  3. Backend should disallow invalid email addresses now

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Customer Relates to Mage_Customer label Sep 17, 2025
kiatng
kiatng previously approved these changes Sep 25, 2025
@kiatng kiatng self-requested a review September 25, 2025 02:36
@kiatng
Copy link
Contributor

kiatng commented Sep 25, 2025

I tested with a bogus email with valid format; the system saves on every submission beyond the allowed times. Shouldn't we avoid saving beyond the allowed times for this type of emails as well, besides invalid formatted emails?

@pquerner
Copy link
Contributor Author

I tested with a bogus email with valid format; the system saves on every submission beyond the allowed times. Shouldn't we avoid saving beyond the allowed times for this type of emails as well, besides invalid formatted emails?

It is true that inserts are done first and then checked afterwards. But I didn't want to touch that logic part.

…il or check if password request is allowed
@pquerner pquerner force-pushed the fix/4933-forgottenPasswordEmailValidityCheck branch from 7a12936 to b196220 Compare September 25, 2025 09:20
@pquerner
Copy link
Contributor Author

PHPStan fails, but not because of my changes. No idea what to do in that case. :D Anyone?

@Hanmac
Copy link
Contributor

Hanmac commented Sep 25, 2025

PHPStan fails, but not because of my changes. No idea what to do in that case. :D Anyone?

I added an extra MR #4937

@kiatng
Copy link
Contributor

kiatng commented Sep 26, 2025

If the intent of this PR is to lower write amplification: fewer DB writes under spam/abuse, then we need to consider that correctly formatted emails would still get written to the DB until it exceeded 24 hours or per IP limits.

@pquerner
Copy link
Contributor Author

Yes, but please lets do 1 issue 1 pull request. I didnt want to get this all too bloated.

@kiatng
Copy link
Contributor

kiatng commented Sep 28, 2025

I tasked the AI for a solution, it came up with this:

    public function forgotPasswordPostAction()
    {
        $email = (string) $this->getRequest()->getPost('email');
        if ($email) {
            $flowPassword = Mage::getModel('customer/flowpassword');
            $flowPassword->setEmail($email); // kiat: no save

            if (!$flowPassword->checkCustomerForgotPasswordFlowEmail($email)) {
                // ...
            }

            if (!$flowPassword->checkCustomerForgotPasswordFlowIp()) {
                // ...
            }

            if (!Zend_Validate::is($email, 'EmailAddress')) {
                // ...
            }

            // ...

            try {
                $flowPassword->save(); // kiat: insert save after try before if
                if ($customerId) {
                    /** @var Helper $helper */ // kiat: should remove
                    // ...
                }
            } catch (Exception $exception) {
                // ...
            }
//....

I tested it and it works! You can still move the email validation up if desired. The log only saved up to the limit set in the system config.

@pquerner
Copy link
Contributor Author

As I said, this wasnt the intend of this pull request and I feel like it should be done in its own PR.
Of course if you or others feel like it absolutely must be included here, then please go ahead and add it.

Modify the customer forgot‑password flow to not save emails beyond the configured limits + 1.
kiatng
kiatng previously approved these changes Sep 29, 2025
@addison74
Copy link
Contributor

PHPStan errors.

@kiatng kiatng self-requested a review September 29, 2025 13:36
@sreichel sreichel requested a review from Copilot October 2, 2025 05:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the password reset flow by validating email addresses before performing any database operations or flow checks. The change prevents invalid email addresses from being processed or stored during password reset attempts.

Key changes:

  • Email validation moved to the beginning of the process
  • Database operations only occur after email validation passes
  • Improved error handling flow for invalid emails

Copy link

sonarqubecloud bot commented Oct 2, 2025

@sreichel sreichel merged commit 24cd60d into OpenMage:main Oct 2, 2025
22 checks passed
@sreichel sreichel added the bug label Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Component: Customer Relates to Mage_Customer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate email address for forgottenPassword

5 participants