From b538163058fbbc73cd44a28621ff65c722008cfd Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 11 Jul 2016 17:22:53 +0200 Subject: [PATCH] Signaling: Ensure that responder id does not conflict with own address Refs #24 --- saltyrtc/signaling.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/saltyrtc/signaling.ts b/saltyrtc/signaling.ts index e257ad4..5c77430 100644 --- a/saltyrtc/signaling.ts +++ b/saltyrtc/signaling.ts @@ -322,6 +322,9 @@ export class Signaling { * Do the server handshake. * * The `buffer` argument contains the `server-hello` packet. + * + * If an exception is thrown in this method, it will be converted to a + * protocol error. */ private async serverHandshake(buffer: ArrayBuffer): Promise { @@ -421,6 +424,11 @@ export class Signaling { if (this.role == 'initiator') { this.responders = new Map(); for (let id of message.responders) { + // Make sure that responder id is different from own id + if (id === this.address) { + console.error(this.logTag, 'Responder id matches own address.'); + throw 'address-conflict'; + } this.responders.set(id, new Responder(id)); this.client.emit({type: 'new-responder', data: id}); } @@ -721,6 +729,10 @@ export class Signaling { // A new responder wants to connect. Store id. const id = (message as saltyrtc.messages.NewResponder).id; if (!this.responders.has(id)) { + if (id === this.address) { + console.error(this.logTag, 'Responder id matches own address.'); + abort(); + } this.responders.set(id, new Responder(id)); this.client.emit({type: 'new-responder', data: id}); } else {