mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
fix: validate size metadata
This commit is contained in:
parent
44d340d429
commit
2008db0852
@ -27,6 +27,7 @@ const { BatchExecutor } = require("../../../filesystem/batch/BatchExecutor");
|
|||||||
const { TeePromise } = require("../../../util/promise");
|
const { TeePromise } = require("../../../util/promise");
|
||||||
const { EWMA, MovingMode } = require("../../../util/opmath");
|
const { EWMA, MovingMode } = require("../../../util/opmath");
|
||||||
const { get_app } = require('../../../helpers');
|
const { get_app } = require('../../../helpers');
|
||||||
|
const { valid_file_size } = require("../../../util/validutil");
|
||||||
|
|
||||||
const commands = require('../../../filesystem/batch/commands.js').commands;
|
const commands = require('../../../filesystem/batch/commands.js').commands;
|
||||||
|
|
||||||
@ -189,9 +190,11 @@ module.exports = eggspress('/batch', {
|
|||||||
|
|
||||||
if ( fieldname === 'fileinfo' ) {
|
if ( fieldname === 'fileinfo' ) {
|
||||||
const fileinfo = JSON.parse(value);
|
const fileinfo = JSON.parse(value);
|
||||||
if ( fileinfo.size < 0 ) {
|
const { v: size, ok: size_ok } = valid_file_size(fileinfo.size);
|
||||||
|
if ( ! size_ok ) {
|
||||||
throw APIError.create('invalid_file_metadata');
|
throw APIError.create('invalid_file_metadata');
|
||||||
}
|
}
|
||||||
|
fileinfo.size = size;
|
||||||
fileinfos.push(fileinfo);
|
fileinfos.push(fileinfo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ const Busboy = require('busboy');
|
|||||||
const { TeePromise } = require('../../util/promise.js');
|
const { TeePromise } = require('../../util/promise.js');
|
||||||
const APIError = require('../../api/APIError.js');
|
const APIError = require('../../api/APIError.js');
|
||||||
const api_error_handler = require('../../api/api_error_handler.js');
|
const api_error_handler = require('../../api/api_error_handler.js');
|
||||||
|
const { valid_file_size } = require('../../util/validutil.js');
|
||||||
|
|
||||||
// -----------------------------------------------------------------------//
|
// -----------------------------------------------------------------------//
|
||||||
// POST /up | /write
|
// POST /up | /write
|
||||||
@ -119,9 +120,19 @@ module.exports = eggspress(['/up', '/write'], {
|
|||||||
const {
|
const {
|
||||||
filename, mimetype,
|
filename, mimetype,
|
||||||
} = details;
|
} = details;
|
||||||
|
|
||||||
|
const { v: size, ok: size_ok } =
|
||||||
|
valid_file_size(req.body.size);
|
||||||
|
|
||||||
|
if ( ! size_ok ) {
|
||||||
|
p_ready.reject(
|
||||||
|
APIError.create('invalid_file_metadata')
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uploaded_file = {
|
uploaded_file = {
|
||||||
size: req.body.size,
|
size: size,
|
||||||
name: filename,
|
name: filename,
|
||||||
mimetype,
|
mimetype,
|
||||||
stream,
|
stream,
|
||||||
|
14
packages/backend/src/util/validutil.js
Normal file
14
packages/backend/src/util/validutil.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const valid_file_size = v => {
|
||||||
|
v = Number(v);
|
||||||
|
if ( ! Number.isInteger(v) ) {
|
||||||
|
return { ok: false, v };
|
||||||
|
}
|
||||||
|
if ( ! (v >= 0) ) {
|
||||||
|
return { ok: false, v };
|
||||||
|
}
|
||||||
|
return { ok: true, v };
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
valid_file_size,
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user