@@ -2,12 +2,31 @@ const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0
2
2
const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])'
3
3
const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$'
4
4
5
+
6
+ const linuxAbsolutePathRegex = / ^ \/ / // path starts with `/`
7
+ const linuxPathStartsWithEnvVariableRegex = / ^ \$ / // path starts with `$`
8
+ const linuxPathStartsWithTildeRegex = / ^ ~ / // path starts with `~`
9
+
10
+
11
+ const windowsAbsolutePathRegex = / ^ ( [ A - Z a - z ] : ( \\ | \/ ) ) / // path starts like `C:\` OR `C:/`
12
+ const windowsEnvVarNonNumeric = '[A-Za-z#\\$\'\\(\\)\\*\\+,\\-\\.\\?@\\[\\]_`\\{\\}~ ]'
13
+ const windowsPathStartsWithEnvVariableRegex = new RegExp (
14
+ `^%(${ windowsEnvVarNonNumeric } +(${ windowsEnvVarNonNumeric } |\\d)*)%`
15
+ ) // path starts like `$` OR `%abc%`
16
+ const windowsUncPathRegex = / ^ \\ { 2 } / // Path starts like `\\`
17
+ const emptyRegex = / ^ $ /
18
+
19
+
5
20
export const IP_RANGE = 'ip-range' ;
6
21
export const IP = 'ip' ;
22
+ export const VALID_RANSOMWARE_TARGET_PATH_LINUX = 'valid-ransomware-target-path-linux'
23
+ export const VALID_RANSOMWARE_TARGET_PATH_WINDOWS = 'valid-ransomware-target-path-windows'
7
24
8
25
export const formValidationFormats = {
9
26
[ IP_RANGE ] : buildIpRangeRegex ( ) ,
10
- [ IP ] : buildIpRegex ( )
27
+ [ IP ] : buildIpRegex ( ) ,
28
+ [ VALID_RANSOMWARE_TARGET_PATH_LINUX ] : buildValidRansomwarePathLinuxRegex ( ) ,
29
+ [ VALID_RANSOMWARE_TARGET_PATH_WINDOWS ] : buildValidRansomwarePathWindowsRegex ( )
11
30
} ;
12
31
13
32
function buildIpRangeRegex ( ) {
@@ -22,3 +41,21 @@ function buildIpRangeRegex(){
22
41
function buildIpRegex ( ) {
23
42
return new RegExp ( '^' + ipRegex + '$' )
24
43
}
44
+
45
+ function buildValidRansomwarePathLinuxRegex ( ) {
46
+ return new RegExp ( [
47
+ emptyRegex . source ,
48
+ linuxAbsolutePathRegex . source ,
49
+ linuxPathStartsWithEnvVariableRegex . source ,
50
+ linuxPathStartsWithTildeRegex . source
51
+ ] . join ( '|' ) )
52
+ }
53
+
54
+ function buildValidRansomwarePathWindowsRegex ( ) {
55
+ return new RegExp ( [
56
+ emptyRegex . source ,
57
+ windowsAbsolutePathRegex . source ,
58
+ windowsPathStartsWithEnvVariableRegex . source ,
59
+ windowsUncPathRegex . source
60
+ ] . join ( '|' ) )
61
+ }
0 commit comments