Class RegexDetector
- java.lang.Object
-
- org.openidentityplatform.openig.ai.filter.RegexDetector
-
- All Implemented Interfaces:
InjectionDetector
public final class RegexDetector extends Object implements InjectionDetector
Layer-1 injection detector: deterministic, sub-millisecond regex matching.Detection pipeline
- Unicode normalization – collapses homoglyphs and strips invisible/zero-width characters (U+200B, U+FEFF, RTL overrides).
- Base64 decode-then-scan – detects obfuscated injection payloads embedded as Base64 strings.
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRegexDetector.PatternEntryRaw pattern entry before compilation (maps to injection-patterns.json).
-
Constructor Summary
Constructors Constructor Description RegexDetector(List<RegexDetector.PatternEntry> patterns)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DetectionResultscan(String prompt)Scanpromptfor injection signals.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openidentityplatform.openig.ai.filter.InjectionDetector
destroy
-
-
-
-
Constructor Detail
-
RegexDetector
public RegexDetector(List<RegexDetector.PatternEntry> patterns)
-
-
Method Detail
-
scan
public DetectionResult scan(String prompt)
Description copied from interface:InjectionDetectorScanpromptfor injection signals.- Specified by:
scanin interfaceInjectionDetector- Parameters:
prompt- the normalized prompt text extracted from the LLM request body- Returns:
- a
DetectionResult; nevernull
-
-