Fix CAPTCHA hostname verification when providers return parent domains #5376
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3549
This pull request improves the CAPTCHA hostname verification logic to be more robust and accurate, especially when dealing with parent domains returned by some CAPTCHA providers. The main changes introduce a new hostname matching function, update the verification logic to use it, and add tests to ensure correct behavior.
Hostname verification improvements:
normalize_hostnamefunction to ensure hostnames are compared in a case-insensitive manner and without trailing dots.hostname_matches_sitefunction, which allows the CAPTCHA response hostname to match either exactly or as a parent domain of the site hostname. This accommodates providers that return only the registrable domain.Formimplementation to use the newhostname_matches_sitefunction instead of a strict equality check.Testing improvements: