Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,19 @@
"optionsTestError": {
"message": "Error sending test webhook: ",
"description": "Error message for the test webhook."
}
,
},
"optionsErrorInvalidUrlScheme": {
"message": "Invalid URL scheme. Only http:// and https:// are allowed.",
"description": "Error message when a webhook URL has an invalid scheme."
},
"optionsErrorInvalidUrl": {
"message": "Invalid URL.",
"description": "Error message when a webhook URL is invalid."
},
"optionsErrorUrlRequired": {
"message": "URL is required.",
"description": "Error message when a webhook URL is missing."
},
"optionsAppearanceHeader": {
"message": "Appearance",
"description": "Header for the appearance section."
Expand Down
18 changes: 18 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ async function sendWebhook(webhook, isTest = false) {

const url = webhook.url;

if (!url) {
throw new Error(browserAPI.i18n.getMessage("optionsErrorUrlRequired") || "URL is required.");
}

try {
const urlObj = new URL(url);
if (urlObj.protocol !== "http:" && urlObj.protocol !== "https:") {
const schemeError = new Error(browserAPI.i18n.getMessage("optionsErrorInvalidUrlScheme") || "Invalid URL scheme. Only http:// and https:// are allowed.");
schemeError.name = "SchemeError";
throw schemeError;
}
} catch (e) {
if (e.name === "SchemeError") {
throw e;
}
throw new Error(browserAPI.i18n.getMessage("optionsErrorInvalidUrl") || "Invalid URL.");
}

if (method === "POST") {
fetchOpts.body = JSON.stringify(payload);
} else if (method === "GET") {
Expand Down