Closed mrclschstr closed 6 months ago
Maybe jq
could be used to escape the ${BODY}
variable for webhooks? Example:
Issue is still present in version 2024-02
.
I have rummaged through the watchdog.sh
script and found the error. It is in this line:
The problem is the message subject during an IP ban that looks like IP ban: fe80::7645:6de2:ff:1/128
or IP ban: 127.0.0.1/24
, for example. Specifically, the problem lies in the CIDR notation of the IP address with the slash /
contained in it, which is also used as a separator in sed
. The following error message is displayed in bash:
sed: -e expression #1, char 105: unknown option to `s'
A simple fix could be to replace the separator to #
for the subject, such as (inspired by https://unix.stackexchange.com/a/378991):
WEBHOOK_BODY=$(echo ${WATCHDOG_NOTIFY_WEBHOOK_BODY} | sed "s#\$SUBJECT\|\${SUBJECT}#$SUBJECT#g" | sed "s/\$BODY\|\${BODY}/$BODY/g")
Unfortunately, I cannot judge whether changing the separator provokes another error.
Already did it. Originally i used |
as a separator, but it was reverted with this PR as it didn't fully work.
https://github.com/mailcow/mailcow-dockerized/pull/5647
The only other possibility I can think of off the top of my head would be sanitizing the replacement string.
You could use bash variable expansion, for example (inspired by https://stackoverflow.com/a/13210909):
sed "s/\$SUBJECT\|\${SUBJECT}/${SUBJECT//\//\\/}/g"
Caution: Not fully tested!
[EDIT] See also:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Contribution guidelines
I've found a bug and checked that ...
Description
I have seen that you can now also use webhooks for the watchdog notifications:
I have therefore made the following settings in
mailcow.conf
(inspired by: https://community.mailcow.email/d/2234-watchdog-notification-how-to-enable-pushover-notification/7):With the setting
WATCHDOG_NOTIFY_BAN=y
I wanted to get an overview of current IP bans. However, I noticed in the Docker logs that an error is generated when a ban notification is sent (see logs below).I am sure that the token is not the problem as the notification about the watchdog start (
WATCHDOG_NOTIFY_START=y
) is delivered normally. I have already contacted Pushover support to get details about the request. The short answer was simply:I therefore suspect that the body of the webhook is causing a syntax error in the event of an IP ban. Do a few special characters need to be escaped here?
Logs:
Steps to reproduce:
docker compose logs watchdog-mailcow | grep -i "webhook"
Which branch are you using?
master
Which architecture are you using?
x86
Operating System:
Ubuntu 22.04.3 LTS
Server/VM specifications:
4 vCPU, 8 GB RAM
Is Apparmor, SELinux or similar active?
No
Virtualization technology:
KVM
Docker version:
24.0.7
docker-compose version or docker compose version:
v2.21.0
mailcow version:
2024-01e
Reverse proxy:
No
Logs of git diff:
Logs of iptables -L -vn:
Logs of ip6tables -L -vn:
Logs of iptables -L -vn -t nat:
Logs of ip6tables -L -vn -t nat:
DNS check: