pub struct EncodingGuard { /* private fields */ }Expand description
Encoding guard to detect potentially malicious encodings.
When block_base64 is enabled and a decoded_content_matcher is provided,
the guard will decode base64 candidates and run the decoded text through
the matcher to detect threats hidden inside encoded payloads (F-002).
Security features:
- Detects both padded and unpadded base64 candidates
- Recursive decoding up to
max_decode_depthlayers to catch multi-encoded payloads - Configurable minimum candidate length (default: 8 chars)
- Supports both STANDARD and URL_SAFE base64 alphabets
Implementations§
Source§impl EncodingGuard
impl EncodingGuard
Sourcepub fn block_unicode_escapes(self, block: bool) -> Self
pub fn block_unicode_escapes(self, block: bool) -> Self
Set whether to block unicode escapes
Sourcepub fn block_base64(self, block: bool) -> Self
pub fn block_base64(self, block: bool) -> Self
Set whether to block base64
Sourcepub fn with_action(self, action: GuardAction) -> Self
pub fn with_action(self, action: GuardAction) -> Self
Set the action
Sourcepub fn with_decoded_content_matcher(self, matcher: PatternMatcher) -> Self
pub fn with_decoded_content_matcher(self, matcher: PatternMatcher) -> Self
Set a pattern matcher to run against decoded base64 content.
When base64-encoded text is detected and this matcher is set, the guard will decode the payload and check it for threats, catching attacks that hide prompt injections or jailbreaks inside base64 encoding.
Sourcepub fn with_max_decode_depth(self, depth: usize) -> Self
pub fn with_max_decode_depth(self, depth: usize) -> Self
Set the maximum recursive decode depth (default: 3).
Attackers may nest base64 encoding multiple times to evade detection. This controls how many layers of encoding the guard will unwrap.
Sourcepub fn with_min_candidate_len(self, len: usize) -> Self
pub fn with_min_candidate_len(self, len: usize) -> Self
Set the minimum candidate length in chars (default: 8).
Strings shorter than this are not considered base64 candidates. Lower values catch shorter payloads but may increase false positives.