split logger into separate module with minor improvements
[websub-hub] / src / logger / data-sanitizers.js
1 'use strict';
2
3 /**
4 * Scrub credential from POST login body data.
5 * @param {Object} data
6 * @param {Boolean} sanitize
7 * @returns {Boolean}
8 */
9 function sanitizePostCredential(data, sanitize = true) {
10 let unclean = false;
11
12 const credentialLength = data && data.ctx && data.ctx.parsedBody && data.ctx.parsedBody.credential && data.ctx.parsedBody.credential.length;
13 if (credentialLength) {
14 unclean = true;
15 }
16 if (unclean && sanitize) {
17 data.ctx.parsedBody.credential = '*'.repeat(credentialLength);
18 }
19
20 return unclean;
21 }
22
23 module.exports = {
24 sanitizePostCredential,
25 };