Skip to content

Commit

Permalink
fix(Backend): 🚑 fix secured print not using error, but reusing pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Aug 27, 2024
1 parent b8f88f4 commit 5eb50fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ codegen-backend = "cranelift"

[dependencies]
tikv-jemallocator = { workspace = true }
log = "0.4.18"
paste = "1.0.12"
toml = { workspace = true }
thiserror = "1.0.44"
Expand Down Expand Up @@ -42,6 +41,10 @@ lazy_static = "1.5.0"
prost-wkt-types = { workspace = true }
tracing-futures = "0.2.5"

[dependencies.log]
version = "0.4.18"
features = ["release_max_level_off"]

[dependencies.grpc]
path = "../grpc"
features = [
Expand Down Expand Up @@ -94,7 +97,7 @@ features = ["json"]

[dependencies.tracing]
workspace = true
features = ["async-await", "log", "release_max_level_debug"]
features = ["async-await", "log", "release_max_level_off"]

[dependencies.tokio]
workspace = true
Expand Down
8 changes: 4 additions & 4 deletions backend/src/macro_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ macro_rules! report_internal {
}};
}

/// Log error message to infarstructure and report a error id to frontend
/// Log error message to infrastructure and report an error id to frontend
///
/// It doesn't contain sensitive information either on infrastructure or frontend
#[macro_export]
Expand All @@ -33,14 +33,14 @@ macro_rules! report_internal {
tracing::$level!(uuid = uuid.to_string(), $pattern);
tonic::Status::unknown(msg.report())
}};
($level:ident,$pattern:expr) => {{
($level:ident,$error:expr) => {{
let (msg, uuid) = crate::util::error::Tracing::random();
tracing::$level!(uuid = uuid.to_string(), "{}", $pattern);
tracing::$level!(uuid = uuid.to_string(), "{}", $error);
tonic::Status::unknown(msg.report())
}};
($level:ident,$pattern:literal, $error:expr) => {{
let (msg, uuid) = crate::util::error::Tracing::random();
tracing::$level!(uuid = uuid.to_string(), "{}", $pattern);
tracing::$level!(uuid = uuid.to_string(), $pattern, $error);
tonic::Status::unknown(msg.report())
}};
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/util/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ impl From<Error> for Status {
///
/// useful to log the tracing information to client
/// without exposing the server's internal error
#[cfg(not(feature = "insecure-print"))]
pub struct Tracing {
trace_id: TraceId,
span_id: SpanId,
log_id: Uuid,
}

#[cfg(not(feature = "insecure-print"))]
impl Tracing {
pub fn random() -> (Self, Uuid) {
let log_id = Uuid::new_v4();
Expand Down

0 comments on commit 5eb50fa

Please sign in to comment.