From e6a8a84278677490289f3c031641b9eb47114ba4 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 17 Apr 2022 19:30:58 +0800 Subject: [PATCH] Include only nessacary data in webhook --- server/model/monitor.js | 24 ++++++++++++++++-------- server/server.js | 9 ++++++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index bbb80da4a..0603a098c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -42,7 +42,7 @@ class Monitor extends BeanModel { /** * Return an object that ready to parse to JSON */ - async toJSON() { + async toJSON(includeSensitiveData = true) { let notificationIDList = {}; @@ -56,15 +56,11 @@ class Monitor extends BeanModel { const tags = await this.getTags(); - return { + let data = { id: this.id, name: this.name, url: this.url, method: this.method, - body: this.body, - headers: this.headers, - basic_auth_user: this.basic_auth_user, - basic_auth_pass: this.basic_auth_pass, hostname: this.hostname, port: this.port, maxretries: this.maxretries, @@ -82,11 +78,23 @@ class Monitor extends BeanModel { dns_resolve_type: this.dns_resolve_type, dns_resolve_server: this.dns_resolve_server, dns_last_result: this.dns_last_result, - pushToken: this.pushToken, proxyId: this.proxy_id, notificationIDList, tags: tags, }; + + if (includeSensitiveData) { + data = { + ...data, + headers: this.headers, + body: this.body, + basic_auth_user: this.basic_auth_user, + basic_auth_pass: this.basic_auth_pass, + pushToken: this.pushToken, + }; + } + + return data; } async getTags() { @@ -727,7 +735,7 @@ class Monitor extends BeanModel { for (let notification of notificationList) { try { - await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(), bean.toJSON()); + await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), bean.toJSON()); } catch (e) { log.error("monitor", "Cannot send notification to " + notification.name); log.error("monitor", e); diff --git a/server/server.js b/server/server.js index eae21deeb..314f3fd93 100644 --- a/server/server.js +++ b/server/server.js @@ -11,7 +11,7 @@ if (nodeVersion < requiredVersion) { } const args = require("args-parser")(process.argv); -const { sleep, log, getRandomInt, genSecret, debug } = require("../src/util"); +const { sleep, log, getRandomInt, genSecret, debug, isDev } = require("../src/util"); const config = require("./config"); log.info("server", "Welcome to Uptime Kuma"); @@ -235,6 +235,13 @@ try { } }); + if (isDev) { + app.post("/test-webhook", async (request, response) => { + log.debug("test", request.body); + response.send("OK"); + }); + } + // Robots.txt app.get("/robots.txt", async (_request, response) => { let txt = "User-agent: *\nDisallow:";