Validate numeric region ownership in AbstractAddress::getRegionId() - #41164
Validate numeric region ownership in AbstractAddress::getRegionId()#41164in-session wants to merge 4 commits into
Conversation
Refactor region ID handling to check region model before setting region ID.
|
Hi @in-session. 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. |
Added tests for region ID validation and handling in AbstractAddress model.
|
@magento run all tests |
|
@magento run all tests |
|
@magento run Functional Tests CE |
|
@engcom-Hotel |
Background
The underlying
getRegionId()behavior predates the recent Magento security updates.We started seeing the resulting inconsistent address state block checkout after applying the July 2026 Magento security hardening associated with APSB26-73.
One relevant change in that update moves the
validateQuoteAddressplugin from the REST-specific DI scope:to the global quote DI scope:
Previously:
was registered only for REST requests.
After the security update, the plugin is registered globally for:
so quote address validation is applied to additional PHP and checkout flows that call
setShippingAddress()orsetBillingAddress(), not only REST-specific flows.This security change does not create the invalid
region_id, andMagento\Quote\Plugin\QuoteAddressitself is not responsible for validating whether a region belongs to a country.The inconsistent state can already exist before validation:
and
AbstractAddress::getRegionId()can then materialize the country-mismatched ID:Persisted data observed
We also found already persisted addresses where
region_idbelonged to a different country than the address itself.The following query can be used to identify these records in quote addresses:
In our database this returned, among others, combinations such as:
Region ID
80is:The same inconsistency was also present in saved customer addresses:
Historical mismatched customer address records were present as far back as 2024 and 2025.
This provides database-level evidence that invalid country/region combinations existed before the July 2026 security hardening.
The mismatch is ultimately rejected later by Magento address validation during quote/order validation.
In our case this became visible as:
The relevant sequence is therefore:
Therefore the security hardening should be considered the point at which the existing data-integrity issue became visible in our checkout, not the origin of the invalid state.