Class RegexDetector

  • All Implemented Interfaces:
    InjectionDetector

    public final class RegexDetector
    extends Object
    implements InjectionDetector
    Layer-1 injection detector: deterministic, sub-millisecond regex matching.

    Detection pipeline

    1. Unicode normalization – collapses homoglyphs and strips invisible/zero-width characters (U+200B, U+FEFF, RTL overrides).
    2. Base64 decode-then-scan – detects obfuscated injection payloads embedded as Base64 strings.
    3. Pattern matching – applies a compiled set of case-insensitive patterns covering all categories from the architecture: override instructions, role-play bypass, prompt exfiltration, etc.

    Patterns are compiled once at construction time and are immutable, making this class fully thread-safe without synchronization.