Skip to content

Commit 0b8221e

Browse files
committed
feat(admin-ui): add webhook url regex validation #1704
1 parent 4f0ac8d commit 0b8221e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

admin-ui/plugins/admin/components/Webhook/WebhookForm.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const WebhookForm = () => {
5050
)
5151
const dispatch = useDispatch()
5252
const [modal, setModal] = useState(false)
53-
5453
const validatePayload = (values) => {
5554
let faulty = false
5655
if (values.httpRequestBody) {
@@ -64,8 +63,7 @@ const WebhookForm = () => {
6463
)
6564
}
6665
}
67-
const isCool = isValid(values.url)
68-
if (isValid(values.url) === false) {
66+
if (!isValid(values.url)) {
6967
faulty = true
7068
formik.setFieldError(
7169
'url',

admin-ui/plugins/admin/components/Webhook/WebhookURLChecker.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const NOT_ALLOWED = ["http://", "ftp://", "file://", "telnet://", "smb://", "ssh://", "ldap://", "https://192.168", "https://127.0", "https://172", "https://localhost"]
22
export const isValid = (url) => {
3-
if (url === undefined || url === null) {
3+
if (url === undefined || url === null || !isAllowed(url)) {
44
return false;
55
} else {
6-
return isAllowed(url)
6+
const pattern = new RegExp(
7+
'^(https?:\\/\\/)?' + // protocol
8+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
9+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
10+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
11+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
12+
'(\\#[-a-z\\d_]*)?$', // fragment locator
13+
'i'
14+
);
15+
return pattern.test(url)
716
}
817
}
918

@@ -16,4 +25,5 @@ const isAllowed = (url) => {
1625
}
1726
}
1827
return result;
19-
}
28+
}
29+

0 commit comments

Comments
 (0)