CVE-2024-0436 (published 2024-02-26T16:27Z)

Theoretically, it would be possible for an attacker to brute-force the password for an instance in single-user password protection mode via a timing attack given the linear nature of the `!==` used for comparison.\n\nThe risk is minified by the additional overhead of the request, which varies in a non-constant nature making the attack less reliable to execute 


Weakness information:
cwe_id: CWE-764
cwe_name: Multiple Locks of a Critical Resource
description: The product locks a critical resource more times than intended, leading to an unexpected state in the system.
extended_description: When a product is operating in a concurrent environment and repeatedly locks a critical resource, the consequences will vary based on the type of lock, the lock's implementation, and the resource being protected. In some situations such as with semaphores, the resources are pooled and extra locking calls will reduce the size of the total available pool, possibly leading to degraded performance or a denial of service. If this can be triggered by an attacker, it will be similar to an unrestricted lock (CWE-412). In the context of a binary lock, it is likely that any duplicate locking attempts will never succeed since the lock is already held and progress may not be possible.
         

Fix information:
repo_url: https://github.com/mintplex-labs/anything-llm
commit_details: repo_url: https://github.com/mintplex-labs/anything-llm
author: Timothy Carambat
author_date: 2024-01-11 10:54:55-08:00
msg: Change pwd check to O(1) check to prevent timing attacks - single user mode (#575)

Change pwd check to O(1) check to prevent timing attacks
repository: repo_url: https://github.com/mintplex-labs/anything-llm
repo_name: Mintplex-Labs/anything-llm
description: The all-in-one Desktop & Docker AI application with full RAG and AI Agent capabilities.
repo_language: JavaScript
owner: mintplex-labs
file_changes: filename: index.jsx
change_type: ModificationType.MODIFY
diff: @@ -37,7 +37,7 @@ export default function PasswordModal({ mode = "single" }) {
 export function usePasswordModal() {
   const [auth, setAuth] = useState({
     loading: true,
-    required: false,
+    requiresAuth: false,
     mode: "single",
   });
 

programming_language: JavaScript
filename: index.jsx
change_type: ModificationType.MODIFY
diff: @@ -1,9 +1,13 @@
 import React from "react";
 import PasswordModal, { usePasswordModal } from "@/components/Modals/Password";
 import { FullScreenLoader } from "@/components/Preloader";
+import { Navigate } from "react-router-dom";
+import paths from "@/utils/paths";
 
 export default function Login() {
-  const { loading, mode } = usePasswordModal();
+  const { loading, requiresAuth, mode } = usePasswordModal();
   if (loading) return <FullScreenLoader />;
+  if (requiresAuth === false) return <Navigate to={paths.home()} />;
+
   return <PasswordModal mode={mode} />;
 }

programming_language: TypeScript
filename: system.js
change_type: ModificationType.MODIFY
diff: @@ -107,6 +107,8 @@ function systemEndpoints(app) {
 
   app.post("/request-token", async (request, response) => {
     try {
+      const bcrypt = require("bcrypt");
+
       if (await SystemSettings.isMultiUserMode()) {
         const { username, password } = reqBody(request);
         const existingUser = await User.get({ username });
@@ -121,7 +123,6 @@ function systemEndpoints(app) {
           return;
         }
 
-        const bcrypt = require("bcrypt");
         if (!bcrypt.compareSync(password, existingUser.password)) {
           response.status(200).json({
             user: null,
@@ -159,7 +160,12 @@ function systemEndpoints(app) {
         return;
       } else {
         const { password } = reqBody(request);
-        if (password !== process.env.AUTH_TOKEN) {
+        if (
+          !bcrypt.compareSync(
+            password,
+            bcrypt.hashSync(process.env.AUTH_TOKEN, 10)
+          )
+        ) {
           response.status(401).json({
             valid: false,
             token: null,

programming_language: TypeScript
filename: validatedRequest.js
change_type: ModificationType.MODIFY
diff: @@ -36,8 +36,9 @@ async function validatedRequest(request, response, next) {
     return;
   }
 
+  const bcrypt = require("bcrypt");
   const { p } = decodeJWT(token);
-  if (p !== process.env.AUTH_TOKEN) {
+  if (!bcrypt.compareSync(p, bcrypt.hashSync(process.env.AUTH_TOKEN, 10))) {
     response.status(401).json({
       error: "Invalid auth token found.",
     });

programming_language: JavaScript