CVE-2024-3101 (JavaScript, published 2024-04-10T17:15Z)
Description: value: In mintplex-labs/anything-llm, an improper input validation vulnerability allows attackers to escalate privileges by deactivating 'Multi-User Mode'. By sending a specially crafted curl request with the 'multi_user_mode' parameter set to false, an attacker can deactivate 'Multi-User Mode'. This action permits the creation of a new admin user without requiring a password, leading to unauthorized administrative access.
Severity: nan (CVSS v3 base score: )
Weakness: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
Repository: https://github.com/mintplex-labs/anything-llm
Files changed:
server/endpoints/system.js
server/models/systemSettings.js
server/models/telemetry.js
Commit message: Patch ability to update multi-user-flag once set (#993)

* Patch ability to update multi-user-flag once set

* update logo function to safe update key values

Vulnerable code:
        await SystemSettings.updateSettings({
        await SystemSettings.updateSettings({
        const { success, error } = await SystemSettings.updateSettings({
        const { success, error } = await SystemSettings.updateSettings({
    "multi_user_mode",
      const updatePromises = Object.keys(updates)
        .filter((key) => this.supportedFields.includes(key))
        .map((key) => {
          const validatedValue = this.validations.hasOwnProperty(key)
            ? this.validations[key](updates[key])
            : updates[key];

          return prisma.system_settings.upsert({
            where: { label: key },
            update: {
              value: validatedValue === null ? null : String(validatedValue),
            },
            create: {
              label: key,
              value: validatedValue === null ? null : String(validatedValue),
            },
          });
    await SystemSettings.updateSettings({ [this.label]: newId });

Fixed code:
        await SystemSettings._updateSettings({
        await SystemSettings._updateSettings({
        const { success, error } = await SystemSettings._updateSettings({
        const { success, error } = await SystemSettings._updateSettings({
  protectedFields: ["multi_user_mode"],
  // Can take generic keys and will pre-filter invalid keys
  // from the set before sending to the explicit update function
  // that will then enforce validations as well.
    const validFields = Object.keys(updates).filter((key) =>
      this.supportedFields.includes(key)
    );

    Object.entries(updates).forEach(([key]) => {
      if (validFields.includes(key)) return;
      delete updates[key];
    });

    return this._updateSettings(updates);
  },

  // Explicit update of settings + key validations.
  // Only use this method when directly setting a key value
  // that takes no user input for the keys being modified.
  _updateSettings: async function (updates = {}) {
      const updatePromises = Object.keys(updates).map((key) => {
        const validatedValue = this.validations.hasOwnProperty(key)
          ? this.validations[key](updates[key])
          : updates[key];

        return prisma.system_settings.upsert({
          where: { label: key },
          update: {
            value: validatedValue === null ? null : String(validatedValue),
          },
          create: {
            label: key,
            value: validatedValue === null ? null : String(validatedValue),
          },
      });
    await SystemSettings._updateSettings({ [this.label]: newId });