Skip to content

fix: escape bidirectional control characters in log fields - #392

Open
UlisesGascon wants to merge 2 commits into
masterfrom
escape-bidi-control-chars
Open

UlisesGascon wants to merge 2 commits into
masterfrom
escape-bidi-control-chars

Conversation

@UlisesGascon

Copy link
Copy Markdown
Member

escapeLogField already neutralizes C0/C1 control characters and the U+2028 / U+2029 line separators so a logged field stays on a single line. The Unicode bidirectional format controls (U+061C, U+200E/200F, U+202A-202E, U+2066-2069) aren't covered, yet they can reorder how a log line renders in a terminal or editor, making the recorded value misleading. This extends the same character class to escape them as \uXXXX, consistent with the existing controls, and adds a regression test (delivered via the :remote-user token, matching the existing escaping tests).

escapeLogField already escapes C0/C1 controls and the U+2028/U+2029 line
separators; extend the same handling to the Unicode bidirectional format
controls (U+061C, U+200E/200F, U+202A-202E, U+2066-2069) so a field cannot
reorder how a log line renders. Emitted as \uXXXX like the other controls.
@UlisesGascon
UlisesGascon marked this pull request as ready for review October 15, 2026 14:00
@UlisesGascon UlisesGascon self-assigned this Oct 15, 2026

@krzysdz krzysdz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it in June, but realistically there are many other characters that can mess up how things are seen by people (homoglyphs, modifiers, symmetric swapping (U+206B)1). Fortunately, these should not be mistaken for something else by software (like e.g. NEL/LS/PS being treated as newline by Python's str.splitlines()) and some text editors mark them to prevent improper interpretation by people.

I think that it may help in some situations, but fooling people into misinterpreting text will still be possible.

Footnotes

  1. This causes e.g. ( to be displayed as ) or could be used to swap [ and ] that the date is wrapped in, and generally applies to pairs of Bidi Mirrored characters. ↩

Comment thread index.js Outdated
Co-authored-by: krzysdz <12915102+krzysdz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants