X-Git-Url: http://git.squeep.com/?p=squeep-authentication-module;a=blobdiff_plain;f=lib%2Fcommon.js;h=1a117e9a71d7ff877abd15c7b9fd467315cd0818;hp=d69e6ad6a2131d12d975dbaaddaca70fdb3551e5;hb=05f10d7419d363570d3c553afc0aed211afecb4b;hpb=a821a0f79c42f8ea55aec503c992650113d82028 diff --git a/lib/common.js b/lib/common.js index d69e6ad..1a117e9 100644 --- a/lib/common.js +++ b/lib/common.js @@ -46,8 +46,23 @@ const mysteryBoxLogger = (logger, scope) => { }; }; +/** + * 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