Exclude disabled categories from the GraphQL route query#40992
Open
thai2301 wants to merge 2 commits into
Open
Exclude disabled categories from the GraphQL route query#40992thai2301 wants to merge 2 commits into
thai2301 wants to merge 2 commits into
Conversation
CatalogTreeDataProvider resolved a category by ID without checking its active status, so a disabled category still returned a valid route through the GraphQL route query. ProductDataProvider already rejects disabled products the same way; apply the same check here using the category repository already injected into the class.
|
Hi @thai2301. 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. |
Author
|
@magento run Unit Tests, Static Tests, WebAPI Tests |
5 tasks
…route-disabled-category
Author
|
Updated with latest 2.4-develop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description (*)
The GraphQL
routequery returns a valid result (typeCATEGORY, a relative URL) for a category that has been disabled, instead of returningnull. This is a security/data exposure issue: a category the merchant explicitly disabled is still reachable and resolvable through the storefront GraphQL API.Root cause:
Magento\CatalogUrlRewriteGraphQl\Model\DataProvider\UrlRewrite\CatalogTreeDataProvider::getData()loads the category tree and only checks whether the category exists at all, never whether it is active. The analogousProductDataProvider::getData()already rejects disabled products the same way (Status::STATUS_ENABLEDcheck, since 2.4.9), but no equivalent check was ever added on the category side.Fix: use the
CategoryRepositorythat was already injected intoCatalogTreeDataProvider(but previously unused) to load the category and checkgetIsActive()before resolving the tree, throwingGraphQlNoSuchEntityExceptionif the category is disabled - matching the product behavior and theroutequery's documented contract.Related Pull Requests
N/A
Fixed Issues (if relevant)
Manual testing scenarios (*)
type: CATEGORY, a relative URL). After the fix:routereturnsnull.Questions or comments
Unit test added:
Magento\CatalogUrlRewriteGraphQl\Test\Unit\Model\DataProvider\UrlRewrite\CatalogTreeDataProviderTest(verified against the Magento2 coding standard and passing locally under PHPUnit 12).Contribution checklist (*)