From 15ab25940e9fa9ee6d47061047d76e1b133427fc Mon Sep 17 00:00:00 2001 From: Taylor Stine Date: Mon, 1 Feb 2016 14:15:30 -0500 Subject: [PATCH 1/2] Added encoding to user name and password --- ExportAdapter.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index 89cb6c5900..ffb493fe7f 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -34,8 +34,19 @@ ExportAdapter.prototype.connect = function() { return this.connectionPromise; } + var usernameStart = this.mongoURI.indexOf('://') + 3; + var lastAtIndex = this.mongoURI.lastIndexOf('@'); + var encodedMongoURI = this.mongoURI; + var username = null; + var password = null; + var split = null + if (lastAtIndex > 0) { + split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':'); + encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex); + } + this.connectionPromise = Promise.resolve().then(() => { - return MongoClient.connect(this.mongoURI); + return MongoClient.connect(encodedMongoURI, {uri_decode_auth:true}); }).then((db) => { this.db = db; }); From 97cf00b4d01044d48fad37be244b8786fe143195 Mon Sep 17 00:00:00 2001 From: Taylor Stine Date: Tue, 2 Feb 2016 07:31:50 -0500 Subject: [PATCH 2/2] added regex to validate mongo uri and remove unused variables --- ExportAdapter.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ExportAdapter.js b/ExportAdapter.js index ffb493fe7f..db586d8348 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -34,12 +34,14 @@ ExportAdapter.prototype.connect = function() { return this.connectionPromise; } + //http://regexr.com/3cn6m + if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):([^:]+)\/(.+?)$/gm)) { + throw new Error("Invalid mongoURI: " + this.mongoURI) + } var usernameStart = this.mongoURI.indexOf('://') + 3; var lastAtIndex = this.mongoURI.lastIndexOf('@'); var encodedMongoURI = this.mongoURI; - var username = null; - var password = null; - var split = null + var split = null; if (lastAtIndex > 0) { split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':'); encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex);