Skip to content

Commit 37d8e4a

Browse files
committed
OF-2189: Apply privacy lists to CC'ed stanzas.
This prevents stanzas to bypass a privacy list or blocklist, when they're included in a carbon copy.
1 parent 7d3ed5d commit 37d8e4a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

xmppserver/src/main/java/org/jivesoftware/openfire/carbons/Received.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.jivesoftware.openfire.carbons;
22

3+
import org.dom4j.Element;
34
import org.jivesoftware.openfire.forward.Forwarded;
4-
import org.xmpp.packet.PacketExtension;
5+
import org.xmpp.packet.*;
6+
7+
import javax.annotation.Nonnull;
58

69
/**
710
* The implementation of the {@code <received xmlns="urn:xmpp:carbons:2"/>} extension.
@@ -14,8 +17,28 @@ public final class Received extends PacketExtension {
1417
public static final String NAME = "received";
1518
public static final String NAMESPACE = "urn:xmpp:carbons:2";
1619

17-
public Received(Forwarded forwarded) {
20+
public Received(@Nonnull final Forwarded forwarded) {
1821
super(NAME, NAMESPACE);
1922
element.add(forwarded.getElement());
2023
}
24+
25+
public Packet getForwardedStanza() {
26+
if (element.element("forwarded") == null) {
27+
return null;
28+
}
29+
if (element.element("forwarded").elements() == null) {
30+
return null;
31+
}
32+
final Element originalStanza = element.element("forwarded").elements().get(0);
33+
switch (originalStanza.getName()) {
34+
case "message":
35+
return new Message(originalStanza, true);
36+
case "iq":
37+
return new IQ(originalStanza, true);
38+
case "presence":
39+
return new Presence(originalStanza, true);
40+
default:
41+
throw new IllegalArgumentException("A 'forwarded' stanza must by of type 'message', 'iq' or 'presence', not: " + originalStanza.getName());
42+
}
43+
}
2144
}

xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalClientSession.java

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.jivesoftware.openfire.XMPPServer;
2424
import org.jivesoftware.openfire.auth.AuthToken;
2525
import org.jivesoftware.openfire.auth.UnauthorizedException;
26+
import org.jivesoftware.openfire.carbons.Received;
2627
import org.jivesoftware.openfire.cluster.ClusterManager;
2728
import org.jivesoftware.openfire.entitycaps.EntityCapabilitiesManager;
2829
import org.jivesoftware.openfire.net.SASLAuthentication;
@@ -873,6 +874,21 @@ public void setHasRequestedBlocklist(boolean hasRequestedBlocklist) {
873874
@Override
874875
public boolean canProcess(Packet packet) {
875876

877+
// If the packet is a forwarded stanza (eg: carbon copy), ensure that the forwarded message would have
878+
// passed the privacy lists that are active for _this_ session. Note that the active list could differ
879+
// for each session of a particular user! (OF-2189)
880+
// Implementation note: it might be tempting to implement this in org.jivesoftware.openfire.spi.RoutingTableImpl.ccMessage
881+
// There is, however, no way to check the active privacy list for sessions on remote cluster nodes there.
882+
final Received received = (Received) packet.getExtension(Received.NAME, Received.NAMESPACE);
883+
if (received != null) {
884+
final Packet forwardedStanza = received.getForwardedStanza();
885+
if (forwardedStanza != null) {
886+
if (!canProcess(forwardedStanza)) {
887+
return false;
888+
}
889+
}
890+
}
891+
876892
PrivacyList list = getActiveList();
877893
if (list != null) {
878894
// If a privacy list is active then make sure that the packet is not blocked

0 commit comments

Comments
 (0)