CVE-2023-34093 (published 2023-07-25T15:15Z)

Strapi is an open-source headless content management system. Prior to version 4.10.8, anyone (Strapi developers, users, plugins) can make every attribute of a Content-Type public without knowing it. The vulnerability only affects the handling of content types by Strapi, not the actual content types themselves. Users can use plugins or modify their own content types without realizing that the `privateAttributes` getter is being removed, which can result in any attribute becoming public. This can lead to sensitive information being exposed or the entire system being taken control of by an attacker(having access to password hashes). Anyone can be impacted, depending on how people are using/extending content-types. If the users are mutating the content-type, they will not be affected. Version 4.10.8 contains a patch for this issue.

CVSS v3 base score: 7.1, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:N)

Weakness information:
cwe_id: CWE-200
cwe_name: Exposure of Sensitive Information to an Unauthorized Actor
description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
extended_description: 
	   There are many different kinds of mistakes that introduce information exposures. The severity of the error can range widely, depending on the context in which the product operates, the type of sensitive information that is revealed, and the benefits it may provide to an attacker.  Some kinds of sensitive information include:
       
         private, personal information, such as personal messages, financial data, health records, geographic location, or contact details
         system status and environment, such as the operating system and installed packages
		 business secrets and intellectual property
		 network status and configuration
		 the product's own code or internal state
         metadata, e.g. logging of connections or message headers
		 indirect information, such as a discrepancy between two internal operations that can be observed by an outsider
       
	    Information might be sensitive to different parties, each of which may have their own expectations for whether the information should be protected.  These parties include:
               
                  the product's own users
                  people or organizations whose information is created or used by the product, even if they are not direct product users
		  the product's administrators, including the admins of the system(s) and/or networks on which the product operates
                  the developer
               
	    Information exposures can occur in different ways:
               
                  the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorized actors, but should not contain the information - i.e., the information should have been "scrubbed" or "sanitized"
                  a different weakness or mistake indirectly inserts the sensitive information into resources, such as a web script error revealing the full system path of the program.
                  the code manages resources that intentionally contain sensitive information, but the resources are unintentionally made accessible to unauthorized actors. In this case, the information exposure is resultant - i.e., a different weakness enabled the access to the information in the first place.
               
	    It is common practice to describe any loss of confidentiality as an "information exposure," but this can lead to overuse of CWE-200 in CWE mapping. From the CWE perspective, loss of confidentiality is a technical impact that can arise from dozens of different weaknesses, such as insecure file permissions or out-of-bounds read.  CWE-200 and its lower-level descendants are intended to cover the mistakes that occur in behaviors that explicitly manage, store, transfer, or cleanse sensitive information.
         
         

Fix information:
repo_url: https://github.com/strapi/strapi
commit_details: repo_url: https://github.com/strapi/strapi
author: nathan-pichon
author_date: 2023-05-30 19:01:28+02:00
msg: fix(content-types): remove getter for private attributes

+ Fixes a flaky test (transactions.test.api.js)
repository: repo_url: https://github.com/strapi/strapi
repo_name: strapi/strapi
description: 🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
repo_language: TypeScript
owner: strapi
file_changes: filename: transactions.test.api.js
change_type: ModificationType.MODIFY
diff: @@ -284,7 +284,7 @@ describe('transactions', () => {
         .where({ id: 1 })
         .execute();
 
-      expect(end[0].key).toEqual('strapi_content_types_schema');
+      expect(end[0].key).toEqual(original[0].key);
     });
 
     test('rollback successfully', async () => {
@@ -323,7 +323,7 @@ describe('transactions', () => {
         .where({ id: 1 })
         .execute();
 
-      expect(end[0].key).toEqual('strapi_content_types_schema');
+      expect(end[0].key).toEqual(original[0].key);
     });
   });
 });

