Skip to content

feat(redteam): add Unicode normalization strategy - #10056

Open
3nesdeniz wants to merge 28 commits into
promptfoo:mainfrom
3nesdeniz:feat/unicode-normalization
Open

3nesdeniz wants to merge 28 commits into
promptfoo:mainfrom
3nesdeniz:feat/unicode-normalization

Conversation

@3nesdeniz

@3nesdeniz 3nesdeniz commented Jul 12, 2026 •

Copy link
Copy Markdown

Summary

  • add a unicode-normalization red-team strategy with NFC, NFD, NFKC, and NFKD support, defaulting to NFKD
  • expose the normalization form in the Web UI and preserve explicit form configuration when the strategy is composed in Layer
  • skip byte-identical standalone probes and non-string injected values instead of duplicating a baseline or coercing data
  • preserve unchanged inputs inside Layer so later transforms can still run; omit the final generated probe only when a Unicode-only pipeline remains unchanged
  • keep per-turn agentic Layer conversations moving when Unicode normalization is a no-op
  • validate Unicode forms at the top level and recursively inside nested Layer steps, returning HTTP 400 before provider work for invalid preview requests
  • return an explicit empty preview batch for Unicode-only no-ops while preserving existing fallback behavior for other strategies
  • keep the strategy explicit opt-in, including coding-agent canary exclusions, UI metadata, risk scoring, generated schema, and documentation

Design notes

Unicode normalization and homoglyph substitution remain separate strategies. Promptfoo already maintains the homoglyph strategy and substitution table, so users can compose the two with Layer when they need both behaviors.

The implementation uses the runtime's standards-compliant String.prototype.normalize() behavior and validates the requested form before generation. Changed probes retain assertions and existing metadata while recording the original text and applied normalization form. Assertions without a metric name remain unchanged.

No-op behavior is deliberate: standalone unchanged probes are filtered to avoid duplicate provider calls and false strategy attribution. Within a Layer pipeline, unchanged values continue to later transforms; a fully unchanged Unicode-only pipeline is reported as skipped. At runtime, unchanged per-turn prompts pass through so an agentic conversation is not interrupted.

The Web UI and backend share the same normalization-form constants and default. Existing configurations remain backward compatible because an omitted form still resolves to NFKD.

Validation

  • 339 focused backend strategy, route, schema, Layer, and reporting tests passed
  • 92 focused Web UI strategy-configuration and preview tests passed
  • full red-team regression suite passed: 141 files, 2,571 tests
  • root and Web UI TypeScript checks passed
  • Biome, git diff --check, architecture boundaries, and Knip passed
  • production package/Web UI build passed
  • Docusaurus production build passed

Fixes #10039

@3nesdeniz
3nesdeniz requested a review from ianw-oai as a code owner July 12, 2026 17:56
Copilot AI review requested due to automatic review settings July 12, 2026 17:56
@codecov

