From 3d48a11fc25ab0af5aef8c473345b435c6c25180 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 1 Jul 2021 13:29:05 +0530 Subject: [PATCH] cc: Add regex validators for ransomware directory path validation --- .../ValidationFormats.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js index ff0b4706b..02a8ec506 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ValidationFormats.js @@ -1,13 +1,22 @@ const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])' const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$' +// path starts with `/` OR `$` +const linuxDirRegex = '^/|\\$' +// path starts like `C:\` OR `C:/` OR `$` OR `%abc%` +const windowsDirRegex = '^([A-Za-z]:(\\\\|\\/))|\\$|(%\\w*\\d*\\s*%)' + export const IP_RANGE = 'ip-range'; export const IP = 'ip'; +export const VALID_DIR_LINUX = 'valid-directory-linux' +export const VALID_DIR_WINDOWS = 'valid-directory-windows' export const formValidationFormats = { [IP_RANGE]: buildIpRangeRegex(), - [IP]: buildIpRegex() + [IP]: buildIpRegex(), + [VALID_DIR_LINUX]: buildValidDirLinuxRegex(), + [VALID_DIR_WINDOWS]: buildValidDirWindowsRegex() }; function buildIpRangeRegex(){ @@ -22,3 +31,11 @@ function buildIpRangeRegex(){ function buildIpRegex(){ return new RegExp('^'+ipRegex+'$') } + +function buildValidDirLinuxRegex() { + return new RegExp(linuxDirRegex) +} + +function buildValidDirWindowsRegex() { + return new RegExp(windowsDirRegex) +}