From 4bda0e5af379380efc4fd425531a4f55c86df5e4 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 2 Jun 2023 14:17:59 -0700 Subject: [PATCH] Redacting sensitive fields in debug logs. PiperOrigin-RevId: 537407555 --- examples/seccheck/BUILD | 1 + examples/seccheck/server.cc | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/seccheck/BUILD b/examples/seccheck/BUILD index 9db11222f..6b1b13543 100644 --- a/examples/seccheck/BUILD +++ b/examples/seccheck/BUILD @@ -22,5 +22,6 @@ cc_binary( "//pkg/sentry/seccheck/points:points_cc_proto", "@com_google_absl//absl/cleanup", "@com_google_absl//absl/strings", + "@com_google_protobuf//:protobuf", ], ) diff --git a/examples/seccheck/server.cc b/examples/seccheck/server.cc index 7ac859907..c203f1527 100644 --- a/examples/seccheck/server.cc +++ b/examples/seccheck/server.cc @@ -27,11 +27,13 @@ #include #include "absl/cleanup/cleanup.h" +#include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" #include "pkg/sentry/seccheck/points/common.pb.h" #include "pkg/sentry/seccheck/points/container.pb.h" #include "pkg/sentry/seccheck/points/sentry.pb.h" #include "pkg/sentry/seccheck/points/syscall.pb.h" +#include "google/protobuf/text_format.h" typedef std::function Callback; @@ -56,6 +58,14 @@ void log(const char* fmt, ...) { } } +template +std::string shortfmt(T msg) { + std::string short_text_msg; + google::protobuf::TextFormat::PrintToString(msg, &short_text_msg); + return absl::StrReplaceAll(short_text_msg, + {{"\r\n", " "}, {"\n", " "}, {"\r", " "}}); +} + template void unpackSyscall(absl::string_view buf) { T evt; @@ -63,8 +73,7 @@ void unpackSyscall(absl::string_view buf) { err(1, "ParseFromString(): %.*s", static_cast(buf.size()), buf.data()); } log("%s %s %s\n", evt.has_exit() ? "X" : "E", - evt.GetMetadata().descriptor->name().c_str(), - evt.ShortDebugString().c_str()); + evt.GetMetadata().descriptor->name().c_str(), shortfmt(evt).c_str()); } template @@ -74,7 +83,7 @@ void unpack(absl::string_view buf) { err(1, "ParseFromString(): %.*s", static_cast(buf.size()), buf.data()); } log("%s => %s\n", evt.GetMetadata().descriptor->name().c_str(), - evt.ShortDebugString().c_str()); + shortfmt(evt).c_str()); } // List of dispatchers indexed based on MessageType enum values.