From cecc4b1f6d7977ddeb180e446549a5b2aeeb249f Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 5 Feb 2015 13:19:47 +0100 Subject: [PATCH] Fix secure URL check. --- packages/xo-lib/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/xo-lib/index.js b/packages/xo-lib/index.js index a3d7d6787..b8554abd3 100644 --- a/packages/xo-lib/index.js +++ b/packages/xo-lib/index.js @@ -14,6 +14,12 @@ function notConnected() { throw new Error('not connected'); } +function startsWith(string, target) { + return (string.lastIndexOf(target, 0) === 0); +} + +//==================================================================== + // Fix URL if necessary. var URL_RE = /^(?:(?:http|ws)(s)?:\/\/)?(.*?)\/*(?:\/api\/)?$/; function fixUrl(url) { @@ -67,7 +73,7 @@ assign(Xo.prototype, { this.status = 'connecting'; var opts = {}; - if (/^https/.test(this._url)) { + if (startsWith(this._url, 'wss')) { // Due to imperfect TLS implementation in XO-Server. opts.rejectUnauthorized = false; }