diff --git a/app/src/Server.js b/app/src/Server.js index a373acbc..c43f7286 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -469,12 +469,10 @@ function startServer() { ); if (!Validator.isValidRoomName(room)) { - return res - .status(401) - .json({ - message: - 'Invalid Room name! Must be a UUID4 or an alphanumeric string without special characters or spaces.', - }); + return res.status(401).json({ + message: + 'Invalid Room name! Must be a UUID4 or an alphanumeric string without special characters or spaces.', + }); } let peerUsername = ''; diff --git a/cloud/server.js b/cloud/server.js index 0a626556..60640f72 100644 --- a/cloud/server.js +++ b/cloud/server.js @@ -50,7 +50,7 @@ app.post('/recSync', (req, res) => { return res.status(400).send('Filename not provided'); } - if (!fileName.startsWith('Rec_') && !fileName.endsWith('.webm')) { + if (!isValidRecFileNameFormat(fileName)) { log.warn('[RecSync] - Invalid file name', fileName); return res.status(400).send('Invalid file name'); } @@ -86,3 +86,13 @@ app.post('/recSync', (req, res) => { app.listen(port, () => { log.debug(`Server is running on http://localhost:${port}`); }); + +// Utils +function isValidRecFileNameFormat(input) { + if (typeof input !== 'string') { + return false; + } + const pattern = + /^Rec_(?:[A-Za-z0-9-_]+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})_\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}\.(webm)$/; + return pattern.test(input); +}