Skip to content

Commit 50073cb

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 b8e18ab commit 50073cb

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-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

+17
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import java.net.UnknownHostException;
2020
import java.util.*;
2121

22+
import org.dom4j.Element;
2223
import org.jivesoftware.openfire.Connection;
2324
import org.jivesoftware.openfire.SessionManager;
2425
import org.jivesoftware.openfire.StreamID;
2526
import org.jivesoftware.openfire.XMPPServer;
2627
import org.jivesoftware.openfire.auth.AuthToken;
2728
import org.jivesoftware.openfire.auth.UnauthorizedException;
29+
import org.jivesoftware.openfire.carbons.Received;
2830
import org.jivesoftware.openfire.cluster.ClusterManager;
2931
import org.jivesoftware.openfire.entitycaps.EntityCapabilitiesManager;
3032
import org.jivesoftware.openfire.net.SASLAuthentication;
@@ -969,6 +971,21 @@ public void setHasRequestedBlocklist(boolean hasRequestedBlocklist) {
969971
@Override
970972
public boolean canProcess(Packet packet) {
971973

974+
// If the packet is a forwarded stanza (eg: carbon copy), ensure that the forwarded message would have
975+
// passed the privacy lists that are active for _this_ session. Note that the active list could differ
976+
// for each session of a particular user! (OF-2189)
977+
// Implementation note: it might be tempting to implement this in org.jivesoftware.openfire.spi.RoutingTableImpl.ccMessage
978+
// There is, however, no way to check the active privacy list for sessions on remote cluster nodes there.
979+
final Received received = (Received) packet.getExtension(Received.NAME, Received.NAMESPACE);
980+
if (received != null) {
981+
final Packet forwardedStanza = received.getForwardedStanza();
982+
if (forwardedStanza != null) {
983+
if (!canProcess(forwardedStanza)) {
984+
return false;
985+
}
986+
}
987+
}
988+
972989
PrivacyList list = getActiveList();
973990
if (list != null) {
974991
// If a privacy list is active then make sure that the packet is not blocked

0 commit comments

Comments
 (0)