FEAT: Add BidiConverter for Arabic adversarial Unicode manipulation#1832
Merged
romanlutz merged 5 commits intoJun 1, 2026
Merged
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
…-converter' into raulster24/add-bidi-converter
romanlutz
approved these changes
Jun 1, 2026
This was referenced Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
BidiConverter, a deterministicPromptConverterthat wraps text in a matched pair of Unicode bidirectional control characters so the logical (stored) code point order can differ from the order a reader sees rendered. This is the manipulation family behind the "Trojan Source" findings (CVE-2021-42574).Three schemes are supported, per the Unicode Bidirectional Algorithm (UAX #9):
override(default): RLO U+202E ... PDF U+202Cembedding: RLE U+202B ... PDF U+202Cisolate: RLI U+2067 ... PDI U+2069The transformation is pure deterministic code point insertion (no LLM, no randomness), which makes it reproducible and distinct from the LLM-based converters. It is useful for probing bidirectional-rendering and tokenizer handling, and is particularly relevant when red-teaming right-to-left script (e.g. Arabic) models.
cc @romanlutz
Tests and Documentation
tests/unit/prompt_converter/test_bidi_converter.py: covers all three schemes (exact output), empty input, determinism, invalid-scheme rejection, and unsupported-input-type rejection. All pass:uv run pytest tests/unit/prompt_converter/test_bidi_converter.pypyrit/prompt_converter/__init__.py(import +__all__).doc/code/converters/1_text_to_text_converters.py(Obfuscation Converters section) and regenerated the paired.ipynbplus the converter modality table in0_converters.ipynbusing JupyText (uv run jupytext --sync).references.bibentry for the Trojan Source citation.ruffandtyare clean.