diff --git a/guards/rust-guards/prompt-injection-guard-wasm/src/patterns.rs b/guards/rust-guards/prompt-injection-guard-wasm/src/patterns.rs index 6e5ab57..a6bb702 100644 --- a/guards/rust-guards/prompt-injection-guard-wasm/src/patterns.rs +++ b/guards/rust-guards/prompt-injection-guard-wasm/src/patterns.rs @@ -1,358 +1,221 @@ -//! Pattern categories for prompt injection detection. -//! -//! Uses keyword-sequence matching: each pattern is a sequence of term groups. -//! All groups must match in order in normalized text. -//! Within each group, any alternative keyword matches. - -/// A keyword-sequence detection pattern. -/// Each element is a group of alternative search terms. -/// All groups must match in order in the normalized text. -pub struct DetectionPattern { - pub terms: &'static [&'static [&'static str]], -} +# Remediation Plan: -/// A single pattern category with its detection patterns and risk weight. -pub struct PatternCategory { - pub name: &'static str, - pub weight: u32, - pub patterns: &'static [DetectionPattern], -} +**Severity:** medium +**Category:** threat-model +**Estimated Effort:** 6-8 hours -/// Match result from scanning text against patterns. -#[derive(Clone)] -pub struct PatternMatch { - pub category: String, - pub matched_text: String, - pub weight: u32, -} +## Summary +Implement comprehensive threat modeling for prompt injection guard patterns to identify security gaps and enhance protection mechanisms -/// All built-in pattern categories. -pub static CATEGORIES: &[PatternCategory] = &[ - PatternCategory { - name: "prompt_override", - weight: 8, - patterns: &[ - // ignore (all)? previous instructions/commands/prompts - DetectionPattern { terms: &[&["ignore"], &["previous"], &["instruction", "command", "prompt"]] }, - // disregard (all)? previous/prior/earlier instructions/commands - DetectionPattern { terms: &[&["disregard"], &["previous", "prior", "earlier"], &["instruction", "command"]] }, - // forget (all)? previous/prior/earlier instructions/commands - DetectionPattern { terms: &[&["forget"], &["previous", "prior", "earlier"], &["instruction", "command"]] }, - // override (all)? previous/prior/current instructions/commands - DetectionPattern { terms: &[&["override"], &["previous", "prior", "current"], &["instruction", "command"]] }, - // new instructions: ignore - DetectionPattern { terms: &[&["new instruction"], &["ignore"]] }, - // do not follow previous/prior/earlier instructions/rules - DetectionPattern { terms: &[&["do not follow"], &["previous", "prior", "earlier"], &["instruction", "rule"]] }, - ], - }, - PatternCategory { - name: "role_manipulation", - weight: 7, - patterns: &[ - // you are now (a)? admin/root/system/jailbroken/unrestricted - DetectionPattern { terms: &[&["you are now"], &["admin", "root", "system", "jailbroken", "unrestricted"]] }, - // act as (if you are)? admin/root/system/unrestricted - DetectionPattern { terms: &[&["act as"], &["admin", "root", "system", "unrestricted"]] }, - // pretend (you are|to be) admin/root/system/unrestricted - DetectionPattern { terms: &[&["pretend"], &["admin", "root", "system", "unrestricted"]] }, - // switch to admin/root/system/developer/debug mode - DetectionPattern { terms: &[&["switch to"], &["admin", "root", "system", "developer", "debug"], &["mode"]] }, - // enter admin/root/system/developer/debug mode - DetectionPattern { terms: &[&["enter"], &["admin", "root", "system", "developer", "debug"], &["mode"]] }, - // you have no restrictions/limitations/rules/constraints - DetectionPattern { terms: &[&["you have no"], &["restriction", "limitation", "rule", "constraint"]] }, - ], - }, - PatternCategory { - name: "system_override", - weight: 9, - patterns: &[ - // SYSTEM: override/execute/run/bypass - DetectionPattern { terms: &[&["system:"], &["override", "execute", "run", "bypass"]] }, - // ADMIN: override/execute/run/bypass - DetectionPattern { terms: &[&["admin:"], &["override", "execute", "run", "bypass"]] }, - // ROOT: execute/run - DetectionPattern { terms: &[&["root:"], &["execute", "run"]] }, - // execute as root/admin/system/superuser - DetectionPattern { terms: &[&["execute as"], &["root", "admin", "system", "superuser"]] }, - // [SYSTEM OVERRIDE] - DetectionPattern { terms: &[&["[system override]"]] }, - // [ADMIN OVERRIDE] - DetectionPattern { terms: &[&["[admin override]"]] }, - ], - }, - PatternCategory { - name: "safety_bypass", - weight: 8, - patterns: &[ - // disregard (all)? safety/security/restrictions/guardrails - DetectionPattern { terms: &[&["disregard"], &["safety", "security", "restriction", "guardrail"]] }, - // bypass (all)? safety/security/restrictions/guardrails/filters - DetectionPattern { terms: &[&["bypass"], &["safety", "security", "restriction", "guardrail", "filter"]] }, - // ignore (all)? safety/security/restrictions/guardrails - DetectionPattern { terms: &[&["ignore"], &["safety", "security", "restriction", "guardrail"]] }, - // disable (all)? safety/security/guardrails/filters/protections - DetectionPattern { terms: &[&["disable"], &["safety", "security", "guardrail", "filter", "protection"]] }, - // turn off (all)? safety/security/guardrails/filters - DetectionPattern { terms: &[&["turn off"], &["safety", "security", "guardrail", "filter"]] }, - // remove (all)? restrictions/limitations/filters/constraints - DetectionPattern { terms: &[&["remove"], &["restriction", "limitation", "filter", "constraint"]] }, - ], - }, - PatternCategory { - name: "hidden_instructions", - weight: 6, - patterns: &[ - DetectionPattern { terms: &[&["[hidden]"]] }, - DetectionPattern { terms: &[&["[secret]"]] }, - DetectionPattern { terms: &[&["[invisible]"]] }, - // HTML comment injection: