only valid utf8 in logs

This commit is contained in:
Christien Rioux 2025-06-14 14:00:14 -04:00
parent 11c675e019
commit a04c71c3de
2 changed files with 11 additions and 2 deletions

View file

@ -12,6 +12,7 @@
- Fix crash when peer info has missing or unsupported node ids
- Add 'auto' mode for detect_address_changes
- Improved `TypedXXX` conversion traits, including to and from `Vec<u8>`
- Ensure utf8 replacement characters are never emitted in logs
- veilid-server:
- Use `detect_address_changes: auto` by default

View file

@ -134,11 +134,19 @@ impl ApiTracingLayer {
.unwrap_or_default(),
};
let message = format!("{} {}", origin, message).trim().to_owned();
// Dart can't handle the Unicode Replacement Character
// and it causes crashes on multiple Flutter applications
// see: https://gitlab.com/veilid/veilid/-/issues/473
// We sanitize the logs here because it is generally a good idea to
// ensure only valid UTF8 strings are returned to applications
let message = format!("{} {}", origin, message)
.trim()
.replace(char::REPLACEMENT_CHARACTER, "");
let backtrace = if log_level <= VeilidLogLevel::Error {
let bt = backtrace::Backtrace::new();
Some(format!("{:?}", bt))
Some(format!("{:?}", bt).replace(char::REPLACEMENT_CHARACTER, ""))
} else {
None
};