CVE-2024-31454: Insufficient Information (NVD-CWE-noinfo)
value: PsiTransfer is an open source, self-hosted file sharing solution. Prior to version 2.2.0, the absence of restrictions on the endpoint, which is designed for uploading files, allows an attacker who received the id of a file distribution to change the files that are in this distribution. The vulnerability allows an attacker to influence those users who come to the file distribution after them and slip the victim files with a malicious or phishing signature. Version 2.2.0 contains a patch for this issue.

CVE-2024-31454 allows users to violate the integrity of a file that is uploaded by another user. In this case, additional files are not loaded into the file bucket. Violation of integrity at the level of individual files. While the vulnerability with the number CVE-2024-31453 allows users to violate the integrity of a file bucket without violating the integrity of files uploaded by other users. Thus, vulnerabilities are reproduced differently, require different security recommendations and affect different objects of the application’s business logic.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-04-09T18:15Z
Repository: https://github.com/psi-4ward/psitransfer
Language: JavaScript
Files changed: app/src/Upload/store/upload.js, lib/db.js, lib/endpoints.js
Commit date: 2024-04-05 13:27:51 +0200
Commit message: Lock the bucket when the files upload completes

Diff: diff --git a/app/src/Upload/store/upload.js b/app/src/Upload/store/upload.js
index c47b118..41c39c8 100644
--- a/app/src/Upload/store/upload.js
+++ b/app/src/Upload/store/upload.js
@@ -229,11 +229,14 @@ export default {
                 file, data: {
                   uploaded: true,
                   progress: { percentage: 100, humanFileSize: file.humanSize, bytesUploaded: file._File.size }
                 }
               });
-              if (state.files.every(f => f.uploaded)) commit('STATE', 'uploaded', { root: true });
+              if (state.files.every(f => f.uploaded)) {
+                fetch(state.uploadURI + '/' + state.sid + '?lock=yes', { method: 'PATCH' });
+                commit('STATE', 'uploaded', { root: true });
+              }
             }
           }).start();
         }
         startTusUpload();
       });
diff --git a/lib/db.js b/lib/db.js
index 3d33403..5824160 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -130,10 +130,23 @@ module.exports = class DB {
     if (!file) return;
     file.metadata = { ...file.metadata, ...data };
     await this.store.update(`${ sid }++${ key }`, file);
   }
 
+  async lock(sid) {
+    const files = this.get(sid);
+    if(!files) return;
+    await Promise.all(files.map(async file => {
+      await this.updateMetadata(sid, file.key, { buckedLocked: true });
+    }));
+  }
+
+  isLocked(sid) {
+    const files = this.get(sid);
+    if(!files) return false;
+    return files.some(file => file.metadata.buckedLocked);
+  }
 
   get(sid) {
     return this.db[sid];
   }
 
diff --git a/lib/endpoints.js b/lib/endpoints.js
index 93fb921..9d91b69 100644
--- a/lib/endpoints.js
+++ b/lib/endpoints.js
@@ -330,15 +330,29 @@ app.use(`${ config.uploadAppPath }files`,
       }
     }
 
     if (req.method === 'GET') return res.status(405).end();
 
-    // Restrict upload to a file which upload completed already
+    // Lock bucket by PATCH /files/:sid?lock=yes
+    const fid = req.path.substring(1);
+    if(!fid.includes('++') && req.method === 'PATCH' && req.query.lock) {
+      await db.lock(fid);
+      return res.status(204).end('Bucket locked');
+    }
+
     if(['POST', 'PATCH'].includes(req.method)) {
+      // Restrict upload to the bucket if it is locked
+      if(!fid.includes('++') && db.isLocked(fid)) {
+        return res.status(400).end('Bucket locked');
+      }
       try {
-        const fid = req.url.substring(1);
         const info = await store.info(fid);
+        // Restrict upload to the bucket if it is locked
+        if(info.metadata.locked) {
+          return res.status(400).end('Bucket locked');
+        }
+        // Restrict upload to a file which upload completed already
         if(!info.isPartial) {
           return res.status(400).end('Upload already completed');
         }
       } catch(e) {
         if(! e instanceof httpErrors.NotFound) {
@@ -361,10 +375,15 @@ app.use(`${ config.uploadAppPath }files`,
           `invalid tus meta prop retention. Value ${ meta.retention } not in [${ Object.keys(config.retentions).join(',') }]`);
 
         const uploadLength = req.get('Upload-Length');
         assert(uploadLength, 'missing Upload-Length header');
 
+        // Restrict creating new files for locked buckets
+        if(db.isLocked(meta.sid)) {
+          return res.status(400).end('Bucket locked');
+        }
+
         meta.uploadLength = uploadLength;
         meta.key = uuid();
         meta.createdAt = Date.now().toString();
 
         // limit file and bucket size

Vulnerable code:               if (state.files.every(f => f.uploaded)) commit('STATE', 'uploaded', { root: true });
    // Restrict upload to a file which upload completed already
        const fid = req.url.substring(1);
Fixed code:               if (state.files.every(f => f.uploaded)) {
                fetch(state.uploadURI + '/' + state.sid + '?lock=yes', { method: 'PATCH' });
                commit('STATE', 'uploaded', { root: true });
              }
  async lock(sid) {
    const files = this.get(sid);
    if(!files) return;
    await Promise.all(files.map(async file => {
      await this.updateMetadata(sid, file.key, { buckedLocked: true });
    }));
  }

  isLocked(sid) {
    const files = this.get(sid);
    if(!files) return false;
    return files.some(file => file.metadata.buckedLocked);
  }
    // Lock bucket by PATCH /files/:sid?lock=yes
    const fid = req.path.substring(1);
    if(!fid.includes('++') && req.method === 'PATCH' && req.query.lock) {
      await db.lock(fid);
      return res.status(204).end('Bucket locked');
    }

      // Restrict upload to the bucket if it is locked
      if(!fid.includes('++') && db.isLocked(fid)) {
        return res.status(400).end('Bucket locked');
      }
        // Restrict upload to the bucket if it is locked
        if(info.metadata.locked) {
          return res.status(400).end('Bucket locked');
        }
        // Restrict upload to a file which upload completed already
        // Restrict creating new files for locked buckets
        if(db.isLocked(meta.sid)) {
          return res.status(400).end('Bucket locked');
        }