programming_language: TypeScript
filename: permissions-manager.test.js
change_type: ModificationType.MODIFY
diff: @@ -143,7 +143,6 @@ describe('Permissions Manager', () => {
     global.strapi = {
       getModel() {
         return {
-          privateAttributes: [],
           attributes: {
             title: {
               type: 'text',

programming_language: TypeScript
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -2,7 +2,7 @@
 
 const { cloneDeep } = require('lodash/fp');
 const _ = require('lodash');
-const { hasDraftAndPublish, getPrivateAttributes } = require('@strapi/utils').contentTypes;
+const { hasDraftAndPublish } = require('@strapi/utils').contentTypes;
 const {
   CREATED_AT_ATTRIBUTE,
   UPDATED_AT_ATTRIBUTE,
@@ -58,12 +58,6 @@ const createContentType = (uid, definition) => {
     );
   }
 
-  Object.defineProperty(schema, 'privateAttributes', {
-    get() {
-      return getPrivateAttributes(schema);
-    },
-  });
-
   // attributes
   Object.assign(schema.attributes, {
     [CREATED_AT_ATTRIBUTE]: {

programming_language: JavaScript
filename: entity-service-events.test.js
change_type: ModificationType.MODIFY
diff: @@ -13,7 +13,6 @@ describe('Entity service triggers webhooks', () => {
       uid: 'api::test.test',
       kind: 'singleType',
       modelName: 'test-model',
-      privateAttributes: [],
       attributes: {
         attr: { type: 'string' },
       },

programming_language: TypeScript
filename: entity-service.test.js
change_type: ModificationType.MODIFY
diff: @@ -62,7 +62,7 @@ describe('Entity service', () => {
 
       const fakeStrapi = {
         getModel: jest.fn(() => {
-          return { kind: 'singleType', privateAttributes: [] };
+          return { kind: 'singleType' };
         }),
       };
 
@@ -133,7 +133,6 @@ describe('Entity service', () => {
           uid: entityUID,
           kind: 'contentType',
           modelName: 'test-model',
-          privateAttributes: [],
           options: {},
           attributes: {
             attrStringDefaultRequired: {
@@ -467,7 +466,6 @@ describe('Entity service', () => {
           modelName: 'entity',
           collectionName: 'entity',
           uid: entityUID,
-          privateAttributes: [],
           options: {},
           info: {
             singularName: 'entity',

programming_language: TypeScript
filename: biginteger-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('BigInteger validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrBigIntegerUnique: { type: 'biginteger', unique: true },

programming_language: TypeScript
filename: date-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Date validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrDateUnique: { type: 'date', unique: true },

programming_language: TypeScript
filename: datetime-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Datetime validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrDateTimeUnique: { type: 'datetime', unique: true },

programming_language: TypeScript
filename: float-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Float validator', () => {
       kind: 'contentType',
       uid: 'test-uid',
       modelName: 'test-model',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrFloatUnique: { type: 'float', unique: true },

programming_language: TypeScript
filename: integer-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Integer validator', () => {
       kind: 'contentType',
       uid: 'test-uid',
       modelName: 'test-model',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrIntegerUnique: { type: 'integer', unique: true },

programming_language: TypeScript
filename: string-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('String validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrStringUnique: { type: 'string', unique: true },

programming_language: TypeScript
filename: time-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Time validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrTimeUnique: { type: 'time', unique: true },

programming_language: TypeScript
filename: timestamp-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,6 @@ describe('Time validator', () => {
       kind: 'contentType',
       modelName: 'test-model',
       uid: 'test-uid',
-      privateAttributes: [],
       options: {},
       attributes: {
         attrTimestampUnique: { type: 'timestamp', unique: true },

programming_language: TypeScript
filename: uid-validators.test.js
change_type: ModificationType.MODIFY
diff: @@ -26,7 +26,6 @@ describe('UID validator', () => {
     kind: 'contentType',
     modelName: 'test-model',
     uid: 'test-uid',
-    privateAttributes: [],
     options: {},
     attributes: {
       attrUidUnique: { type: 'uid' },

programming_language: TypeScript
filename: content-types.test.js
change_type: ModificationType.MODIFY
diff: @@ -153,7 +153,6 @@ describe('Content types utils', () => {
     test('Attribute is private in the model attributes', () => {
       const model = createModelWithPrivates();
       global.strapi = { config: createConfig() };
-      Object.assign(model, { privateAttributes: getPrivateAttributes(model) });
 
       expect(isPrivateAttribute(model, 'foo')).toBeTruthy();
       expect(isPrivateAttribute(model, 'bar')).toBeFalsy();
@@ -164,7 +163,6 @@ describe('Content types utils', () => {
     test('Attribute is set to private in the app config', () => {
       const model = createModelWithPrivates();
       global.strapi = { config: createConfig(['bar']) };
-      Object.assign(model, { privateAttributes: getPrivateAttributes(model) });
 
       expect(isPrivateAttribute(model, 'foo')).toBeTruthy();
       expect(isPrivateAttribute(model, 'bar')).toBeTruthy();
@@ -175,7 +173,6 @@ describe('Content types utils', () => {
     test('Attribute is set to private in the model options', () => {
       const model = createModelWithPrivates(['foobar']);
       global.strapi = { config: createConfig() };
-      Object.assign(model, { privateAttributes: getPrivateAttributes(model) });
 
       expect(isPrivateAttribute(model, 'foo')).toBeTruthy();
       expect(isPrivateAttribute(model, 'bar')).toBeFalsy();

programming_language: TypeScript
filename: content-types.js
change_type: ModificationType.MODIFY
diff: @@ -1,7 +1,7 @@
 'use strict';
 
 const _ = require('lodash');
-const { has } = require('lodash/fp');
+const { getOr, has, union } = require('lodash/fp');
 
 const SINGLE_TYPE = 'singleType';
 const COLLECTION_TYPE = 'collectionType';
@@ -92,16 +92,23 @@ const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
 const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
 const isKind = (kind) => (model) => model.kind === kind;
 
+const getStoredPrivateAttributes = (model) => union(
+  strapi?.config?.get('api.responses.privateAttributes', []) ?? [],
+  getOr([], 'options.privateAttributes', model)
+);
+
 const getPrivateAttributes = (model = {}) => {
   return _.union(
-    strapi.config.get('api.responses.privateAttributes', []),
-    _.get(model, 'options.privateAttributes', []),
+    getStoredPrivateAttributes(model),
     _.keys(_.pickBy(model.attributes, (attr) => !!attr.private))
   );
 };
 
 const isPrivateAttribute = (model, attributeName) => {
-  return model?.privateAttributes?.includes(attributeName) ?? false;
+  if (model?.attributes?.[attributeName]?.private === true) {
+    return true;
+  }
+  return getStoredPrivateAttributes(model).includes(attributeName);
 };
 
 const isScalarAttribute = (attribute) => {

programming_language: JavaScript
filename: remove-private.js
change_type: ModificationType.MODIFY
diff: @@ -7,7 +7,7 @@ module.exports = ({ schema, key, attribute }, { remove }) => {
     return;
   }
 
-  const isPrivate = isPrivateAttribute(schema, key) || attribute.private === true;
+  const isPrivate = attribute.private === true || isPrivateAttribute(schema, key);
 
   if (isPrivate) {
     remove(key);

programming_language: JavaScript