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