Skip to content

Commit

Permalink
[mirotalkwebrtc] - add type validator
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Aug 6, 2024
1 parent 7f1acb1 commit 878c4e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions backend/middleware/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const validEmailReg = new RegExp(
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 miroTalkType = new RegExp(/^(SFU|P2P|C2C|BRO)$/);

const checkData = (req, res, next) => {
const { username, email, phone, password, room, tag } = req.body;
const { username, email, phone, password, room, tag, type } = req.body;
if (username) {
const validUsername = isValidUsername(username);
log.debug('Validator', { username: validUsername });
Expand Down Expand Up @@ -58,6 +59,13 @@ const checkData = (req, res, next) => {
return res.status(201).json({ message: validTag });
}
}
if (type) {
const validType = isValidType(type);
log.debug('Validator', { type: validType });
if (validType != true) {
return res.status(201).json({ message: validType });
}
}
return next();
};

Expand Down Expand Up @@ -100,17 +108,24 @@ function isValidPassword(password) {
return true;
}

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

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

function isValidType(type) {
if (!type.match(miroTalkType)) {
return '⚠️ Type must be one of SFU/P2P/C2C/BRO!';
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ function delAllRows() {
});
}

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

Expand Down

0 comments on commit 878c4e7

Please sign in to comment.