Bug 1356229 - Prevent non-loopback connections in Marionette; r?whimboo
This patch removes the Marionette server's ability to accept non-loopback
connections completely. The configuration option for this, the
marionette.forcelocal preference, was removed in the previous patch in
this changeset.
MozReview-Commit-ID: 3XXYpTDGs8S
--- a/testing/marionette/server.js
+++ b/testing/marionette/server.js
@@ -19,16 +19,18 @@ Cu.import("chrome://marionette/content/d
Cu.import("chrome://marionette/content/error.js");
Cu.import("chrome://marionette/content/message.js");
// Bug 1083711: Load transport.js as an SDK module instead of subscript
loader.loadSubScript("resource://devtools/shared/transport/transport.js");
const logger = Log.repository.getLogger("Marionette");
+const {KeepWhenOffline, LoopbackOnly} = Ci.nsIServerSocket;
+
this.EXPORTED_SYMBOLS = ["server"];
this.server = {};
const PROTOCOL_VERSION = 3;
const PREF_CONTENT_LISTENER = "marionette.contentListener";
const PREF_RECOMMENDED = "marionette.prefs.recommended";
@@ -263,23 +265,19 @@ const RECOMMENDED_PREFS = new Map([
* Starting the Marionette server will open a TCP socket sporting the
* debugger transport interface on the provided |port|. For every new
* connection, a |server.TCPConnection| is created.
*/
server.TCPListener = class {
/**
* @param {number} port
* Port for server to listen to.
- * @param {boolean=} forceLocal
- * Listen only to connections from loopback if true (default).
- * When false, accept all connections.
*/
- constructor (port, forceLocal = true) {
+ constructor (port) {
this.port = port;
- this.forceLocal = forceLocal;
this.conns = new Set();
this.nextConnID = 0;
this.alive = false;
this._acceptConnections = false;
this.alteredPrefs = new Set();
}
/**
@@ -316,21 +314,19 @@ server.TCPListener = class {
if (!Preferences.isSet(k)) {
logger.debug(`Setting recommended pref ${k} to ${v}`);
Preferences.set(k, v);
this.alteredPrefs.add(k);
}
}
}
- let flags = Ci.nsIServerSocket.KeepWhenOffline;
- if (this.forceLocal) {
- flags |= Ci.nsIServerSocket.LoopbackOnly;
- }
- this.listener = new ServerSocket(this.port, flags, 1);
+ const flags = KeepWhenOffline | LoopbackOnly;
+ const backlog = 1;
+ this.listener = new ServerSocket(this.port, flags, backlog);
this.listener.asyncListen(this);
this.alive = true;
this._acceptConnections = true;
}
stop () {
if (!this.alive) {