Skip to content

Commit 44c702c

Browse files
committed
first commit
1 parent f974542 commit 44c702c

File tree

5 files changed

+422
-0
lines changed

5 files changed

+422
-0
lines changed

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
storybook-static
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
15+
# Editor directories and files
16+
.idea
17+
.vscode
18+
*.suo
19+
*.ntvs*
20+
*.njsproj
21+
*.sln
22+
*.sw?

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": {
3+
"safe-regex": "^2.1.1",
4+
"validator": "^13.1.1",
5+
"vuln-regex-detector": "^1.3.0"
6+
}
7+
}

readme.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
##Safe Patterns
2+
3+
* en_label :
4+
5+
`/^[a-zA-Z0-9-_ ]{0,250}$/`
6+
7+
* unicode_label :
8+
9+
`/^[\s\w\u0600-\u06FFs]{0,250}$/`
10+
11+
* label :
12+
13+
`/^[\s\w\u0600-\u06FFs]{0,250}$/`
14+
15+
* publicKey :
16+
17+
`/^[\s\d\w]{0,3000}$/`
18+
19+
* description :
20+
21+
`/^[\s\w\u0600-\u06FFs]{0,5000}$/`
22+
23+
* email :
24+
25+
`/^[\w-.]{1,50}@[\w-.]{1,50}\.[\w-.]{1,50}$/`
26+
27+
* mobile :
28+
29+
`/^((\+[0-9]{1,2})|0)9[0-9]{9}$/`
30+
31+
* number :
32+
33+
`/^[0-9]*$/`
34+
35+
* complexWord :
36+
37+
`/^[\s\d\w\u0600-\u06FFs_+=:!@#$%^&*()+.\/\/-]*$/`
38+
39+
* password :
40+
41+
`/^[\s\d\w\u0600-\u06FFs_+=:;!@#$%^&*()+<>,.\/-]{8,16}$/`
42+
43+
* password16 :
44+
45+
`/^[\s\d\w\u0600-\u06FFs_+=:;!@#$%^&*()+<>,.\/\/-]{16,32}$/`
46+
47+
* passwordN :
48+
49+
`/^[\s\d\w\u0600-\u06FFs_+=:;!@#$%^&*()+<>,.\/\/-]{8,}$/`
50+
51+
* alphaNumeric :
52+
53+
`/^[\w\d]+$/`
54+
55+
* license :
56+
57+
`/^[\w\d]{25}$/`
58+
59+
* vpnHexKey :
60+
61+
`/^[a-fA-F\d]{64}$/`
62+
63+
* vpnHexIV :
64+
65+
`/^[a-fA-F\d]{32}$/`
66+
67+
* vpnPassword :
68+
69+
`/^[A-Za-z0-9@#$%^&!+=]{8,16}$/`
70+
71+
##Un-Safe Patterns
72+
73+
###Use Atomic group to solve this(or use `re2` or `validator.js`)
74+
75+
* link :
76+
77+
`/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/`

safe.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var safe = require('safe-regex');
2+
// use atomic group to scape backtracking
3+
// var regex = process.argv.slice(2).join(' ');
4+
// console.log(safe(regex));
5+
const showPatterns = (arr) => {
6+
arr.forEach(pattern => {
7+
// console.log("\r\n*", pattern[0], ":\r\n")
8+
// console.log(" `" + prepareRegexObject(pattern[1]) + "`", "\r\n")
9+
10+
console.log("\r\n", pattern[0], "=>", "safe:", pattern[2])
11+
console.log(prepareRegexObject(pattern[1]), "\r\n")
12+
})
13+
}
14+
const prepareRegexObject = (p_text) => typeof p_text === "string" ? new RegExp(p_text) : p_text;
15+
const checkPatterns = (patterns_object) => {
16+
const safePatterns = [];
17+
const unSafePatterns = [];
18+
Object.entries(patterns_object).forEach(pattern => {
19+
if (safe(prepareRegexObject(pattern[1]))) {
20+
safePatterns.push([...pattern, true])
21+
} else
22+
unSafePatterns.push([...pattern, false])
23+
})
24+
console.log("\r\n**********Safe Patterns*******\r\n")
25+
showPatterns(safePatterns);
26+
console.log("\r\n\r\n\r\n⚠⚠⚠⚠⚠ Un-Safe Patterns ⚠⚠⚠⚠⚠")
27+
showPatterns(unSafePatterns);
28+
}
29+
30+
const patterns = {
31+
en_label: "^[a-zA-Z0-9-_ ]{0,250}$",
32+
unicode_label: "^[\\s\\w\\u0600-\\u06FFs]{0,250}$",
33+
label: "^[\\s\\w\\u0600-\\u06FFs]{0,250}$",
34+
35+
publicKey: "^[\\s\\d\\w]{0,3000}$",
36+
37+
description: "^[\\s\\w\\u0600-\\u06FFs]{0,5000}$",
38+
39+
email: "^[\\w-.]{1,50}@[\\w-.]{1,50}\\.[\\w-.]{1,50}$",
40+
41+
mobile: "^((\\+[0-9]{1,2})|0)9[0-9]{9}$",
42+
43+
number: "^[0-9]*$",
44+
//^(?<protocol>((ht|f)tp(s?):\/\/))?$
45+
//
46+
link: /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/,
47+
//^(?<port>:(\d){1,5})?(\/)?([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$
48+
complexWord: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:!@#$%^&*()+.\\/\\/-]*$",
49+
password: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/-]{8,16}$",
50+
password16:
51+
"^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/\\/-]{16,32}$",
52+
passwordN: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/\\/-]{8,}$",
53+
alphaNumeric: /^[\w\d]+$/,
54+
license: "^[\\w\\d]{25}$",
55+
vpnHexKey: "^[a-fA-F\\d]{64}$",
56+
vpnHexIV: "^[a-fA-F\\d]{32}$",
57+
vpnPassword: "^[A-Za-z0-9@#$%^&!+=]{8,16}$"
58+
};
59+
checkPatterns(patterns)
60+
// var validator = require('validator');
61+
62+
// validator.isEmail('[email protected]'); //=> true
63+
64+
// const result = validator.isURL("https://emm-develop.pho`enix.mahsan.net/")
65+
// console.log(result);

0 commit comments

Comments
 (0)