This commit is contained in:
Isaac 2022-08-12 23:31:02 +01:00
parent a190c1ac27
commit 975d30c261
No known key found for this signature in database
GPG Key ID: F4EAABEB0FFCC06A
2 changed files with 0 additions and 47 deletions

View File

@ -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);

View File

@ -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;
};