Comparing version 1.0.4 to 1.0.19
@@ -123,2 +123,8 @@ "use strict"; | ||
const FILTER_PARAMETERS_REPLACER = '********'; | ||
/** | ||
* 过滤日志参数,替换为 ********,避免敏感信息泄露,仅支持 对象和 Map | ||
* @param obj - 需要过滤的对象 | ||
* @param depth - 对象层级 | ||
* @returns 过滤后的对象 | ||
*/ | ||
function filterParameters(obj, depth = 10) { | ||
@@ -131,22 +137,24 @@ if (exports.FILTER_LOGGER_PARAMETERS.size === 0) | ||
if (lodash_1.default.isMap(obj)) { | ||
const map = new Map(); | ||
obj.forEach(function (value, key) { | ||
if (exports.FILTER_LOGGER_PARAMETERS.has(key)) { | ||
obj.set(key, FILTER_PARAMETERS_REPLACER); | ||
map.set(key, FILTER_PARAMETERS_REPLACER); | ||
} | ||
else { | ||
obj.set(key, filterParameters(value, restDepth)); | ||
map.set(key, filterParameters(value, restDepth)); | ||
} | ||
}); | ||
return obj; | ||
return map; | ||
} | ||
if (lodash_1.default.isPlainObject(obj)) { | ||
const newObj = {}; | ||
for (const key in obj) { | ||
if (exports.FILTER_LOGGER_PARAMETERS.has(key)) { | ||
obj[key] = FILTER_PARAMETERS_REPLACER; | ||
newObj[key] = FILTER_PARAMETERS_REPLACER; | ||
} | ||
else { | ||
obj[key] = filterParameters(obj[key], restDepth); | ||
newObj[key] = filterParameters(obj[key], restDepth); | ||
} | ||
} | ||
return obj; | ||
return newObj; | ||
} | ||
@@ -153,0 +161,0 @@ return obj; |
{ | ||
"name": "takin", | ||
"version": "1.0.4", | ||
"version": "1.0.19", | ||
"description": "Front end engineering base toolchain and scaffold", | ||
@@ -70,3 +70,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "660989eb25464172cebd90a5ac077d0097c07365" | ||
"gitHead": "8c63c604fe1562b099e193929444ad30316e4da6" | ||
} |
Sorry, the diff of this file is not supported yet
392432
7240