Magento 2.4.x Critical Security Alert: Unmasking the Password Hash Extraction Vulnerability via Search Filters
Critical Magento 2 Security Vulnerability: Password Hash Extraction Via Search Filters
In the ever-evolving landscape of e-commerce, security remains paramount. A recent discovery has brought to light a significant security vulnerability affecting Magento Open Source and Adobe Commerce versions 2.4.x, specifically 2.4.6-p11, 2.4.7-p8, and 2.4.8-p3. This flaw, detailed in GitHub issue #41791, allows an attacker with an admin or integration token to extract customer password hashes from the system, posing a severe risk of account takeover and data breaches. For any business running on these Magento versions, understanding and addressing this vulnerability is not just recommended—it's critical.
The Vulnerability Explained: A Side-Channel Leak
The core of this issue lies within the customer search endpoint (/V1/customers/search), a REST API route designed for retrieving customer information. This endpoint, accessible with a Magento_Customer::customer permission (which is part of standard admin or integration tokens), accepts caller-supplied filter fields and applies them directly to the customer collection. Crucially, the password_hash attribute, a static EAV column that stores encrypted customer passwords, is not excluded from these filters.
An attacker can exploit this by sending a LIKE filter on the password_hash field. While the hash itself is never returned in the JSON response items (a standard security practice), the total_count field in the API response acts as a boolean oracle. If a guessed character prefix for the hash matches any customer's password hash, total_count will be at least 1; if it doesn't, total_count will be 0. By repeating this query and iterating through characters (e.g., 'a%', 'b%', 'c%', then 'aa%', 'ab%', etc.), an attacker can reconstruct the full stored hash character by character. In a lab environment, the first 16 hex characters were recovered in just 131 oracle calls, demonstrating the efficiency of this attack.
Deep Dive: Technical Root Cause
The vulnerability stems from how CustomerRepository::getList() processes search criteria. This method, responsible for fetching customer data, adds every customer attribute to the SQL select statement. Subsequently, the FilterProcessor maps request field names directly to collection conditions without any allowlist or blocklist check for sensitive fields.
Here's a simplified breakdown of the code path:
CustomerRepository::getList(): Fetches customer data and applies search criteria. It includes all attributes, includingpassword_hash.FilterProcessor::process(): Takes the caller-supplied filters and directly translates them into SQLWHEREclauses. There's no validation to prevent sensitive fields likepassword_hashfrom being used in filters.CustomerSetup.php: Definespassword_hashas a 'static' attribute, meaning it's stored directly in the main customer entity table (customer_entity) rather than in EAV attribute tables.AbstractCollection.php: When a static attribute is filtered, it's directly added to the SQL query as a normal column predicate.
The final SQL query includes a WHERE clause like WHERE e.password_hash LIKE 'c655%', and the COUNT(*) operation for total_count reveals whether any records match this condition. This is the critical side channel that bypasses direct data exposure.
// Example of the vulnerable filter processing (simplified)
foreach ($filterGroup->getFilters() as $filter) {
$c>getConditionType() ?: 'eq';
$fields[] = $this->getFieldMapping($filter->getField());
$conditions[] = [$c> $filter->getValue()];
}
if ($fields) {
$collection->addFieldToFilter($fields, $conditions);
}
// No check for sensitive fields like 'password_hash'The Attack Path: How It Works
An attacker can execute this exploit in a few straightforward steps:
- Obtain an Admin or Integration Token: The attacker first needs a valid admin or integration token with the
Magento_Customer::customerACL resource. This is typically achieved through compromised admin credentials or a rogue integration. - Call the Customer Search Endpoint: Using the obtained token, the attacker sends a GET request to
/rest/V1/customers/search. - Craft a Filter on
password_hash: The attacker includes a filter group targeting thepassword_hashfield with aLIKEcondition, e.g.,searchCriteria[filter_groups][0][filters][0][field]=password_hash&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][0][value]=c%. - Use
total_countas an Oracle: The attacker observes thetotal_countin the response. If it's greater than 0, the guessed prefix is correct. If it's 0, the prefix is incorrect. - Iterate and Reconstruct: By systematically iterating through characters and appending them to the known prefix, the attacker can reconstruct the entire
password_hashvalue character by character. - Offline Cracking: Once the full hash is obtained, it can be cracked offline using brute-force or dictionary attacks. Magento's hashes are typically
sha256(password + salt) : salt : algorithm metadata, which are robust but not impervious to offline cracking if the password is weak. - Account Takeover: The cracked plaintext password can then be used to log into customer accounts, leading to full account takeover.
Impact on Your Magento Store
The implications of this vulnerability are severe and far-reaching:
- Confidentiality Breach: Every customer's password hash in the store can be reconstructed, compromising sensitive user data.
- Account Takeover: Cracked passwords enable attackers to gain unauthorized access to customer accounts. This can lead to fraudulent orders, modification of personal information (addresses, payment methods), and access to order history.
- Integrity and Business Impact: Beyond individual accounts, the integrity of your e-commerce operations is at risk. Fraudulent activities can damage your brand reputation, lead to financial losses, and incur significant costs for incident response and customer notification.
- Regulatory and Legal Risks: Depending on your jurisdiction (e.g., GDPR, CCPA), a data breach involving customer passwords can trigger mandatory reporting requirements, hefty fines, and legal action from affected customers.
- Extended Impact: Many users reuse passwords across multiple services. A compromised Magento password could open doors to other online accounts, amplifying the damage.
Identifying the Threat: Detection Strategies
Proactive monitoring is crucial for detecting attempts to exploit this vulnerability:
- Log Monitoring: Implement alerts for
/rest/V1/customers/searchrequests that includepassword_hash,rp_token, orconfirmationas filter fields. - Behavioral Analysis: Look for patterns of many requests from a single admin or integration token with incrementing
LIKEprefixes on sensitive fields. - Token Auditing: Regularly review and rotate admin and integration tokens. Audit recent usage of customer search functionalities.
- Database Query Telemetry: If possible, monitor your MySQL general log or query telemetry for
LIKEoperations on thee.password_hashcolumn.
Securing Your Magento Installation: Remediation Steps
The fix for this vulnerability involves preventing sensitive fields from being used in search criteria. While 2.4-develop contains the necessary RestrictedFieldsPlugin, stable releases (2.4.6-p11, 2.4.7-p8, 2.4.8-p3) currently lack this protection.
Why Stable Releases Are Exposed
At the time of assessment, the RestrictedFieldsPlugin file, which is designed to block restricted filter and sort fields, was absent from the tagged versions of 2.4.8-p3 and 2.4.7-p8. This means that installations running these stable versions remain vulnerable until the fix is officially backported and released in a patch.
Immediate Remediation Actions:
- Apply Official Patches: As soon as Adobe releases official security patches for the affected versions, apply them immediately. This is the most critical step.
- Backport the Fix (if no official patch is available): If you cannot wait for an official patch, consider backporting the
RestrictedFieldsPluginand its DI registration from the2.4-developbranch to your stable installation. This involves adding the plugin toMagento\Customer\Model\Plugin\CustomerRepositoryand configuring the restricted fields (password_hash,rp_token,confirmation) indi.xml. - Implement an Allowlist: Instead of a blocklist, consider a more robust allowlist approach for filterable customer fields. Explicitly reject
password_hash,rp_token, andconfirmationin both filters and sort orders. - Rotate Tokens: Immediately rotate all admin and integration tokens. Audit recent customer search usage to identify any suspicious activity.
- WAF Rule: As a defense-in-depth measure, implement a Web Application Firewall (WAF) rule to block requests to
/rest/V1/customers/searchthat containpassword_hash,rp_token, orconfirmationin the search criteria. - Regression Testing: After applying any fixes, perform thorough regression tests for REST, SOAP, and GraphQL search criteria to ensure no legitimate functionality is broken.
Shopping Mover's Perspective: Secure Your Future
At Shopping Mover, we specialize in Magento migrations and ensuring the long-term security and stability of your e-commerce platform. Vulnerabilities like this underscore the critical importance of staying updated with the latest Magento versions and security patches. Proactive security measures, regular audits, and expert guidance are indispensable for protecting your business and customer data.
If you're running an older Magento 2.4.x version or are concerned about your store's security posture, our team of Magento migration and security experts can help. We assist businesses in securely migrating to the latest, most stable versions of Adobe Commerce and Open Source, implementing best practices, and fortifying their defenses against emerging threats. Don't wait for an incident to act; secure your e-commerce future today.