Skip to content

Commit

Permalink
[mirotalkwebrtc] - add tag and room validator
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Aug 6, 2024
1 parent 8ed52cc commit 7f1acb1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
32 changes: 31 additions & 1 deletion backend/middleware/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const validEmailReg = new RegExp(
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
);
const validNumberReg = new RegExp(/^\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/);
const pathTraversal = new RegExp(/(\.\.(\/|\\))+/);
const alphanumeric = new RegExp(/^[A-Za-z0-9-_]+$/);

const checkData = (req, res, next) => {
const { username, email, phone, password } = req.body;
const { username, email, phone, password, room, tag } = req.body;
if (username) {
const validUsername = isValidUsername(username);
log.debug('Validator', { username: validUsername });
Expand Down Expand Up @@ -42,6 +44,20 @@ const checkData = (req, res, next) => {
return res.status(201).json({ message: validPassword });
}
}
if (room) {
const validRoom = isValidRoom(room);
log.debug('Validator', { room: validRoom });
if (validRoom != true) {
return res.status(201).json({ message: validRoom });
}
}
if (tag) {
const validTag = isValidTag(tag);
log.debug('Validator', { tag: validTag });
if (validTag != true) {
return res.status(201).json({ message: validTag });
}
}
return next();
};

Expand Down Expand Up @@ -84,4 +100,18 @@ function isValidPassword(password) {
return true;
}

function isValidRoom(room){
if (room.match(pathTraversal)) {
return '⚠️ The room name is not valid!';
};
return true;
}

function isValidTag(tag){
if (!tag.match(alphanumeric)) {
return '⚠️ The Tag must be alphanumeric!';
};
return true;
}

module.exports = checkData;
14 changes: 13 additions & 1 deletion frontend/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @license For private project or commercial purposes contact us at: [email protected] or purchase it directly via Code Canyon:
* @license https://codecanyon.net/item/a-selfhosted-mirotalks-webrtc-rooms-scheduler-server/42643313
* @author Miroslav Pejic - [email protected]
* @version 1.0.83
* @version 1.0.84
*/

const isMobile = !!/Android|webOS|iPhone|iPad|iPod|BB10|BlackBerry|IEMobile|Opera Mini|Mobile|mobile/i.test(
Expand Down Expand Up @@ -469,6 +469,7 @@ function addRow() {
console.log('[API] - ROOM CREATE RESPONSE', res);
if (res.message) {
popupMessage('warning', `${res.message}`);
removeLastRow();
} else {
const tableRow = getRow(res);
if (tableRow) {
Expand Down Expand Up @@ -798,6 +799,17 @@ function delAllRows() {
});
}

function removeRow(id){
dataTable.row(`#${id}`).remove().draw();
}

function removeLastRow() {
const lastRowIndex = dataTable.rows().count() - 1;
if (lastRowIndex >= 0) {
dataTable.row(lastRowIndex).remove().draw();
}
}

function getMyAccount() {
userGet(userId)
.then((res) => {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalkwebrtc",
"version": "1.0.83",
"version": "1.0.84",
"description": "MiroTalk WebRTC admin",
"main": "server.js",
"scripts": {
Expand Down Expand Up @@ -34,8 +34,8 @@
"homepage": "https://github.com/miroslavpejic85/mirotalkwebrtc",
"dependencies": {
"@sentry/integrations": "^7.114.0",
"@sentry/node": "^8.20.0",
"axios": "^1.7.2",
"@sentry/node": "^8.24.0",
"axios": "^1.7.3",
"bcryptjs": "^2.4.3",
"colors": "1.4.0",
"compression": "^1.7.4",
Expand All @@ -45,7 +45,7 @@
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"js-yaml": "^4.1.0",
"mongoose": "^8.5.1",
"mongoose": "^8.5.2",
"ngrok": "^5.0.0-beta.2",
"nodemailer": "^6.9.14",
"swagger-ui-express": "^5.0.1",
Expand Down

0 comments on commit 7f1acb1

Please sign in to comment.