Version: 1.0
Datum: 7. Januar 2026
Zielgruppe: Entwickler & DevOps
⚠️ WICHTIGER HINWEIS ZUM PRODUKTIONSEINSATZDie LoRa-Signaturvalidierung ist derzeit als Prototyp/Konzept implementiert und verwendet Stub-Code. NICHT für Produktionsumgebungen geeignet ohne:
- Vollständige OpenSSL X.509 Signaturverifikation
- LoRa-Dateiformat-Parsing
- Security-Audit
Die Prompt Injection Detection und Embedding Anomaly Detection sind produktionsreif und können sofort eingesetzt werden.
#include "llm/lora_security_validator.h"
#include "llm/multi_lora_manager.h"
using namespace themis::llm;
// Configure security
LoRASecurityConfig security_config;
security_config.require_signature = true;
security_config.verify_checksum = true;
security_config.detect_weight_anomalies = true;
// Add trusted signers
security_config.trusted_signers = {
"a1b2c3d4...", // SHA-256 fingerprint of trusted cert
"e5f6g7h8..."
};
// Create validator
LoRASecurityValidator validator(security_config);
// Validate adapter before loading
auto sig_result = validator.verifyEmbeddedSignature("legal-qa.lora");
if (!sig_result.is_valid) {
LOG_ERROR("LoRa signature invalid: {}", sig_result.error_message);
return false;
}
auto integrity_result = validator.checkIntegrity("legal-qa.lora");
if (!integrity_result.is_intact) {
LOG_ERROR("LoRa integrity check failed");
return false;
}
// Safe to load
MultiLoRAManager lora_manager(config);
lora_manager.loadLoRA("legal-qa", "legal-qa.lora", "mistral-7b");#include "llm/lora_security_validator.h"
// Configure detector
PromptInjectionDetector::Config detector_config;
detector_config.enabled = true;
detector_config.risk_threshold = 0.7f;
detector_config.block_high_risk = true;
PromptInjectionDetector detector(detector_config);
// Check user input
std::string user_prompt = get_user_input();
if (detector.isSuspicious(user_prompt)) {
LOG_WARN("Suspicious prompt detected");
// Option 1: Block
return error_response("Prompt appears malicious");
// Option 2: Sanitize
user_prompt = detector.sanitizePrompt(user_prompt);
}
// Safe to process
process_llm_request(user_prompt);#include "llm/lora_security_validator.h"
// Configure detector
EmbeddingAnomalyDetector::Config anomaly_config;
anomaly_config.enabled = true;
anomaly_config.outlier_threshold = 3.0f;
anomaly_config.min_samples = 100;
EmbeddingAnomalyDetector anomaly_detector(anomaly_config);
// Build baseline with normal embeddings
for (const auto& doc : corpus) {
auto embedding = generate_embedding(doc);
anomaly_detector.updateBaseline(embedding);
}
// Check new embedding
auto new_embedding = generate_embedding(new_document);
float anomaly_score = anomaly_detector.getAnomalyScore(new_embedding);
if (anomaly_score > 0.8f) {
LOG_WARN("Anomalous embedding detected: score={}", anomaly_score);
// Reject or quarantine
}- Signaturvalidierung aktiviert (
require_signature = true) - Trusted Signers konfiguriert (mindestens 1 Zertifikat)
- Checksummen-Verifikation (
verify_checksum = true) - Anomalie-Detection für Weights (
detect_weight_anomalies = true) - Metadata-Validierung (base_model, rank, size)
- Audit-Logging für Adapter-Operationen
- Prompt Injection Detection aktiviert
- Risk-Threshold konfiguriert (empfohlen: 0.7)
- Sanitization bei verdächtigen Prompts
- Logging aller Detection-Events
- Rate-Limiting für verdächtige Benutzer
- Vector Encryption aktiviert (siehe VECTOR_ENCRYPTION_CONFIGURATION.md)
- HNSW Encryption aktiviert (siehe HNSW_ENCRYPTION_CONFIGURATION.md)
- Anomalie-Detection für Embeddings
- Baseline regelmäßig aktualisieren
- Threshold-basierte Alerts
// In src/llm/grafana_metrics.cpp:
// LoRa Security Metrics
grafana_metrics::lora_signature_failures.inc();
grafana_metrics::lora_integrity_check_failures.inc();
grafana_metrics::lora_anomalies_detected.inc();
// Prompt Injection Metrics
grafana_metrics::prompt_injection_detections.inc();
grafana_metrics::prompt_injection_risk_score.set(risk_score);
grafana_metrics::prompt_injection_blocks.inc();
// Embedding Anomaly Metrics
grafana_metrics::embedding_anomaly_score.set(anomaly_score);
grafana_metrics::embedding_anomalies_detected.inc();# In grafana/alerts.yaml:
- alert: LoRASignatureFailure
expr: lora_signature_failures > 0
for: 1m
severity: critical
annotations:
summary: "LoRa adapter signature validation failed"
- alert: HighPromptInjectionRate
expr: rate(prompt_injection_detections[5m]) > 0.1
for: 5m
severity: warning
annotations:
summary: "High rate of prompt injection attempts"
- alert: EmbeddingAnomalyDetected
expr: embedding_anomaly_score > 0.9
for: 1m
severity: warning
annotations:
summary: "Highly anomalous embedding detected"llm:
security:
# LoRa Adapter Security
lora_signature_required: true
lora_trusted_signers:
- "a1b2c3d4e5f6..." # Cert fingerprints
- "f6g7h8i9j0k1..."
lora_checksum_verification: true
lora_anomaly_detection: true
lora_anomaly_threshold: 3.0
# Prompt Injection Detection
prompt_injection_enabled: true
prompt_injection_threshold: 0.7
prompt_injection_block_high_risk: false # Warn only
prompt_injection_log_detections: true
# Embedding Anomaly Detection
embedding_anomaly_enabled: true
embedding_anomaly_threshold: 3.0
embedding_min_baseline_samples: 100# LoRa Security
export THEMIS_LORA_REQUIRE_SIGNATURE=true
export THEMIS_LORA_TRUSTED_SIGNERS="cert1.pem,cert2.pem"
# Prompt Security
export THEMIS_PROMPT_INJECTION_DETECTION=true
export THEMIS_PROMPT_INJECTION_THRESHOLD=0.7
# Embedding Security
export THEMIS_EMBEDDING_ANOMALY_DETECTION=true# Run security tests
cd /home/runner/work/ThemisDB/ThemisDB
./build/tests/test_lora_security
# Expected output:
# [==========] Running 20 tests from 5 test suites.
# [----------] 6 tests from LoRASecurityTest
# [ RUN ] LoRASecurityTest.CalculateChecksum
# [ OK ] LoRASecurityTest.CalculateChecksum (1 ms)
# ...
# [==========] 20 tests from 5 test suites ran. (234 ms total)
# [ PASSED ] 20 tests.# Test with real LoRa adapter
./scripts/test_lora_security.sh --adapter ./models/legal-qa.lora
# Test prompt injection detection
./scripts/test_prompt_injection.sh --prompts ./test_data/malicious_prompts.txt
# Test embedding anomalies
./scripts/test_embedding_anomaly.sh --corpus ./test_data/corpus.jsonlSymptom: lora_signature_failures metric increased
Schritte:
- Identifiziere betroffenen Adapter: Check Audit-Logs
- Verifiziere Signatur manuell mit OpenSSL
- Prüfe ob Adapter manipuliert wurde (Checksum)
- Entferne verdächtigen Adapter aus Produktion
- Informiere Security-Team
Symptom: prompt_injection_detections steigt plötzlich
Schritte:
- Identifiziere Benutzer/IP-Adresse
- Aktiviere Rate-Limiting für Benutzer
- Prüfe ob koordinierter Angriff
- Ggf. temporär blockieren
- Analyse der Prompts für neue Patterns
Symptom: embedding_anomaly_score > 0.9
Schritte:
- Identifiziere Dokument/Vektor-ID
- Quarantäne des verdächtigen Embeddings
- Prüfe auf Poisoning-Angriff
- Update Baseline falls False Positive
- Überprüfe Embedding-Modell
- LLM_LORA_ATTACK_VECTORS.md - Vollständige Bedrohungsanalyse
- security_threat_model.md - Allgemeines Threat Model
- Multi-LoRa Manager - LoRa-Verwaltung
- Security Validator - Sicherheitsvalidierung
Bei Fragen oder Problemen:
- Issues: https://github.com/makr-code/ThemisDB/issues
- Slack: #security-channel
- Email: security@themisdb.com