Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin-ui): Implement security measures for webhook #1705

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions admin-ui/plugins/admin/components/Webhook/WebhookForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import GluuTypeAhead from 'Routes/Apps/Gluu/GluuTypeAhead'
import GluuProperties from 'Routes/Apps/Gluu/GluuProperties'
import ShortcodePopover from './ShortcodePopover'
import shortCodes from 'Plugins/admin/helper/shortCodes.json'
import { isValid } from './WebhookURLChecker'

const WebhookForm = () => {
const { id } = useParams()
Expand Down Expand Up @@ -63,6 +64,14 @@ const WebhookForm = () => {
)
}
}
const isCool = isValid(values.url)
syntrydy marked this conversation as resolved.
Show resolved Hide resolved
if (isValid(values.url) === false) {
faulty = true
formik.setFieldError(
'url',
"Invalid url or url not allowed."
)
}

return faulty
}
Expand All @@ -85,11 +94,9 @@ const WebhookForm = () => {
},
onSubmit: (values) => {
const faulty = validatePayload(values)

if (faulty) {
return
}

toggle()
},
validationSchema: Yup.object().shape({
Expand Down
19 changes: 19 additions & 0 deletions admin-ui/plugins/admin/components/Webhook/WebhookURLChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const NOT_ALLOWED = ["http://", "ftp://", "file://", "telnet://", "smb://", "ssh://", "ldap://", "https://192.168", "https://127.0", "https://172", "https://localhost"]
export const isValid = (url) => {
if (url === undefined || url === null) {
return false;
} else {
return isAllowed(url)
}
}

const isAllowed = (url) => {
syntrydy marked this conversation as resolved.
Show resolved Hide resolved
let result = true;
for (let extention in NOT_ALLOWED) {
if (url.startsWith(NOT_ALLOWED[extention])) {
result = false;
break;
}
}
return result;
}