首页 > 解决方案 > 温斯顿:加密敏感信息

问题描述

我开始使用 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"
}

标签: node.jsexpressloggingwinston

解决方案


推荐阅读