Document Service rejects private attributes in nested populate `fields` ("Invalid key") — validator reads `includes.fields` but repository passes `field`
Node Version
22.17.1
Package Manager
yarn
Package Manager Version
1.22.22
Strapi Version
5.52.3
Operating System
Windows 11
Database
Strapi Cloud
Javascript or Typescript
Javascript
Reproduction URL
No response
Bug Description
Selecting a private: true attribute inside a nested populate via the Document Service throws ValidationError: Invalid key <attr> (400), while selecting the same attribute with top-level fields works.
This is a re-report of #23361, which was closed by the stale bot without a fix. The root cause is a key mismatch between @strapi/core and @strapi/utils:
@strapi/core/dist/services/document-service/repository.js passes the nested-populate validations under the key field (singular):
const populateValidations = {
sort: sortValidations,
field: fieldValidations, // ['scalarAttributes']
filters: filtersValidations,
populate: ['nonAttributesOperators'],
};But validatePopulate in @strapi/utils/dist/validate/validators.js reads includes.fields (plural) for nested fields:
if (key === 'fields') {
set(key, await validateFields({ schema, getModel }, value, includes?.fields || FIELDS_TRAVERSALS));
}includes.fields is always undefined, so it falls back to FIELDS_TRAVERSALS (scalarAttributes, privateFields, passwordFields). As a result, internal Document Service queries get the Content API's private-field restriction, but only for nested populate fields.
Per the docs, private only removes an attribute from server responses. It should not prevent backend code from reading the attribute through the Document Service.
Still present in 5.53.0, 5.54.0 and 5.55.0.
Steps to Reproduce
- Content type
organizationwith an attribute marked private:"status": { "type": "enumeration", "enum": ["active", "suspended"], "private": true } - Content type
organization-memberwith a relationorganization→api::organization.organization. - In backend code (service/controller/policy):→ throws
await strapi.documents('api::organization-member.organization-member').findFirst({ populate: { organization: { fields: ['documentId', 'status'] } }, });ValidationError: Invalid key status(details: { key: 'status', path: 'status' }). - For comparison, this works:
await strapi.documents('api::organization.organization').findFirst({ fields: ['documentId', 'status'], });
Expected Behavior
Nested populate fields should be validated with the repository's field validations (scalarAttributes only), the same as top-level fields. Private attributes should be selectable by internal Document Service calls. Content API validation is unaffected, since it goes through defaultValidatePopulate.
Logs
ValidationError: Invalid key status
at Object.throwInvalidKey (@strapi/utils/dist/validate/utils.js:10:11)
at visitor (@strapi/utils/dist/validate/visitors/throw-private.js:12:15)
at traverse (@strapi/utils/dist/traverse/factory.js:68:19)
at @strapi/utils/dist/traverse/query-fields.js:12:44
at async @strapi/utils/dist/validate/validators.js:453:22Code Snippets
Suggested one-line fix in @strapi/utils validatePopulate (we currently ship it as a patch-package patch):
- }, value, includes?.fields || FIELDS_TRAVERSALS));
+ }, value, includes?.fields || includes?.field || FIELDS_TRAVERSALS));Alternatively, rename the key in @strapi/core's populateValidations from field to fields.
Media
No response
Additional information
Workaround: use strapi.db.query() (Query Engine) instead of the Document Service for these lookups, or apply the patch above.
Confirmation Checklist
- I have checked the existing issues for duplicates.
- I agree to follow this project's Code of Conduct.
Source: strapi/strapi