'use strict';
/**
- * Here are some sanitizers to replace data fields before logging.
- * Well, really, this just documents the expected format.
+ * Sanitizers replace data fields before logging.
+ * None are bundled, but here is an example of one.
*/
/**
- * template for sanitizers
+ * Example sanitizer function.
+ * Sanitizers are called initially with `sanitize` false, to only determine
+ * whether the data object will be changed. If so, the sanitizer is then
+ * called again with `sanitize` true, but provided with a clone of the
+ * original data to update, to avoid leaking any applied changes back to the
+ * application.
* @param {Object} data
* @param {Boolean} sanitize
- * @returns {Boolean}
+ * @returns {Boolean} whether sanitizer is applicable to data
*/
/* istanbul ignore next */
function _sanitizer(data, sanitize = true) {
let unclean = false;
- if (undefined) { // eslint-disable-line no-constant-condition
+ const sensitiveFieldLength = data?.sensitiveField?.length;
+ if (sensitiveFieldLength) {
unclean = true;
- }
- if (unclean && sanitize) {
- data;
+
+ if (sanitize) {
+ data.sensitiveField = '*'.repeat(sensitiveFieldLength);
+ }
}
return unclean;