Harden Loguru markup handling in test clients#8078
Conversation
Preserve arbitrary backslashes when escaping Loguru markup and safely embed dynamic request and response fields before generated closing tags. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7e07da9f-f450-44f5-93be-ed970fff11f1
There was a problem hiding this comment.
Pull request overview
This PR hardens the Python test client logging path against Loguru markup parsing errors by escaping tag-like substrings and handling tricky backslash interactions, so dynamically generated request/response data can be safely embedded in colored log messages.
Changes:
- Update Loguru tag escaping to preserve arbitrary existing backslashes and prevent malformed markup sequences.
- Escape dynamic request/response text (paths, headers, redirect locations, bodies) before embedding in colored log lines.
- Add a focused Python unit test and register it with CTest to exercise
flush_info(..., colors=True).
Custom instructions used:
.github/copilot-instructions.md.github/instructions/reviewing.instructions.md
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/infra/clients.py |
Adds safer escaping helpers and applies them to dynamic text rendered inside Loguru colored messages. |
tests/infra/client_logging_test.py |
Adds a unit test reproducing Loguru markup parsing scenarios via flush_info(colors=True). |
CMakeLists.txt |
Registers the new Python unit test with CTest and sets PYTHONPATH for imports. |
Convert descriptions to strings before Loguru escaping and cover trailing backslashes without duplicating their rendered output. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7e07da9f-f450-44f5-93be-ed970fff11f1
|
Having thought about this, tried other things, contemplated the logs, the loading times in the UI etc I think I want to do #8079 rather than this. I leave it to @eddyashton to make a decision, but I think that we need to do one or the other (or possibly something else, but something!), the current implementation is not sound. |
Pull request was converted to draft
Summary
flush_info(colors=True)pathExamples of previously unsafe input
\<invalid><invalid>, so Loguru parsed the unknown tag and raisedValueError.Location/records/<invalid><invalid>instead of logging it literally.<red>spoofed</>trailing\</>closing tag; the response workaround avoided the parse issue by adding a visible trailing space.The hardened paths render each example literally, including the original number of backslashes.
Context
This is defense-in-depth logging hardening split out from #8077. It intentionally does not add COSE, CBOR, or other binary media-type classification or response-body suppression; that minimal COSE-specific behavior remains in #8077.
The broader markup issue was revealed while investigating the failed GitHub Actions job: https://github.com/microsoft/CCF/actions/runs/29526537129/job/87716300085
Testing
tests/infra/client_logging_test.pyCMakeLists.txt