Skip to content

Commit

Permalink
only allow for valid urls in slack button (louislam#5312)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanMeijer authored Nov 5, 2024
1 parent a7407a1 commit 13ea190
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions server/notification-providers/slack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { setSettings, setting } = require("../util-server");
const { getMonitorRelativeURL, UP } = require("../../src/util");
const { getMonitorRelativeURL, UP, log } = require("../../src/util");

class Slack extends NotificationProvider {
name = "slack";
Expand Down Expand Up @@ -50,15 +50,20 @@ class Slack extends NotificationProvider {

const address = this.extractAddress(monitorJSON);
if (address) {
actions.push({
"type": "button",
"text": {
"type": "plain_text",
"text": "Visit site",
},
"value": "Site",
"url": address,
});
try {
actions.push({
"type": "button",
"text": {
"type": "plain_text",
"text": "Visit site",
},
"value": "Site",
"url": new URL(address),
});

} catch (e) {
log.debug("slack", `Failed to parse address ${address} as URL`);
}
}

return actions;
Expand Down

0 comments on commit 13ea190

Please sign in to comment.