mirror of
https://gitlab.com/timvisee/send.git
synced 2025-12-09 03:43:23 +00:00
fixed size limit on server to include crypto overhead
This commit is contained in:
@@ -11,6 +11,7 @@ class Limiter extends Transform {
|
||||
this.length += chunk.length;
|
||||
this.push(chunk);
|
||||
if (this.length > this.limit) {
|
||||
console.error('LIMIT', this.length, this.limit);
|
||||
return callback(new Error('limit'));
|
||||
}
|
||||
callback();
|
||||
|
||||
@@ -3,6 +3,7 @@ const storage = require('../storage');
|
||||
const config = require('../config');
|
||||
const mozlog = require('../log');
|
||||
const Limiter = require('../limiter');
|
||||
const { encryptedSize } = require('../../app/utils');
|
||||
|
||||
const log = mozlog('send.upload');
|
||||
|
||||
@@ -22,7 +23,7 @@ module.exports = async function(req, res) {
|
||||
};
|
||||
|
||||
try {
|
||||
const limiter = new Limiter(config.max_file_size);
|
||||
const limiter = new Limiter(encryptedSize(config.max_file_size));
|
||||
const fileStream = req.pipe(limiter);
|
||||
//this hasn't been updated to expiration time setting yet
|
||||
//if you want to fallback to this code add this
|
||||
|
||||
@@ -6,6 +6,7 @@ const Limiter = require('../limiter');
|
||||
const wsStream = require('websocket-stream/stream');
|
||||
const fxa = require('../fxa');
|
||||
const { statUploadEvent } = require('../amplitude');
|
||||
const { encryptedSize } = require('../../app/utils');
|
||||
|
||||
const { Duplex } = require('stream');
|
||||
|
||||
@@ -74,7 +75,7 @@ module.exports = function(ws, req) {
|
||||
id: newId
|
||||
})
|
||||
);
|
||||
const limiter = new Limiter(maxFileSize);
|
||||
const limiter = new Limiter(encryptedSize(maxFileSize));
|
||||
const flowControl = new Duplex({
|
||||
read() {
|
||||
ws.resume();
|
||||
@@ -92,8 +93,8 @@ module.exports = function(ws, req) {
|
||||
});
|
||||
|
||||
fileStream = wsStream(ws, { binary: true })
|
||||
.pipe(limiter)
|
||||
.pipe(flowControl);
|
||||
.pipe(flowControl)
|
||||
.pipe(limiter); // limiter needs to be the last in the chain
|
||||
|
||||
await storage.set(newId, fileStream, meta, timeLimit);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user