Skip to content

Commit 32cac69

Browse files
committed
feat: add setting to toggle webhook logging, off by default
1 parent 3e56856 commit 32cac69

5 files changed

Lines changed: 54 additions & 30 deletions

File tree

‎src/backend/crowbar-relay/crowbar-relay-websocket.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import ReconnectingWebSocket from '../reconnecting-websocket';
22
import accountAccess from "../common/account-access";
33
import { TypedEmitter } from "tiny-typed-emitter";
44
import logger from "../logwrapper";
5-
import { maskPII } from '../utils';
65

76
class CrowbarRelayWebSocket extends TypedEmitter<{
87
"ready": () => void,
@@ -68,7 +67,6 @@ class CrowbarRelayWebSocket extends TypedEmitter<{
6867
});
6968

7069
this.ws.addEventListener("message", (msg) => {
71-
logger.debug("Crowbar Relay WebSocket message:", maskPII(msg.data));
7270
try {
7371
this.emit("message", JSON.parse(msg.data));
7472
} catch (e) {

‎src/backend/webhooks/webhook-config-manager.ts‎

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import frontendCommunicator from "../common/frontend-communicator";
33
import JsonDbManager from "../database/json-db-manager";
44
import { crowbarRelayWebSocket } from "../crowbar-relay/crowbar-relay-websocket";
55
import eventManager from "../events/EventManager";
6+
import { SettingsManager } from "../common/settings-manager";
7+
import { maskPII } from "../utils";
8+
import logger from "../logwrapper";
69

710
class WebhookConfigManager extends JsonDbManager<WebhookConfig, { "webhook-received": (data: { config: WebhookConfig; payload: unknown; }) => void }> {
811
constructor() {
@@ -18,32 +21,37 @@ class WebhookConfigManager extends JsonDbManager<WebhookConfig, { "webhook-recei
1821
crowbarRelayWebSocket.on("ready", sendWebhookIds);
1922

2023
crowbarRelayWebSocket.on("message", (msg) => {
21-
if (msg.event === "webhook") {
22-
const data = msg.data as { webhookId: string; payload: unknown; };
23-
24-
const webhookConfig = this.getItem(data.webhookId);
25-
if (!webhookConfig) {
26-
return;
27-
}
28-
29-
let payload = data.payload;
30-
31-
if (typeof payload === "string") {
32-
try {
33-
payload = JSON.parse(payload);
34-
} catch {
35-
// ignore
36-
}
37-
}
38-
39-
this.emit("webhook-received", { config: webhookConfig, payload });
40-
41-
eventManager.triggerEvent("firebot", "webhook-received", {
42-
webhookId: webhookConfig.id,
43-
webhookName: webhookConfig.name,
44-
webhookPayload: payload
45-
});
24+
if (msg.event !== "webhook") {
25+
return;
4626
}
27+
28+
if (SettingsManager.getSetting("WebhookDebugLogs")) {
29+
logger.debug("Webhook received:", maskPII(msg.data));
30+
}
31+
32+
const data = msg.data as { webhookId: string; payload: unknown; };
33+
34+
const webhookConfig = this.getItem(data.webhookId);
35+
if (!webhookConfig) {
36+
return;
37+
}
38+
39+
let payload = data.payload;
40+
41+
if (typeof payload === "string") {
42+
try {
43+
payload = JSON.parse(payload);
44+
} catch {}
45+
}
46+
47+
this.emit("webhook-received", { config: webhookConfig, payload });
48+
49+
eventManager.triggerEvent("firebot", "webhook-received", {
50+
webhookId: webhookConfig.id,
51+
webhookName: webhookConfig.name,
52+
webhookPayload: payload
53+
});
54+
4755
});
4856
}
4957
}

‎src/gui/app/directives/settings/categories/advanced-settings.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
name="Proxied Webhooks"
3939
tag="Experimental"
4040
description="This feature allows you to receive webhooks without exposing your local network. A 'Webhook Received' event is triggered each time a webhook is received with the payload available via the $webhookPayload variable."
41+
bottom-border="false"
4142
>
4243
<setting-description-addon>
4344
<b>This feature is experimental and not guaranteed to be stable.</b>
@@ -48,6 +49,20 @@
4849
/>
4950
</firebot-setting>
5051
52+
<firebot-setting
53+
name="Webhook Debug Logs"
54+
description="Enable or disable logging for incoming webhooks. Webhooks might contain sensitive information. Be careful where you send logs when this option is enabled."
55+
>
56+
<setting-description-addon>
57+
<b>Requires Debug Mode to also be enabled.</b>
58+
</setting-description-addon>
59+
<firebot-button
60+
text="{{settings.getSetting('WebhookDebugLogs') && settings.getSetting('DebugMode') ? 'Disable Webhook Logs' : 'Enable Webhook Logs' }}"
61+
disabled="!settings.getSetting('DebugMode')"
62+
ng-click="settings.saveSetting('WebhookDebugLogs', !settings.getSetting('WebhookDebugLogs'))"
63+
/>
64+
</firebot-setting>
65+
5166
<firebot-setting
5267
name="Quote ID Recalculation"
5368
description="Quote IDs in Firebot are static, even if a quote before another is deleted. If you would like to recalculate your quote IDs so that there isn't any skipped quote numbers, you can use this option."

‎src/gui/app/directives/settings/firebot-setting.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
bindings: {
77
name: "@",
88
tag: "@?",
9-
description: "@"
9+
description: "@",
10+
bottomBorder: "<?"
1011
},
1112
transclude: {
1213
descriptionAddon: "?settingDescriptionAddon"
1314
},
1415
template: `
15-
<div style="display: flex; width: 100%; padding: 20px 0; border-bottom: 2px solid #383D3F;">
16+
<div style="display: flex; width: 100%; padding: 20px 0;" ng-style="{'border-bottom': $ctrl.bottomBorder === false ? 'none' : '2px solid #383D3F'}">
1617
<div style="flex: 1;">
1718
<h4 style="display: flex; align-items: center; gap: 10px;">{{$ctrl.name}}<span ng-if="$ctrl.tag" class="label label-primary">{{$ctrl.tag}}</span></h4>
18-
<div style="opacity: 0.7;">{{$ctrl.description}} <div style="display: inline-block" ng-transclude="descriptionAddon"></div></div>
19+
<div style="opacity: 0.7;">{{$ctrl.description}} <div style="display: inline-block;margin-top: 5px;" ng-transclude="descriptionAddon"></div></div>
1920
</div>
2021
<div ng-transclude style="flex: 1; display:flex; align-items: center; justify-content: flex-end;"></div>
2122
</div>

‎src/types/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export type FirebotSettingsTypes = {
9595
UseOverlayInstances: boolean;
9696
ViewerDB: boolean;
9797
ViewerListPageSize: number;
98+
WebhookDebugLogs: boolean;
9899
WebOnlineCheckin: boolean;
99100
WebServerPort: number;
100101
WhileLoopEnabled: boolean;
@@ -211,6 +212,7 @@ export const FirebotSettingsDefaults: FirebotSettingsTypes = {
211212
UseOverlayInstances: false,
212213
ViewerDB: true,
213214
ViewerListPageSize: 10,
215+
WebhookDebugLogs: false,
214216
WebOnlineCheckin: false,
215217
WebServerPort: 7472,
216218
WhileLoopEnabled: false,

0 commit comments

Comments
 (0)