Skip to content

Commit cb48e51

Browse files
committed
Add carbon source verification (CVE-2017-5589)
1 parent 3674fd0 commit cb48e51

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/im-factory.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ im_factory_message_cb (
217217
gboolean create_if_missing;
218218
gboolean sent;
219219

220+
/* CVE-2017-5589+ verification */
221+
if (wocky_node_get_child_ns (wocky_stanza_get_top_node (message), "received", NS_CARBONS)
222+
|| wocky_node_get_child_ns (wocky_stanza_get_top_node (message), "sent", NS_CARBONS))
223+
{
224+
if ((from = wocky_stanza_get_from (message)) != NULL)
225+
{
226+
TpBaseConnection *conn = TP_BASE_CONNECTION (fac->priv->conn);
227+
TpHandleRepoIface *handles = tp_base_connection_get_handles (conn,
228+
TP_HANDLE_TYPE_CONTACT);
229+
TpHandle from_handle = tp_handle_ensure (handles, from, NULL, NULL);
230+
TpHandle self_handle = tp_base_connection_get_self_handle (conn);
231+
232+
if (from_handle != self_handle)
233+
return FALSE;
234+
}
235+
}
236+
220237
if (!gabble_message_util_parse_incoming_message (message, &from, &to, &stamp,
221238
&msgtype, &id, &body, &state, &send_error, &delivery_status, &delivery_token, &sent))
222239
return TRUE;

tests/twisted/text/test-carbons.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from gabbletest import XmppXmlStream, exec_test, elem, acknowledge_iq
77
from servicetest import (EventPattern, wrap_channel, assertEquals, assertLength,
8-
assertContains)
8+
assertContains, TimeoutError)
99
import constants as cs
1010

1111
NS_CARBONS = 'urn:xmpp:carbons:2'
@@ -172,6 +172,25 @@ def test(q, bus, conn, stream):
172172
assert body['content-type'] == 'text/plain', body
173173
assert body['content'] == u'goodbye', body
174174

175+
# Verify source protection
176+
msg = elem('message', type='chat', from_='[email protected]/agent712')(
177+
elem(NS_CARBONS, 'received')(
178+
elem(NS_FORWARD, 'forwarded')(
179+
elem('jabber:client','message', id=id, from_='[email protected]/Pidgin', type='chat')(
180+
elem('body')('Mr. Anderson!')
181+
)
182+
)
183+
)
184+
)
185+
stream.send(msg)
186+
# This is a nasty test but we need to make sure spoofed message is ignored
187+
try:
188+
q.timeout = 2
189+
message_received = q.expect('dbus-signal', signal='MessageReceived')
190+
assert not message_received, message_received.args
191+
except TimeoutError as e:
192+
pass
193+
175194

176195
if __name__ == '__main__':
177196
exec_test(test, protocol=CarbonStream, params={'message-carbons':True})

0 commit comments

Comments
 (0)