codecov Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (45f68f0) to head (ca792aa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10056      +/-   ##
==========================================
- Coverage   89.73%   89.73%   -0.01%     
==========================================
  Files        1051     1051              
  Lines       92740    92717      -23     
  Branches    32831    32820      -11     
==========================================
- Hits        83219    83195      -24     
- Misses       9521     9522       +1     
Flag Coverage Δ
site 53.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Redteam “unicode-normalization” strategy to generate probes that normalize the injected variable using Unicode NFC/NFD/NFKC/NFKD (defaulting to NFKD), helping surface defenses or pipelines that behave differently across equivalent Unicode representations.

Changes:

  • Introduces src/redteam/strategies/unicodeNormalization.ts with form validation, normalization, and test-case rewriting (including metadata about the change).
  • Registers the new strategy across strategy catalogs/metadata/risk scoring/framework mapping and the Web UI probe multiplier.
  • Adds targeted Vitest coverage and documentation for usage and composition with existing strategies.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/redteam/strategies/unicodeNormalization.test.ts New unit tests covering form validation, normalization behavior, and test-case transformation/metadata.
test/redteam/strategies/strategyId.test.ts Adds the new strategy ID → file mapping expectation.
test/redteam/strategies/index.test.ts Extends strategy validation tests to include valid/invalid unicode-normalization forms.
src/redteam/strategies/unicodeNormalization.ts Implements the strategy (form resolution, normalization wrapper, test-case rewrite + metadata).
src/redteam/strategies/index.ts Registers the strategy action and validates config form during validateStrategies.
src/redteam/riskScoring.ts Adds risk metadata for unicode-normalization.
src/redteam/constants/strategies.ts Adds unicode-normalization to strategy catalogs/encoding strategy set.
src/redteam/constants/plugins.ts Adds unicode-normalization to canary-breaking strategy exclusions.
src/redteam/constants/metadata.ts Adds display name + descriptions for the strategy in UI metadata.
src/redteam/constants/frameworks.ts Adds unicode-normalization to the OWASP LLM red team mapping.
src/app/src/pages/redteam/setup/components/strategies/utils.ts Adds probe multiplier entry for unicode-normalization in the setup UI.
site/static/config-schema.json Updates generated schema enum/documentation to include unicode-normalization.
site/docs/red-team/strategies/unicode-normalization.md New docs page describing semantics, configuration, and composition with homoglyph/layer.
site/docs/_shared/data/strategies.ts Adds the strategy to the docs strategy catalog data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@3nesdeniz
3nesdeniz force-pushed the feat/unicode-normalization branch from cfcc98a to 2183ebc Compare July 13, 2026 19:48
@3nesdeniz
3nesdeniz force-pushed the feat/unicode-normalization branch from 2183ebc to 2eaeb26 Compare July 14, 2026 22:41

@mldangelo-oai mldangelo-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Release audit on c895fdd: reviewed the Unicode-normalization strategy, schema/UI wiring, and affected tests; focused backend/UI suites pass (125 tests) and CI is green. No release-blocking findings.

…anged

The unicode-normalization strategy is a no-op on ASCII payloads, so an
all-ASCII batch emits probes that are byte-identical to the baseline. This
is documented and intentional, but it silently doubles scan cost and labels
duplicate probes as a "Unicode Normalization attack" in the report.

Emit a single logger.warn when every test case in a batch comes back
unchanged, naming the count and the normalization form. Purely additive:
the returned test cases, metadata, and metric names are unchanged.
…ation warning

The warning added in the previous commit broke two CI gates:

- test/test-hygiene.test.ts rejected the new logger mock: a module-scope
  persistent setter (`getLogLevel: vi.fn().mockReturnValue('info')`) must be
  paired with a reset in beforeEach to survive random test order. The test
  never reads getLogLevel, so drop the return value and reset logger.warn
  explicitly, per the mock-isolation rule in test/AGENTS.md.

- The `logger` import widened redteam -> legacy-runtime from 142 to 143,
  tripping the architecture baseline ratchet. Importing logger into a strategy
  is the established pattern (18 sibling strategies in src/redteam/strategies/
  already do it), so regenerate the baseline as the check instructs. The diff
  also locks in a pre-existing redteam -> node reduction (211 -> 210).
@mldangelo
mldangelo requested a review from a team as a code owner July 19, 2026 20:59
GitHub did not dispatch any workflow runs for 0b72726 (0 check runs, no
pending approval). All gates verified locally on that commit: test-hygiene
88 passed, architecture:check passed, redteam suite 140 files / 2557 tests
passed, biome clean.

@mldangelo mldangelo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this — a clean, well-integrated strategy addition.

Heads-up: I pushed three commits to your branch

So you aren't surprised by commits you didn't write, I pushed to feat/unicode-normalization:

  • d2ba7f4 — a logger.warn in addUnicodeNormalization when every case in a batch comes back normalizationChanged: false, plus 4 tests
  • 0b72726 — test hygiene + architecture/edge-baseline.json regen for the new logger import
  • 377c0a9 — empty commit to retrigger CI

Purely additive: same returned array, same metadata, same metric names. Your records when normalization leaves an ASCII-only prompt unchanged test still passes, and npx vitest run test/redteam is 140 files / 2557 tests green. Revert it freely if you'd rather solve the underlying issue differently.

What works well

  • The tests are load-bearing, not decorative. Replacing return text.normalize(form) with return text fails 7 tests across unicodeNormalization.test.ts and index.test.ts.
  • resolveUnicodeNormalizationForm throwing on an invalid form instead of silently defaulting is the right call.
  • Integration is genuinely complete — constants, registry, riskScoring metadata, canary exclusions, UI dialog, sidebar — and the docs page honestly calls out the homoglyph ordering interaction rather than glossing over it.

1. Is the ASCII no-op the behavior you want? (P2 — design question)

The docs say "ASCII-only prompts usually remain unchanged" and a test pins it, so I read this as deliberate. I mainly want to check you've seen the downstream cost. Measured through the real CLI (intent plugin, strategies: [basic, unicode-normalization]):

redteam generate -> Total tests: 6 | Plugin tests: 3
  basic -> 3 probes | unicode-normalization -> 3 probes
  uni[0..2] byte-identical to a basic probe: true (normalizationChanged: false)
eval --no-cache  -> 6 provider calls issued for 3 distinct probes

All four forms are exact identity on ASCII (5/5 realistic payloads x 4/4 forms). Two consequences worth your call:

  • getStrategyIdFromTest (src/app/src/pages/redteam/report/components/shared.ts:25) reads metadata.strategyId verbatim, so a plain baseline failure is reported as a successful "Unicode Normalization" attack that performed no transformation.
  • normalizationChanged has zero production consumers — nothing filters, warns, or annotates on it, and applyStrategies pushes every returned case with no dedupe.

Would you consider returning undefined for unchanged cases in unicodeNormalization.ts:51? applyStrategies already filters null/undefined, so it's framework-native. It does contradict your existing test, which is why I'm asking rather than pushing it.

2. src/redteam/constants/frameworks.ts:343 — OWASP preset addition (P2)

This takes owasp:llm:redteam:implementation from 11 to 12 strategies (+9.1%) for everyone already using that preset. 9 of its 10 plugins emit English ASCII prose; the tenth, ascii-smuggling, relies on tag-block / zero-width / variation-selector characters, all of which I verified survive NFKD unchanged. Deleting the line and running npx vitest run test/redteam gives 140 files / 2553 tests green — no test asserts the preset's contents, so this is completely unguarded either way. Worth dropping from this PR (users can still opt in explicitly), or landing it once #1 is settled. If it stays, an assertion on the preset list would be good.

3. site/docs/red-team/plugins/coding-agent.md:158 (P3 — quick fix)

You added unicode-normalization to CANARY_BREAKING_STRATEGY_IDS, but that line hardcodes the exclusion list as prose and now omits it. A user pairing coding-agent:* with this strategy will read that page, expect it to run, and have it silently dropped at src/redteam/plugins/index.ts:156.

Nits (take or leave)

  • src/redteam/strategies/types.ts:3 — the added export type { TestCase }; exists only so unicodeNormalization.ts:7 can import from ./types. Every sibling strategy (homoglyph.ts:1, rot13.ts:1, base64.ts:1, ~20 more) imports it from ../../types/index; matching them reverts types.ts to untouched.
  • unicodeNormalization.ts:9-14 — the re-exports of DEFAULT_UNICODE_NORMALIZATION_FORM / UNICODE_NORMALIZATION_FORMS / UnicodeNormalizationForm have no consumers outside the new test file (the UI imports them from @promptfoo/redteam/constants/strategies directly). AGENTS.md asks for direct imports over re-exports, and Knip may flag these.
  • The typeof x === 'string' && UNICODE_NORMALIZATION_FORMS.includes(...) predicate is duplicated in resolveUnicodeNormalizationForm and StrategyConfigDialog.tsx:56-59, costing three as UnicodeNormalizationForm casts. An isUnicodeNormalizationForm type guard beside the constants would narrow and delete all three — same pattern as isMultiTurnStrategy (constants/strategies.ts:32) and isFanoutStrategy (:194).

Nothing here blocks on my end once #1 and #2 have your answer.

mldangelo-oai and others added 3 commits July 19, 2026 15:57
Resolves a conflict in architecture/edge-baseline.json: main regenerated the
baseline while this branch had also regenerated it for the strategy's logger
import. Resolved by regenerating from the merged tree rather than taking either
side, so the file reflects the actual merged import graph.

Net delta versus main is the single expected edge:
  redteam -> legacy-runtime: 142 -> 143

`npm run architecture:check` passes. The PR was in a DIRTY merge state, which is
why GitHub stopped dispatching pull_request workflows for the last two commits.
@3nesdeniz 3nesdeniz changed the title feat(redteam): add Unicode normalization strategy feat(redteam): add unicode normalization strategy Jul 20, 2026
@3nesdeniz 3nesdeniz changed the title feat(redteam): add unicode normalization strategy feat(redteam): add Unicode normalization strategy Jul 20, 2026
Copilot AI review requested due to automatic review settings July 24, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 24, 2026 21:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@3nesdeniz

Copy link
Copy Markdown
Author

Thanks for the detailed review, @mldangelo, and for the commits you added to the branch.

I compared every item against the current implementation and synced the branch with the latest main:

  • d2ba7f4 and 0b72726 are your warning, test-hygiene, and architecture updates.
  • e19b93e filters byte-identical normalization results, removes unicode-normalization from the default OWASP implementation preset with explicit opt-in coverage, and updates the coding-agent exclusion documentation and tests.
  • 5b0f0c3 preserves the intended layer composition behavior and adds regression coverage for the no-op path.
  • e84149a is your follow-up documentation clarification for ASCII no-op behavior.
  • The unused strategy re-exports were removed, and the shared isUnicodeNormalizationForm guard now handles validation and narrowing.

I intentionally kept the local TestCase type re-export: importing it directly in this additional strategy module would widen the redteam -> legacy-contracts architecture edge, while the current boundary passes the repository architecture ratchet.

Fresh validation on current head 0a35e9d81:

  • focused backend: 294/294
  • focused UI: 92/92
  • integration: 64/64
  • build, TypeScript, generated-schema parity, architecture, changed-file lint, and Prettier: passed
  • branch: 0 commits behind current main at push time

All actionable review items appear addressed. When convenient, could you take another look at the updated head and let us know if anything remains?

@3nesdeniz

Copy link
Copy Markdown
Author

Hi @mldangelo — just following up when you have a chance. We addressed the review items on the current head 0a35e9d, and all checks are green. Is there anything else you would like changed before this is ready to merge? No rush, and thanks for taking another look.

Copilot AI review requested due to automatic review settings July 25, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 28, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@3nesdeniz

Copy link
Copy Markdown
Author

Hi @mldangelo — following up once more since the approval a couple of weeks back. Happy to rebase onto current main or adjust anything else if that would help get this over the line.

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 All Clear

Reviewed the Unicode Normalization strategy additions and related changes across strategy composition, validation, server routing, and UI. These updates focus on pre-LLM test-case transformation, validation, and user feedback. No new tool access, execution sinks, or LLM prompt flows were introduced by this PR.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

mldangelo and others added 4 commits September 18, 2026 00:49
# Conflicts:
#	architecture/edge-baseline.json
#	site/static/config-schema.json
#	src/redteam/riskScoring.ts
#	src/redteam/strategies/index.ts
#	src/types/api/redteam.ts

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 All Clear

Reviewed the PR adding the Unicode Normalization red-team strategy, related UI/config wiring, validation, and server handling for no-op cases. I traced inputs from the redteam generation API through strategy selection/execution and output reporting. No LLM security-relevant changes were found that introduce prompt injection risks, data exfiltration paths, insecure output handling, excessive agency, or jailbreak-only controls.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 All Clear

Reviewed the PR adding a Unicode Normalization red-team strategy, related UI, validation, and server handling. The changes focus on preprocessing test cases, configuration validation, and returning empty batches when normalization is a no-op. No direct LLM call sites or privileged tool integrations are modified in this diff, and no exploitable LLM security issues were identified.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 All Clear

Reviewed the Unicode Normalization strategy addition and related pipeline, validation, and server/UI handling. The changes add deterministic prompt transformations, strict config validation (including nested layers), and safer no-op handling without expanding agent capabilities. No LLM security vulnerabilities were identified in this PR.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

This branch has not been deployed

No deployments
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.

[Feature] Add Unicode normalization strategy for redteam prompt injection detection

4 participants