Browse Source

Made changes to ubuntu-server to reject connections not from localhost

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
tags/0.13.0-mobile
Volodymyr Kozieiev 3 months ago
parent
commit
807e816936
No account linked to committer's email address
1 changed files with 14 additions and 1 deletions
  1. 14
    1
      ubuntu-server.js

+ 14
- 1
ubuntu-server.js View File

@@ -114,6 +114,18 @@ function rnUbuntuServer(readable, writable) {
});
}

var closeDangerousConnection = function(sock) {
var remoteAddress = sock.remoteAddress;
if(remoteAddress.indexOf("127.0.0.1") == -1) {
console.log("WARN: connection not from localhost, will be closed: ", remoteAddress);
sock.destroy();
return true;
} else {
console.log("Connection from: ", remoteAddress);
return false;
}
}

if (process.argv.indexOf('--pipe') != -1) {
console.log = console.error
rnUbuntuServer(process.stdin, process.stdout);
@@ -127,6 +139,7 @@ if (process.argv.indexOf('--pipe') != -1) {

var server = net.createServer((sock) => {
DEBUG && console.error("-- Connection from RN client");
rnUbuntuServer(sock, sock);
if(!closeDangerousConnection(sock))
rnUbuntuServer(sock, sock);
}).listen(port, function() { console.error("-- Server starting") });
}

Loading…
Cancel
Save