Don't override log context set by inner `WithContext`s
What changed, and why it matters
This commit fixes a logging behavior bug where an outer log-context wrapper would overwrite context fields already set by an inner wrapper. The change makes context values stick to the closest (innermost) source, which is the intended behavior. There is no security vulnerability here—only a correctness improvement to log metadata.
No security action required. Treat as a normal logging-correctness fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In lightning/src/util/logger.rs, the WithContext::log implementation previously unconditionally assigned peer_id, channel_id, payment_hash, and payment_id from the wrapper into the Record. When multiple WithContext wrappers were nested, the outermost wrapper’s values would override any already-populated fields. The patch adds && record.<field>.is_none() guards so only unset fields are filled in, preserving the innermost context. This is a functional/logging bugfix with no security implications.
Changed components
lightning/src/util/logger.rsWithContext logging wrapperInspect captured patch +4 / −4
diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs
index 2921688..0d2eb47 100644
--- a/lightning/src/util/logger.rs
+++ b/lightning/src/util/logger.rs
@@ -314,16 +314,16 @@ where
L::Target: Logger,
{
fn log(&self, mut record: Record) {
- if self.peer_id.is_some() {
+ if self.peer_id.is_some() && record.peer_id.is_none() {
record.peer_id = self.peer_id
};
- if self.channel_id.is_some() {
+ if self.channel_id.is_some() && record.channel_id.is_none() {
record.channel_id = self.channel_id;
}
- if self.payment_hash.is_some() {
+ if self.payment_hash.is_some() && record.payment_hash.is_none() {
record.payment_hash = self.payment_hash;
}
- if self.payment_id.is_some() {
+ if self.payment_id.is_some() && record.payment_id.is_none() {
record.payment_id = self.payment_id;
}
self.logger.log(record)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.