From 975d30c26160bd8ebfdef0ca0eeb78cb87baee13 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 12 Aug 2022 23:31:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client.js | 2 -- src/lib/middleware/prisma-encryption.js | 45 ------------------------- 2 files changed, 47 deletions(-) delete mode 100644 src/lib/middleware/prisma-encryption.js diff --git a/src/client.js b/src/client.js index f058fbb..0e91785 100644 --- a/src/client.js +++ b/src/client.js @@ -9,7 +9,6 @@ const fs = require('fs'); const { join } = require('path'); const YAML = require('yaml'); const TicketManager = require('./lib/tickets/manager'); -const encryptionMiddleware = require('./lib/middleware/prisma-encryption'); const sqliteMiddleware = require('./lib/middleware/prisma-sqlite'); module.exports = class Client extends FrameworkClient { @@ -52,7 +51,6 @@ module.exports = class Client extends FrameworkClient { async login(token) { /** @type {PrismaClient} */ this.prisma = new PrismaClient(); - this.prisma.$use(encryptionMiddleware); if (process.env.DB_PROVIDER === 'sqlite') this.prisma.$use(sqliteMiddleware); this.keyv = new Keyv(); return super.login(token); diff --git a/src/lib/middleware/prisma-encryption.js b/src/lib/middleware/prisma-encryption.js deleted file mode 100644 index 87836e4..0000000 --- a/src/lib/middleware/prisma-encryption.js +++ /dev/null @@ -1,45 +0,0 @@ -const Cryptr = require('cryptr'); -const cryptr = new Cryptr(process.env.ENCRYPTION_KEY); -const encryptedFields = [ - // 'name', - 'content', - 'username', - 'displayName', - // 'channelName', - // 'openingMessage', - // 'description', - 'value', - // 'placeholder', - 'closedReason', - 'topic', - 'comment', - // 'label', - // 'regex', -]; - -const traverse = (obj, action) => { - for (const prop in obj) { - if (encryptedFields.includes(prop) && typeof obj[prop] === 'string' && obj[prop].length !== 0) { - try { - // prevent double encryption bug (from nested writes - notably upserting questions in category update). - // not sure why it happens - if (action === 'ENCRYPT' && cryptr.decrypt(obj[prop])) continue; // don't encrypt if it already encrypted - else obj[prop] = cryptr[action.toLowerCase()](obj[prop]); - } catch { - // do nothing - } - } else if (typeof obj[prop] === 'object') { - obj[prop] = traverse(obj[prop], action); - } - } - return obj; -}; - -module.exports = async (params, next) => { - if (params.args.create) params.args.create = traverse(params.args.create, 'ENCRYPT'); - if (params.args.data) params.args.data = traverse(params.args.data, 'ENCRYPT'); - if (params.args.update) params.args.update = traverse(params.args.update, 'ENCRYPT'); - let result = await next(params); - if (result) result = traverse(result, 'DECRYPT'); - return result; -}; \ No newline at end of file