diff --git a/doc/scanner/garak.ipynb b/doc/scanner/garak.ipynb index 4b3f1143a4..a05b5efdd8 100644 --- a/doc/scanner/garak.ipynb +++ b/doc/scanner/garak.ipynb @@ -303,9 +303,9 @@ "pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1\n", "```\n", "\n", - "**Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n", + "**Available techniques** (21 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n", "QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak,\n", - "AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi\n", + "AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi, Disemvowel\n", "\n", "**Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset\n", "spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic\n", diff --git a/doc/scanner/garak.py b/doc/scanner/garak.py index 33b72d4a44..2f4af66015 100644 --- a/doc/scanner/garak.py +++ b/doc/scanner/garak.py @@ -136,9 +136,9 @@ # pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1 # ``` # -# **Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex, +# **Available techniques** (21 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex, # QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak, -# AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi +# AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi, Disemvowel # # **Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset # spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic diff --git a/pyrit/scenario/scenarios/garak/encoding.py b/pyrit/scenario/scenarios/garak/encoding.py index 3d07dd9d46..4544ccfa19 100644 --- a/pyrit/scenario/scenarios/garak/encoding.py +++ b/pyrit/scenario/scenarios/garak/encoding.py @@ -130,6 +130,7 @@ class EncodingTechnique(ScenarioTechnique): AsciiSmuggler = ("ascii_smuggler", set[str]()) Bifid = ("bifid", set[str]()) ColumnarTransposition = ("columnar_transposition", set[str]()) + Disemvowel = ("disemvowel", set[str]()) UbbiDubbi = ("ubbi_dubbi", set[str]()) @classmethod @@ -319,6 +320,9 @@ def _converter_variants() -> list[tuple[list[Converter], str, str]]: ([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"), ([BifidConverter()], "bifid", "bifid"), ([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"), + # "disemvowel": remove all vowels ("disemvoweling"), a comment-moderation technique + # popularized on the Making Light blog (https://nielsenhayden.com/makinglight/). + ([SearchReplaceConverter(pattern="[AEIOUaeiou]", replace="")], "disemvowel", "disemvowel"), # "ubbi_dubbi": a language game that prefixes each vowel run with "ub", popularized by # the PBS children's show Zoom (1972). https://en.wikipedia.org/wiki/Ubbi_dubbi ([SearchReplaceConverter(pattern=r"([aeiouAEIOU]+)", replace=r"ub\1")], "ubbi_dubbi", "ubbi_dubbi"), diff --git a/tests/unit/scenario/garak/test_encoding.py b/tests/unit/scenario/garak/test_encoding.py index da4c169488..80aa4a5129 100644 --- a/tests/unit/scenario/garak/test_encoding.py +++ b/tests/unit/scenario/garak/test_encoding.py @@ -258,13 +258,14 @@ def test_default_aggregate_curates_representative_subset(self): } all_names = {t.value for t in EncodingTechnique.get_all_techniques()} assert default_names < all_names - assert len(all_names) == 20 + assert len(all_names) == 21 # The niche/lossy schemes stay ALL-only. assert all_names - default_names == { "braille", "ecoji", "zalgo", "ascii_smuggler", + "disemvowel", "ubbi_dubbi", "bifid", "columnar_transposition", @@ -350,6 +351,55 @@ async def test_base64_trimmed_to_two_variants( # The trimmed variants must not appear. assert not any("standard" in n or "b2a" in n for n in names) + async def test_disemvowel_technique_builds_registered_row( + self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups, mock_dataset_config + ): + """Selecting Disemvowel must register a row whose converter strips vowels. + + This exercises the registered ``disemvowel`` row end to end (not a hand-built converter), so a + deleted or misnamed row in ``_converter_variants()`` is caught: such a regression leaves the + enum intact while the technique builds no attacks. + """ + from unittest.mock import patch + + with patch.object( + Encoding, + "_resolve_seed_groups_by_dataset_async", + new_callable=AsyncMock, + return_value={"memory": mock_attack_seed_groups}, + ): + scenario = Encoding(objective_scorer=mock_objective_scorer) + scenario.set_params_from_args( + args={ + "objective_target": mock_objective_target, + "dataset_config": mock_dataset_config, + "scenario_techniques": [EncodingTechnique.Disemvowel], + } + ) + await scenario.initialize_async() + + attacks = scenario._get_converter_attacks( + context=scenario._build_scenario_context(seed_groups_by_dataset={"memory": mock_attack_seed_groups}) + ) + + assert attacks, "disemvowel technique built no attacks" + assert all(aa.display_group == "disemvowel" for aa in attacks) + names = {aa.atomic_attack_name for aa in attacks} + assert "disemvowel_raw" in names, "missing raw variant" + assert any(n != "disemvowel_raw" for n in names), "missing decode variant" + + # The registered row's converter actually strips vowels. + raw = next(aa for aa in attacks if aa.atomic_attack_name == "disemvowel_raw") + row_converters = [ + conv + for config in raw.attack_technique.attack.get_request_converters() + for conv in config.converters + if isinstance(conv, SearchReplaceConverter) + ] + assert row_converters, "disemvowel row applies no SearchReplaceConverter" + result = await row_converters[0].convert_async(prompt="Hello World") + assert result.output_text == "Hll Wrld" + async def test_ubbi_dubbi_technique_builds_registered_row( self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups, mock_dataset_config ):