const freezeDeep = (o) => {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach((prop) => {
- if (Object.hasOwnProperty.call(o, prop)
+ if (Object.hasOwn(o, prop)
&& ['object', 'function'].includes(typeof o[prop]) // eslint-disable-line security/detect-object-injection
&& !Object.isFrozen(o[prop])) { // eslint-disable-line security/detect-object-injection
return freezeDeep(o[prop]); // eslint-disable-line security/detect-object-injection
};
};
+/**
+ * Hide sensitive part of an Authorization header.
+ * @param {String} authHeader
+ * @returns {String}
+ */
+const obscureAuthorizationHeader = (authHeader) => {
+ if (!authHeader) {
+ return authHeader;
+ }
+ const space = authHeader.indexOf(' ');
+ // This blurs entire string if no space found, because -1.
+ return authHeader.slice(0, space + 1) + '*'.repeat(authHeader.length - (space + 1));
+};
+
module.exports = Object.assign(Object.create(common), {
freezeDeep,
mysteryBoxLogger,
+ obscureAuthorizationHeader,
omit,
});
\ No newline at end of file