Spaces:
Sleeping
Sleeping
File size: 2,431 Bytes
0fa2038 f86ef86 0fa2038 42d4096 0fa2038 f86ef86 0fa2038 f86ef86 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | ---
title: Prompt Injection Shield
emoji: "🛡️"
colorFrom: green
colorTo: red
sdk: gradio
sdk_version: "5.23.0"
app_file: app.py
pinned: true
license: mit
short_description: Enterprise-grade prompt injection detection OWASP LLM01 2025
---
# 🛡️ Prompt Injection Shield
**Enterprise-grade LLM security middleware** — detecção de prompt injection em tempo real, baseado no OWASP LLM Top 10:2025.
## O que é?
Middleware de segurança que intercepta ataques de prompt injection antes que cheguem ao LLM. Sem dependências pesadas — funciona com regex + heurísticas semânticas em <5ms por request.
## Funcionalidades
| Aba | Descrição |
|-----|-----------|
| 🔬 Demo Interativo | Teste qualquer prompt e veja risk score + ameaças |
| 🔍 Pipeline Visual | Trace de cada camada de detecção passo a passo |
| 📚 OWASP LLM Top 10 | Todas as 10 vulnerabilidades com exemplos e mitigações |
| 🏆 Leaderboard | Ataques detectados pelos usuários em tempo real |
| 📡 API | Simulação de chamada REST + código de integração |
## Uso em produção
```python
from detector import PromptInjectionDetector, ThreatLevel
detector = PromptInjectionDetector()
result = detector.analyze(user_input, sensitivity="alta")
if result.threat_level == ThreatLevel.BLOCKED:
return {"error": "Blocked", "trace_id": result.trace_id}
# usar result.sanitized_text para chamar o LLM
```
## Arquitetura — 7 camadas
```
Request
│
▼
[1] Unicode normalizer — NFKC, BOM removal
│
▼
[2] Control char filter — \x00-\x1f, zero-width, RTL override
│
▼
[3] Size limiter — max chars, max lines, repetition collapse
│
▼
[4] Pattern matcher — 25+ regex patterns (OWASP LLM01)
│ │
│ BLOCKED → HTTP 403 + audit log
│
▼
[5] Semantic scorer — keyword density + linguistic heuristics
│
▼
[6] Risk aggregator — weighted score 0-100
│
▼
[7] Output filter — PII redaction, response sanitization
│
▼
LLM API (Groq / OpenAI / Anthropic)
```
## Stack
- Python 3.11 · zero ML dependencies
- Gradio 4.x
- OWASP LLM01:2025 compliance
- Kubernetes-ready (parte do projeto Agentic RAG K8s)
## Referências
- [OWASP LLM Top 10:2025](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
- [OWASP LLM01: Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) |