Skip to content

Commit f17b35b

Browse files
committed
Allow inbound traffic from browser ports bound to the "ANY" interface.
Fixes UWNetworksLab/uProxy-p2p#2334
1 parent 1dfe26b commit f17b35b

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

src/churn-pipe/churn-pipe.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ class Pipe {
9696
// most one port on each interface.
9797
private browserEndpoints_ :{ [address:string]:number } = {};
9898

99+
// The set of ports used by the browser. All values are true.
100+
// This is only needed because Pipe's mirror sockets are bound to the ANY
101+
// interface (0.0.0.0). If the browser also binds to ANY, packets between
102+
// these interfaces may appear to originate from any local interface, so we
103+
// can't require that source addresses and ports match.
104+
// This object allows O(1) lookup of whether ports are available.
105+
private browserPorts_: {[port:number]:boolean } = {};
106+
99107
// The most recently set public interface for IPv6 and IPv4. Used to
100108
// report mirror endpoints.
101109
private lastInterface_ : {v6?:string; v4?:string;} = {};
@@ -262,6 +270,7 @@ class Pipe {
262270
this.name_, this.browserEndpoints_[browserEndpoint.address])
263271
}
264272
this.browserEndpoints_[browserEndpoint.address] = browserEndpoint.port;
273+
this.browserPorts_[browserEndpoint.port] = true;
265274
return Promise.resolve<void>();
266275
}
267276

@@ -330,16 +339,22 @@ class Pipe {
330339
mirrorSocket.on('onData', (recvFromInfo:freedom.UdpSocket.RecvFromInfo) => {
331340
// Ignore packets that do not originate from the browser, for a
332341
// theoretical security benefit.
333-
if (recvFromInfo.port !==
334-
this.browserEndpoints_[recvFromInfo.address]) {
335-
log.warn('%1: mirror socket for %2 ignoring incoming packet from %3 ' +
336-
'which should have had source port %4',
342+
if (!(recvFromInfo.address in this.browserEndpoints_)) {
343+
log.warn('%1: mirror socket for %2 ignoring incoming packet from %3: ' +
344+
'unknown source address',
345+
this.name_,
346+
remoteEndpoint, {
347+
address: recvFromInfo.address,
348+
port: recvFromInfo.port
349+
});
350+
} else if (!(recvFromInfo.port in this.browserPorts_)) {
351+
log.warn('%1: mirror socket for %2 ignoring incoming packet from %3: ' +
352+
'unknown source port',
337353
this.name_,
338354
remoteEndpoint, {
339355
address: recvFromInfo.address,
340356
port: recvFromInfo.port
341-
},
342-
this.browserEndpoints_[recvFromInfo.address]);
357+
});
343358
} else {
344359
var publicSocket = this.publicSockets_[recvFromInfo.address] &&
345360
this.publicSockets_[recvFromInfo.address][index];

0 commit comments

Comments
 (0)