-
Notifications
You must be signed in to change notification settings - Fork 9.4k
39854: Fix city name validation to allow digits, &, ., () characters #39859
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
base: 2.4-develop
Are you sure you want to change the base?
39854: Fix city name validation to allow digits, &, ., () characters #39859
Conversation
Hi @bhushan-cs. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
You might want to update the error message as well so users are informed of the correct characters that can be used. |
@gwharton thanks for the feedback! That's a great point. I think the following will be good. What do you think? |
Looks good to me. I may expect some push back from Magento team on this, as they explicitly used to allow commas, then they removed commas as allowed in 2.4.8-beta1, so I'm figuring there must have been a reason why they tightened this down. They'll have to advise. I would be willing to concede that comma does not belong in the city name, as comma is commonly used as a separator for address fields, but I can't see a reason why the others shouldn't be allowed, especially ampersand and full stop which should 100% be allowed IMHO. |
@gwharton, it wasn't Magento core devs that added this check, it was done by the community in #38345, more specifically these comments seems relevant: #38345 (comment) & #38345 (comment) So maybe @dekiakbar & @Franciscof-Serfe can take a look here and leave some feedback? |
Yep, looks like a discussion around security is needed again. There must be a better way of detecting someone entering code snippets into the address fields without banning full stop, comma, ampersand, parenthesis and digits. None of my customers who live in "Brighton & Hove" city can place orders with me without misspelling their city name (using and instead of &). Same applies for my customers in "St. Davids" and "Ventnor, Isle of Wight" |
Thanks for digging into the history, @hostep and @gwharton |
Hi @ALL , This validation pattern was originally introduced by @dekiakbar during a period of increased fraudulent activity. Attackers were submitting real credit card data in an attempt to detect vulnerabilities. These were sanitized inputs, but the attempts were annoying. At the time, I reviewed and validated the approach, suggesting applying the same pattern to other input fields for consistency. I agree that we don't need to be overly strict to filter out malicious input while still accepting legitimate data. This small adjustment keeps us on that path. |
Hi @bhushan-cs Could you update according with the additional suggestions above, and also add the appropriate test cases to I do have a slight worry that the original case of preventing the injection of code snippets into address fields is now negated by this change. However, provided the address fields are escaped internally by Magento, which i would hope they are, is there any risk of arbitrary code execution, even if a code snippet was injected. |
Hi All, @hostep Yes, its from that change. I agree, my changes was too strict and we should not to make it strict like this @bhushan-cs Your changes have definitely improved the validation, and the updated error message is much clearer and easier to understand. I fully agree with your approach — well done @gwharton You're absolutely right, and I’m really sorry for the inconvenience this has caused. I completely agree — blocking common characters like |
For those stores that have individual and local issues, I guess there's nothing stopping them overriding the existing city validator in the XML config and having a stricter version local to their store. |
That's a great point, allowing stores to override the city validator locally makes a lot of sense. It gives flexibility for specific needs without affecting the global behavior |
…y validation and update test cases
Hi @Franciscof-Serfe, @gwharton and @dekiakbar, Thanks for the further feedback and suggestions! @Franciscof-Serfe, I agree that adding support for underscore (_) and the typographical apostrophe (’) would definitely improve flexibility and handle more real-world city names accurately. I've updated the regular expression to include these. @gwharton, I've also added the appropriate test cases to ensure these new additions are covered. |
Description (*)
Fixed city name validation to allow commonly used characters that were being incorrectly rejected. The current validation was too restrictive and prevented valid city names containing numbers, periods, ampersands, and parentheses.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)