node.js - 温斯顿:加密敏感信息
问题描述
我开始使用 winston、express-winston 和 winston-mongodb 来记录请求和响应并将它们添加到 mongodb。一段时间后,我能够生成日志,同时还可以在需要使用黑/白名单时将信息隐藏在正文中,但我真正需要的是在将密码等所有敏感数据保存到数据库之前对其进行加密。如何在保存数据之前自定义数据?
例子:
前
{
"_id" : ObjectId("5bbf30b37ca8b70015b8efc6"),
"timestamp" : ISODate("2018-10-11T11:14:59.084Z"),
"level" : "info",
"message" : "HTTP POST /auth - 200 - 147ms",
"meta" : {
"res" : {
"statusCode" : 200
},
"req" : {
"url" : "/auth",
"headers" : {
"host" : "???.herokuapp.com",
"connection" : "close",
"content-type" : "application/json; charset=UTF-8",
"accept-encoding" : "gzip",
"user-agent" : "okhttp/3.10.0",
"x-request-id" : "3b42aa9c-6ead-44cd-939f-cc09bb5318c3",
"x-forwarded-for" : "0.0.0.0",
"x-forwarded-proto" : "https",
"x-forwarded-port" : "443",
"via" : "1.1 vegur",
"connect-time" : "0",
"x-request-start" : "1539256498932",
"total-route-time" : "0",
"content-length" : "54"
},
"method" : "POST",
"httpVersion" : "1.1",
"originalUrl" : "/auth",
"query" : {},
"body" : {
"email" : "abc@test.com",
"password": "123abc"
}
},
"responseTime" : 147
}
}
后
"body" : {
"email" : "abc@test.com",
"password": "ENCRYPTEDPASSWORD"
}
解决方案
推荐阅读
- javascript - 如果值不相等,ACF 选择值将类添加到 div
- apache - Googlebot-Image/1.0 请求多张图片
- sql - 插入null时如何设置默认值
- maven - Jenkins 控制台不显示在 docker 容器上运行的命令的输出
- java - JavaFx 从数据框创建图表
- javascript - 如果模型不存在,为什么 IE 呈现 null
- hp-uft - SAPGuiSession.Sync 有什么意义
- python - csv的2个元素列表
- javascript - PHP:通过 PHP 或 Javascript 将数组值从文本转换为带有 HTML 替换的图标
- kdb - KDB:如何沿表的每条记录打印字符串文字?