validate call hook urls (#431)

This commit is contained in:
Sam Machin authored and GitHub committed 2025-05-01 07:22:01 -04:00
1 parent c21f5b871f
commit ce2ea8bd62
4 files changed
+43 -1

No files matched your search

+25
View File
@@ -1,4 +1,6 @@
const { v4: uuid, validate } = require('uuid');
const URL = require('url').URL;
const isValidHostname = require('is-valid-hostname');
const Account = require('../../models/account');
const {promisePool} = require('../../db');
const {cancelSubscription, detachPaymentMethod} = require('../../utils/stripe-utils');
@@ -464,6 +466,28 @@ function hasValue(data) {
}
}
const isInvalidUrl = async(s) => {
const protocols = ['https:', 'http:', 'ws:', 'wss:'];
try {
const url = new URL(s);
if (s.length != s.trim().length) {
return 'URL contains leading/trailing whitespace';
}
else if (!isValidHostname(url.hostname)) {
return `URL has invalid hostname ${url.hostname}`;
}
else if (!protocols.includes(url.protocol)) {
return `URL has missing or invalid protocol ${url.protocol}`;
}
else {
return false;
}
} catch (err) {
return 'URL is invalid';
}
};
module.exports = {
setupFreeTrial,
createTestCdrs,
@@ -486,4 +510,5 @@ module.exports = {
disableSubspace,
validatePasswordSettings,
hasValue,
isInvalidUrl
};