Skip to content

Commit de776fc

Browse files
committed
fix: preserve cookie masking on malformed unicode
Signed-off-by: lucarlig <luca.carlig@ibm.com>
1 parent 4fa8c89 commit de776fc

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

tests/performance/test_request_logging_masking_sidecar_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def rust_headers(payload: Any) -> Any:
154154
[
155155
{"Authorization": "Bearer abc", "Cookie": "jwt_token=abc; theme=dark", "X-Trace-Id": "123"},
156156
{"X-Auth-Count": "5", "X-Api-Key": "secret"},
157+
{"Cookie": "jwt_token=\ud800; theme=dark"},
157158
],
158159
)
159160

tools_rust/request_logging_masking_sidecar/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "request_logging_masking_sidecar"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "Apache-2.0"
66

77
[lib]

tools_rust/request_logging_masking_sidecar/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ fn mask_sensitive_headers(py: Python<'_>, headers: &Bound<'_, PyAny>) -> PyResul
218218
}
219219

220220
if key_text.eq_ignore_ascii_case("cookie") && value.is_instance_of::<PyString>() {
221-
let cookie_value = value.cast::<PyString>()?.to_str()?;
222-
masked.set_item(key, mask_cookie_header(cookie_value))?;
221+
let cookie_value = value.cast::<PyString>()?.to_string_lossy();
222+
masked.set_item(key, mask_cookie_header(cookie_value.as_ref()))?;
223223
continue;
224224
}
225225

0 commit comments

Comments
 (0)