Description
Preconditions and environment
- Magento version: 2.4.x (affects all versions with DynamicStorage)
- Environment: Any Magento installation with:
- CMS pages with URL rewrites (e.g.,
privacy-policy-cookie-restriction-mode
) - Categories with URL rewrites (e.g.,
schroeven
) - Catalog URL Rewrite module enabled
- CMS pages with URL rewrites (e.g.,
- Modules: Default Magento installation (no third-party modules required to reproduce)
- URL Structure: Category URLs with CMS page identifiers as suffixes
Steps to reproduce
Prerequisites Setup:
-
Create Category:
- Create a category with URL key
schroeven
- Note the category entity_id (e.g., ID = 48)
- Create a category with URL key
-
Create CMS Page:
- Create a CMS page with identifier
privacy-policy-cookie-restriction-mode
- Note the CMS page entity_id (e.g., ID = 4)
- Create a CMS page with identifier
-
Create Product with Matching ID:
- Create a product with entity_id = 4 (same as CMS page ID)
- This is crucial - the product ID must match the CMS page ID
- Assign this product to the
schroeven
category (ID 48) - Ensure the product is enabled and visible
-
System Maintenance:
bin/magento indexer:reindex bin/magento cache:clean bin/magento cache:flush
Reproduction Steps:
-
Verify URL rewrites exist in database:
-- Should show CMS page rewrite SELECT * FROM url_rewrite WHERE request_path = 'privacy-policy-cookie-restriction-mode'; -- Should show category rewrite SELECT * FROM url_rewrite WHERE request_path = 'schroeven.html';
-
Navigate to malformed URL:
/schroeven/privacy-policy-cookie-restriction-mode
-
Observe the response
Why This Setup Is Required:
- DynamicStorage extracts
privacy-policy-cookie-restriction-mode
- Finds CMS page with entity_id=4 (but treats it as product_id=4)
- Checks if product_id=4 can be shown in category_id=48 using
ProductResource::canBeShowInCategory(4, 48)
- Since product ID 4 IS assigned to category 48, the check passes
- DynamicStorage creates:
/cms/page/view/page_id/4/category/48
Expected result
The URL /schroeven/privacy-policy-cookie-restriction-mode
should return HTTP 404 because:
- It's not a valid product URL pattern
- It's not a valid category URL
- It's not a valid CMS page URL
- This malformed URL pattern should not resolve to any content
Actual result
The URL /schroeven/privacy-policy-cookie-restriction-mode
returns HTTP 200 and serves the CMS page content with category context.
Root Cause Analysis:
The issue occurs in vendor/magento/module-catalog-url-rewrite/Model/Storage/DynamicStorage.php
:
- Method
findProductRewriteByRequestPath()
extractsprivacy-policy-cookie-restriction-mode
from the URL - It queries
url_rewrite
table WITHOUT filtering byentity_type
- Query finds the CMS page URL rewrite (
entity_type = 'cms-page'
) - DynamicStorage treats the CMS page as if it's a product
- Creates malformed target path:
/cms/page/view/page_id/X/category/Y
- UrlRewrite Router serves this as valid content
Problematic Code (line ~147):
$productFromDb = $this->connection->fetchRow($this->prepareSelect($data));
The $data
array only contains request_path
and store_id
- missing entity_type = 'product'
filter.
Additional information
Database Evidence:
-- This query shows the CMS page that gets incorrectly matched
SELECT * FROM url_rewrite WHERE request_path = 'privacy-policy-cookie-restriction-mode';
-- Returns: entity_type='cms-page', entity_id=4, target_path='cms/page/view/page_id/4'
Debug Logs:
When processing /schroeven/privacy-policy-cookie-restriction-mode
:
- UrlRewrite Router calls DynamicStorage
- DynamicStorage finds CMS page data (should only find products)
- Router creates Forward action to
/cms/page/view/page_id/4/category/48
Affected Code Files:
vendor/magento/module-catalog-url-rewrite/Model/Storage/DynamicStorage.php
(lines 140-200)- Method:
findProductRewriteByRequestPath()
Suggested Fix:
Add entity_type filtering in the database query:
// Before querying for "product" data, ensure we only get products
$data[UrlRewrite::ENTITY_TYPE] = 'product';
$productFromDb = $this->connection->fetchRow($this->prepareSelect($data));
Security Impact: None - this is a URL routing issue, not a security vulnerability.
Performance Impact: Minimal - affects only specific URL patterns.
Workaround: Plugin on UrlRewrite Router to block malformed URL patterns before they reach DynamicStorage.
Release note
Fixed DynamicStorage URL rewrite query to properly filter by entity_type, preventing CMS pages from being incorrectly processed as products in category URL contexts.
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
m2-assistant commentedon Jun 13, 2025
Hi @rbouma. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.
@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
m2-assistant commentedon Jun 13, 2025
Hi @rbouma! 👋
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use
@magento add to contributors team
command to join Contributors team.m2-assistant commentedon Jun 13, 2025
Hi @rbouma! 👋
Thank you for joining. Please accept team invitation 👉 here 👈 and add your comment one more time.
Fix DynamicStorage entity_type filtering to prevent CMS/product ID co…
m2-assistant commentedon Jun 13, 2025
Hi @engcom-Bravo. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branchDetails
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
Issue: Confirmed
once verification is complete.engcom-Bravo commentedon Jun 16, 2025
Hi @rbouma,
Thanks for your reporting and collaboration.
We have tried to reproduce the issue in Latest 2.4-develop instance and we are not able to reproduce the issue.Kindly refer the screenshots.
The URL /schroeven/privacy-policy-cookie-restriction-mode returns HTTP 404.Could you please let us know if we are missing anything.
Thanks.
16 remaining items