Back to skills
SKILL.md
061 Architecture 58224601
CSecurity> Internal architecture documentation for contributors and maintainers. ---
- 9 stars
- 0 votes
- 0 copies
- 1 view
- Added May 31, 2026
Works with
Security analysis
60/100- Performs destructive filesystem operations
- Impersonates system messages to override safety constraints
Pro scans all 2 files and shows the line behind each finding
npx -y skills add tools-only/X-Skills --skill 061-architecture_58224601 --agent claude-codeAre you the author of 061 Architecture 58224601?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tools-only-061-architecture-58224601)# ποΈ Prompt Guard Architecture
> Internal architecture documentation for contributors and maintainers.
---
## Overview
Prompt Guardλ **λ€μΈ΅ λ°©μ΄(Defense in Depth)** μμΉμΌλ‘ μ€κ³λ¨. λ¨μΌ ν¨ν΄μ΄ μλ μ¬λ¬ λ μ΄μ΄μ κ²μ¬λ₯Ό ν΅ν΄ false positiveλ₯Ό μ€μ΄λ©΄μ 곡격μ ν¨κ³Όμ μΌλ‘ νμ§.
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INPUT MESSAGE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 1: Rate Limiting β
β β’ Per-user request tracking β
β β’ Sliding window algorithm β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 2: Text Normalization β
β β’ Homoglyph detection & replacement β
β β’ Zero-width character removal β
β β’ Unicode normalization β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 3: Pattern Matching Engine β
β β’ Critical patterns (immediate block) β
β β’ Secret/Token requests β
β β’ Multi-language injection patterns β
β β’ Scenario jailbreaks β
β β’ Social engineering β
β β’ Indirect injection β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 4: Encoding Detection β
β β’ Base64 suspicious content β
β β’ URL encoding tricks β
β β’ HTML entity abuse β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 5: Behavioral Analysis β
β β’ Repetition detection (token overflow) β
β β’ Context hijacking patterns β
β β’ Multi-turn manipulation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 6: Context-Aware Decision β
β β’ Sensitivity adjustment β
β β’ Owner bypass rules β
β β’ Group context restrictions β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DetectionResult β
β β’ severity: SAFE β LOW β MEDIUM β HIGH β CRITICAL β
β β’ action: ALLOW | LOG | WARN | BLOCK | BLOCK_NOTIFY β
β β’ reasons: [matched pattern categories] β
β β’ recommendations: [human-readable suggestions] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## Core Components
### 1. Severity Levels
| Level | Value | Description | Typical Trigger |
|-------|-------|-------------|-----------------|
| SAFE | 0 | No threat detected | Normal conversation |
| LOW | 1 | Minor suspicious signal | Output manipulation |
| MEDIUM | 2 | Clear manipulation attempt | Role manipulation, urgency |
| HIGH | 3 | Dangerous command | Jailbreaks, system access |
| CRITICAL | 4 | Immediate threat | Secret exfil, code execution |
### 2. Action Types
| Action | Description | When Used |
|--------|-------------|-----------|
| `allow` | No intervention | SAFE severity |
| `log` | Record only | Owner requests, LOW severity |
| `warn` | Notify user | MEDIUM severity |
| `block` | Refuse request | HIGH severity |
| `block_notify` | Block + alert owner | CRITICAL severity |
### 3. Pattern Categories
#### π΄ Critical (Immediate Block)
- `CRITICAL_PATTERNS` - rm -rf, fork bombs, SQL injection, XSS
- `SECRET_PATTERNS` - API key/token/password requests
#### π v2.6.0 Social Engineering Defense
- `APPROVAL_EXPANSION` - "μκΉ νλ½νμμ" scope creep
- `CREDENTIAL_PATH_PATTERNS` - credentials.json, .env κ²½λ‘
- `BYPASS_COACHING` - "μλλκ² λ§λ€μ΄" bypass help
- `DM_SOCIAL_ENGINEERING` - DM μ‘°μ ν¨ν΄
#### π‘ v2.5.x Advanced Patterns
- `INDIRECT_INJECTION` - URL/file/image-based injection
- `CONTEXT_HIJACKING` - Fake memory/history manipulation
- `MULTI_TURN_MANIPULATION` - Gradual trust building
- `TOKEN_SMUGGLING` - Invisible Unicode characters
- `SYSTEM_PROMPT_MIMICRY` - `<claude_*>`, `[INST]` λ±
#### π’ v2.4.0 Red Team Patterns
- `SCENARIO_JAILBREAK` - Dream/story/cinema/academic
- `EMOTIONAL_MANIPULATION` - Moral dilemmas, threats
- `AUTHORITY_RECON` - Fake admin, capability probing
- `COGNITIVE_MANIPULATION` - Hypnosis/trance patterns
- `PHISHING_SOCIAL_ENG` - Password reset templates
#### π΅ Language-Specific
- `PATTERNS_EN` - English patterns
- `PATTERNS_KO` - νκ΅μ΄ ν¨ν΄
- `PATTERNS_JA` - ζ₯ζ¬θͺγγΏγΌγ³
- `PATTERNS_ZH` - δΈζ樑εΌ
---
## Detection Flow
```python
def analyze(message, context):
# 1. Rate limit check
if check_rate_limit(user_id):
return BLOCK
# 2. Text normalization
normalized, has_homoglyphs = normalize(message)
# 3. Critical patterns (highest priority)
for pattern in CRITICAL_PATTERNS:
if match(pattern, normalized):
return CRITICAL
# 4. Secret request patterns
for lang, patterns in SECRET_PATTERNS:
for pattern in patterns:
if match(pattern, text):
return CRITICAL
# 5. Versioned pattern sets (newest first)
pattern_sets = [
(v2.6.0_patterns, severity), # Social engineering
(v2.5.2_patterns, severity), # Moltbook attacks
(v2.5.0_patterns, severity), # Indirect injection
(v2.4.0_patterns, severity), # Red team patterns
]
# 6. Language-specific patterns
for lang in [EN, KO, JA, ZH]:
check_language_patterns(lang)
# 7. Base64 detection
suspicious = detect_base64(message)
# 8. Behavioral analysis
check_repetition()
check_invisible_chars()
# 9. Context-aware adjustment
adjust_for_sensitivity()
apply_owner_rules()
apply_group_restrictions()
return DetectionResult(...)
```
---
## File Structure
```
prompt-guard/
βββ README.md # User documentation
βββ ARCHITECTURE.md # This file
βββ SKILL.md # Clawdbot skill interface
βββ config.example.yaml # Configuration template
βββ scripts/
βββ detect.py # Core detection engine (~1400 lines)
β βββ Severity # Enum for severity levels
β βββ Action # Enum for action types
β βββ DetectionResult# Result dataclass
β βββ PromptGuard # Main detection class
β βββ Pattern defs # 349+ regex patterns
β
βββ analyze_log.py # Security log analyzer
β βββ LogAnalyzer # Parse and aggregate logs
β
βββ audit.py # System security audit
βββ SecurityAudit # Check permissions, configs
```
---
## Pattern Organization
### Naming Convention
```
{CATEGORY}_{VERSION?} = [
r"pattern1",
r"pattern2",
]
```
### Version Tagging in Matches
ν¨ν΄ λ§€μΉ μ λ²μ νκ·Έ μΆκ°:
- `new:{category}:{pattern}` - v2.4.0 red team
- `v25:{category}:{pattern}` - v2.5.0 indirect
- `v252:{category}:{pattern}` - v2.5.2 moltbook
- `{lang}:{category}:{pattern}` - language-specific
---
## Configuration Schema
```yaml
prompt_guard:
# Detection sensitivity
sensitivity: medium # low | medium | high | paranoid
# Owner IDs (bypass most restrictions)
owner_ids:
- "USER_ID"
# Action per severity
actions:
LOW: log
MEDIUM: warn
HIGH: block
CRITICAL: block_notify
# Rate limiting
rate_limit:
enabled: true
max_requests: 30
window_seconds: 60
# Logging
logging:
enabled: true
path: memory/security-log.md
```
---
## Key Design Decisions
### 1. Regex over ML
- **Pros**: Deterministic, explainable, no model dependencies
- **Cons**: Manual pattern updates needed
- **Reasoning**: Security requires predictability; ML false negatives unacceptable
### 2. Multi-Language First
- All patterns have EN/KO/JA/ZH variants
- Attack language != user language (multilingual attacks common)
### 3. Severity Graduation
- Not binary block/allow
- Owner context matters (more lenient for owners)
- Group context matters (stricter in groups)
### 4. Versioned Patterns
- Clear provenance for each pattern set
- Credits to contributors (νλ―Όν, Moltbook, etc.)
- Easy to audit and roll back
---
## Extension Points
### Adding New Patterns
```python
# 1. Define pattern list
NEW_ATTACK_CATEGORY = [
r"pattern1",
r"pattern2",
]
# 2. Add to analysis loop
new_pattern_sets = [
...
(NEW_ATTACK_CATEGORY, "new_category", Severity.HIGH),
]
```
### Adding New Languages
```python
PATTERNS_XX = {
"instruction_override": [...],
"role_manipulation": [...],
...
}
# Add to all_patterns
all_patterns.append((PATTERNS_XX, "xx"))
```
---
## Performance Notes
- **Regex compilation**: Patterns are compiled on first use (Python caches)
- **Early exit**: CRITICAL patterns checked first
- **Fingerprinting**: Hash-based dedup for repeated attacks
- **Rate limiting**: O(1) sliding window
---
## Security Considerations
### What We DON'T Do
- β Execute user input
- β Log sensitive data in plaintext
- β Trust any "admin" claims without owner_id verification
### What We DO
- β
Fail closed (block on uncertainty)
- β
Log all suspicious activity
- β
Stricter rules in group contexts
---
## Changelog Location
λ²μ λ³ λ³κ²½μ¬νμ `detect.py` μλ¨ docstringμ κΈ°λ‘:
```python
"""
Prompt Guard v2.6.0 - Advanced Prompt Injection Detection
Changelog v2.6.0 (2026-02-01):
- Added Single Approval Expansion detection
- Added Credential Path Harvesting detection
...
"""
```
---
## Credits
- **Core**: @simonkim_nft (κΉμμ€)
- **v2.4.0 Red Team**: νλ―Όν (@kanfrancisco)
- **v2.4.1 Config Fix**: Junho Yeo (@junhoyeo)
- **v2.5.2 Moltbook Patterns**: Community reports
---
*Last updated: 2026-02-01 | v2.6.0*
Files in this skill
- README.md
- skill.md
Attribution
Comments
Loading commentsβ¦