Skip to content

FEAT: Add BidiConverter for Arabic adversarial Unicode manipulation#1832

Merged
romanlutz merged 5 commits into
microsoft:mainfrom
Raulster24:raulster24/add-bidi-converter
Jun 1, 2026
Merged

FEAT: Add BidiConverter for Arabic adversarial Unicode manipulation#1832
romanlutz merged 5 commits into
microsoft:mainfrom
Raulster24:raulster24/add-bidi-converter

Conversation

@Raulster24
Copy link
Copy Markdown
Contributor

Description

Adds BidiConverter, a deterministic PromptConverter that 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+202C
  • embedding: RLE U+202B ... PDF U+202C
  • isolate: RLI U+2067 ... PDI U+2069

The 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

  • Added 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.py
  • Registered the converter in pyrit/prompt_converter/__init__.py (import + __all__).
  • Added a usage example to doc/code/converters/1_text_to_text_converters.py (Obfuscation Converters section) and regenerated the paired .ipynb plus the converter modality table in 0_converters.ipynb using JupyText (uv run jupytext --sync).
  • Added a references.bib entry for the Trojan Source citation.
  • The converter-documentation conformance test passes, and ruff and ty are clean.

@Raulster24
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@romanlutz romanlutz added this pull request to the merge queue Jun 1, 2026
Merged via the queue into microsoft:main with commit 3253c1e Jun 1, 2026
48 checks passed
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