Skip to content

Commit 9bd2d15

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

2 files changed

Lines changed: 3 additions & 2 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/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)