diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index a3051eea7f..6bef09740a 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -2,6 +2,7 @@ const PouchDB = require("pouchdb") const replicationStream = require("pouchdb-replication-stream") const allDbs = require("pouchdb-all-dbs") const { budibaseAppsDir } = require("../utilities/budibaseDir") +const { sanitise } = require("../utilities/sanitisedPath") const env = require("../environment") const COUCH_DB_URL = env.COUCH_DB_URL || `leveldb://${budibaseAppsDir()}/.data/` @@ -26,4 +27,10 @@ const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS) allDbs(Pouch) -module.exports = Pouch +function PouchWrapper(instance) { + Pouch.apply(this, [sanitise(instance)]) +} + +PouchWrapper.prototype = Object.create(Pouch.prototype) + +module.exports = PouchWrapper diff --git a/packages/server/src/utilities/sanitisedPath.js b/packages/server/src/utilities/sanitisedPath.js index a5bfcaf080..c2c304aad9 100644 --- a/packages/server/src/utilities/sanitisedPath.js +++ b/packages/server/src/utilities/sanitisedPath.js @@ -27,3 +27,12 @@ exports.join = function(...args) { exports.resolve = function(...args) { return path.resolve(...sanitiseArgs(args)) } + +/** + * Sanitise a single string + * @param string input string to sanitise + * @returns {string} the final sanitised string + */ +exports.sanitise = function(string) { + return sanitiseArgs([string])[0] +}