Homepage should ignore stale permissions in draft/publish-only queries
Homepage should ignore stale permissions in draft/publish-only queries
Node Version
v24.12.0
Package Manager
Yarn
Package Manager Version
4.12.0
Strapi Version
5.49.0 (fix/lint-warnings branch, PR #26818 context)
Operating System
macOS 26.5 (Darwin)
Database
SQLite (default examples/getstarted sandbox; bug is database-agnostic)
Javascript or Typescript
TypeScript
Reproduction URL
N/A - identified from code review and local source inspection.
Bug Description
The Content Manager homepage service should explicitly ignore stale permission subjects when building draft/publish-only recent document queries.
getContentTypesMeta now skips missing content types, but queryLastDocuments(..., true) still calls contentTypes.hasDraftAndPublish(strapi.contentType(uid)) for every permitted subject before that guard runs.
Current behavior is tolerant only because strapi.contentType(uid) returns undefined for a missing UID and contentTypes.hasDraftAndPublish(undefined) currently returns false. The homepage publish flow is therefore relying on helper tolerance rather than enforcing the invariant that stale permission subjects are dropped before content-type predicates run. There is also no focused test for stale UIDs in the draftAndPublishOnly=true path.
Affected package: @strapi/content-manager server homepage service.
Relevant code:
- Review comment: https://github.com/strapi/strapi/pull/26818#discussion_r3489996549
- Homepage service: https://github.com/strapi/strapi/blob/develop/packages/core/content-manager/server/src/homepage/services/homepage.ts
- Current content type lookup: https://github.com/strapi/strapi/blob/develop/packages/core/core/src/Strapi.ts
- Current
hasDraftAndPublishhelper: https://github.com/strapi/strapi/blob/develop/packages/core/utils/src/content-types.ts
Steps to Reproduce
- Have an admin role with a stale
plugin::content-manager.explorer.readpermission subject whose UID no longer exists instrapi.contentTypes. - Request the homepage recently published endpoint:
GET /content-manager/homepage/recent-documents?action=publish. - The service enters
getRecentlyPublishedDocuments(), thenqueryLastDocuments(..., true). - The stale UID is evaluated by
contentTypes.hasDraftAndPublish(strapi.contentType(uid))before the latergetContentTypesMetamissing-content-type guard can skip it.
Expected Behavior
The homepage service should explicitly filter stale permission subjects before evaluating draft/publish metadata.
Missing content type UIDs should be ignored in both homepage recent document paths:
action=update/draftAndPublishOnly=falseaction=publish/draftAndPublishOnly=true
Logs
N/A. Current code does not prove a live crash in this checkout because hasDraftAndPublish(undefined) returns false.
Code Snippets
Current risky path:
const allowedContentTypeUids = draftAndPublishOnly
? permittedContentTypes.filter((uid) => {
return contentTypes.hasDraftAndPublish(strapi.contentType(uid));
})
: permittedContentTypes;Recommended fix:
const allowedContentTypeUids = draftAndPublishOnly
? permittedContentTypes.filter((uid) => {
const contentType = strapi.contentTypes[uid];
return contentType !== undefined && contentTypes.hasDraftAndPublish(contentType);
})
: permittedContentTypes;Add a focused homepage service test asserting a stale permission subject is ignored when draftAndPublishOnly === true and that the draft/publish predicate is not called with undefined.
Optionally, in getCountDocuments, use meta.contentType.collectionName instead of strapi.contentType(meta.uid).collectionName because meta is already built only from existing content types.
Media
N/A
Additional information
Existing homepage.test.ts covers stale UIDs for queryLastDocuments({ sort: 'updatedAt:desc' }), but not the publish-only path used by getRecentlyPublishedDocuments().
The original review comment says strapi.contentType(uid) throws for stale UIDs. Local source inspection shows it returns the registry lookup result, so the safer issue framing is: stale permission subjects are not explicitly filtered in the draft/publish-only flow, and the code lacks a regression test for that invariant.
Confirmation Checklist
- I have checked the existing issues for duplicates. [NEEDS INPUT]
- I agree to follow this project's Code of Conduct.
Source: strapi/strapi