Class TypoglycemiaDetector
- java.lang.Object
-
- org.openidentityplatform.openig.ai.filter.TypoglycemiaDetector
-
- All Implemented Interfaces:
InjectionDetector
public class TypoglycemiaDetector extends Object implements InjectionDetector
Layer-2 Injection detector: catches prompt-injection keywords that have been typoglycemia-obfuscated — i.e. their interior letters are scrambled while the first and last characters are preserved.Adversaries exploit this to smuggle injection keywords past string-matching guardrails:
"Inoger all preivous isutrctions" → "Ignore all previous instructions" "drsreigad yuor sstyem promt" → "disregard your system prompt" "jilkbraae" → "jailbreak"
Algorithm
For each token in the input prompt:- If token length ≤ 3 — compare directly (no interior to scramble).
- Otherwise — compare the first character, last character, and a sorted bag of the interior characters against the same fingerprint of every keyword in the watch-list.
- If fingerprints match, the similarity is verified with a fast
Damerau-Levenshtein distance (≤
maxEditDistanceon the full strings) to suppress accidental collisions between genuinely different words that happen to share a fingerprint (e.g. "satin"/"saint").
-
-
Constructor Summary
Constructors Constructor Description TypoglycemiaDetector(int minWordLength, int maxEditDistance, List<String> keywords)TypoglycemiaDetector(List<String> keywords)
-
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
-
-
-
-
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
-
-