From 1e5f0cb574de15dd6e1db562214fa09a830ebd53 Mon Sep 17 00:00:00 2001 From: Serg Date: Wed, 3 Jun 2026 18:03:16 +0000 Subject: [PATCH 1/3] Skip encrypted XMPP messages --- bridge/config/config.go | 1 + bridge/xmpp/xmpp.go | 29 +++++++++++++++++++++++++++++ matterbridge.toml.sample | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/bridge/config/config.go b/bridge/config/config.go index 16d2abd644..f1b147e1df 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -196,6 +196,7 @@ type Protocol struct { ShowTopicChange bool // slack ShowUserTyping bool // slack ShowEmbeds bool // discord + SkipEncrypted bool // xmpp SkipTLSVerify bool // IRC, mattermost SkipVersionCheck bool // mattermost StripNick bool // all protocols diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 6a291c5ad4..ff13aa5a8a 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -450,6 +450,30 @@ func (b *Bxmpp) parseChannel(remote string) string { return "" } +// isEncrypted reports whether the message is end-to-end encrypted and therefore +// cannot be relayed as readable text. +func isEncrypted(message xmpp.Chat) bool { + // OTR rides inside the plaintext body + if strings.HasPrefix(message.Text, "?OTR") { + return true + } + for _, e := range message.OtherElem { + switch { + case e.XMLName.Local == "encrypted" && + (e.XMLName.Space == "eu.siacs.conversations.axolotl" || + e.XMLName.Space == "urn:xmpp:omemo:2"): + return true // OMEMO + case e.XMLName.Local == "openpgp" && + e.XMLName.Space == "urn:xmpp:openpgp:0": + return true // OX (XEP-0373) + case e.XMLName.Local == "x" && + e.XMLName.Space == "jabber:x:encrypted": + return true // legacy OpenPGP (XEP-0027) + } + } + return false +} + // skipMessage skips messages that need to be skipped func (b *Bxmpp) skipMessage(message xmpp.Chat) bool { // skip messages from ourselves @@ -467,6 +491,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool { return true } + // skip encrypted messages if configured to do so + if b.GetBool("SkipEncrypted") && isEncrypted(message) { + return true + } + // do not show subjects on connect #732 if strings.Contains(message.Text, "has set the subject to:") && time.Since(b.startTime) < time.Second*5 { return true diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 14d077b3ef..551529c603 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -273,6 +273,11 @@ SkipTLSVerify=true #OPTIONAL (default false) NoTLS=true +#Drop end-to-end encrypted messages (OMEMO, OTR, OpenPGP) instead of relaying +#their unusable plaintext fallback to other bridges. +#OPTIONAL (default false) +SkipEncrypted=false + ## RELOADABLE SETTINGS ## Settings below can be reloaded by editing the file From 909d9c621afb4a5eec913880a0a903598c7c7893 Mon Sep 17 00:00:00 2001 From: Serg Date: Sun, 7 Jun 2026 11:48:41 +0000 Subject: [PATCH 2/3] Update documentation --- changelog.md | 1 + docs/settings.md | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 2df18c0269..3a43911215 100644 --- a/changelog.md +++ b/changelog.md @@ -40,6 +40,7 @@ - Log message type='error' as warnings for easier debugging ([#173](https://github.com/matterbridge-org/matterbridge/pull/173)) - Can now upload files from bytes in addition to sharing attachement URLs ([#23](https://github.com/matterbridge-org/matterbridge/pull/23/)) - Can now receive and download OOB attachments from XMPP channels to share with other bridges ([#23](https://github.com/matterbridge-org/matterbridge/pull/23/)) + - New setting `SkipEncrypted` to ignore encrypted messages (OTR, PGP, OMEMO) ([#217](https://github.com/matterbridge-org/matterbridge/pull/217/)) - discord - Replies will be included inline ([#124](https://github.com/matterbridge-org/matterbridge/pull/124), thanks @lekoOwO), by default like "(re name: message)". This is useful when bridging to destinations that do not understand replies, but distracting when the destination does. Can be disabled with `QuoteDisable=true` under your `[discord]` config. - New setting `EditMaxDays` to ignore edits of older messages. ([#199](https://github.com/matterbridge-org/matterbridge/pull/199)) diff --git a/docs/settings.md b/docs/settings.md index 637272c46c..f81272e2f5 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -158,6 +158,14 @@ Example: enable it `SkipTLSVerify=true` +## SkipEncrypted +Do not relay encrypted messages (OTR, PGP, OMEMO). \ +Only supported by XMPP. + +Setting: OPTIONAL \ +Format: boolean \ +Example: enable it + ## StripNick StripNick only allows alphanumerical nicks. See https://github.com/42wim/matterbridge/issues/285 It will strip other characters from the nick From 00325c865f31054851b86c47531dca34ef141b52 Mon Sep 17 00:00:00 2001 From: Serg Date: Sun, 7 Jun 2026 11:51:06 +0000 Subject: [PATCH 3/3] Moved to proper file --- docs/protocols/xmpp/settings.md | 12 ++++++++++++ docs/settings.md | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/protocols/xmpp/settings.md b/docs/protocols/xmpp/settings.md index 3128af0406..a4ab48abad 100644 --- a/docs/protocols/xmpp/settings.md +++ b/docs/protocols/xmpp/settings.md @@ -61,6 +61,18 @@ Your nick in the rooms NoTLS=true ``` +## SkipEncrypted + +Do not relay encrypted messages (OTR, PGP, OMEMO). + +- Setting: **OPTIONAL** +- Format: *boolean* +- Example: + ```toml + SkipEncrypted=true + ``` + + ## UseDirectTLS Enables direct TLS connection to your server. Most servers by default only support StartTLS, diff --git a/docs/settings.md b/docs/settings.md index f81272e2f5..637272c46c 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -158,14 +158,6 @@ Example: enable it `SkipTLSVerify=true` -## SkipEncrypted -Do not relay encrypted messages (OTR, PGP, OMEMO). \ -Only supported by XMPP. - -Setting: OPTIONAL \ -Format: boolean \ -Example: enable it - ## StripNick StripNick only allows alphanumerical nicks. See https://github.com/42wim/matterbridge/issues/285 It will strip other characters from the nick