From c13cd6b1c340663b7c6312080b5b69a0341ca1a1 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Mon, 18 Sep 2017 12:11:09 +0300 Subject: [PATCH] Log invalid magic's --- lib/attachments/gridstore-storage.js | 11 +++++++++++ lib/errors.js | 4 +++- server.js | 2 -- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/attachments/gridstore-storage.js b/lib/attachments/gridstore-storage.js index cf471817..295cadde 100644 --- a/lib/attachments/gridstore-storage.js +++ b/lib/attachments/gridstore-storage.js @@ -2,6 +2,7 @@ const GridFSBucket = require('mongodb').GridFSBucket; const libbase64 = require('libbase64'); +const errors = require('../errors'); // Set to false to disable base64 decoding feature const FEATURE_DECODE_ATTACHMENTS = true; @@ -50,6 +51,10 @@ class GridstoreStorage { transferEncoding: attachment.transferEncoding }; + if (!isNaN(metadata.m)) { + errors.notify(new Error('Invalid magic "' + metadata.m + '" for ' + id)); + } + Object.keys(attachment.metadata || {}).forEach(key => { if (!(key in attachment.metadata)) { metadata[key] = attachment.metadata[key]; @@ -193,6 +198,9 @@ class GridstoreStorage { } delete(id, magic, callback) { + if (!isNaN(magic)) { + errors.notify(new Error('Invalid magic "' + magic + '" for ' + id)); + } this.gridfs.collection(this.bucketName + '.files').findOneAndUpdate({ _id: id }, { @@ -231,6 +239,9 @@ class GridstoreStorage { } update(ids, count, magic, callback) { + if (!isNaN(magic)) { + errors.notify(new Error('Invalid magic "' + magic + '" for ' + ids)); + } // update attachments this.gridfs.collection(this.bucketName + '.files').updateMany( { diff --git a/lib/errors.js b/lib/errors.js index 61c66423..dcea0790 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -1,4 +1,4 @@ -/* eslint global-require: 0 */ +/* eslint global-require: 0, no-console: 0 */ 'use strict'; const config = require('wild-config'); @@ -12,5 +12,7 @@ if (config.bugsnagCode) { module.exports.notify = (...args) => { if (bugsnag) { bugsnag.notify(...args); + } else { + console.error(...args); } }; diff --git a/server.js b/server.js index ed3f0d70..12d87348 100644 --- a/server.js +++ b/server.js @@ -19,8 +19,6 @@ const packageData = require('./package.json'); log.level = config.log.level; require('./logger'); -errors.notify(new Error('Starting mail server application')); - const printLogo = () => { let logo = fs .readFileSync(__dirname + '/logo.txt', 'utf-8')