saap-plattform / SECURITY_SCAN_REPORT.md
Hwandji's picture
feat: initial HuggingFace Space deployment
4343907
# 🚨 SAAP Security Scan Report - Gitleaks
**Datum:** 2025-11-11 15:49 UTC+1
**Scanner:** Gitleaks v8.27.2
**Status:** ⚠️ KRITISCH - 31 Secrets gefunden
---
## Zusammenfassung
**Git History:** Keine Secrets in Commits (sauber)
**Working Directory:** 31 hardcoded API-Keys gefunden
---
## Gefundene Secrets (Übersicht)
### Kritische Dateien mit hardcoded API-Keys:
| Datei | Zeile | Secret Type | Status |
|-------|-------|-------------|--------|
| `backend/.env` | 23, 65 | OPENROUTER_API_KEY, COLOSSUS_API_KEY | ⚠️ .env sollte nicht committed sein |
| `backend/agents/colossus_agent.py` | - | api_key hardcoded | 🚨 KRITISCH |
| `backend/agents/colossus_saap_agent.py` | 338 | API_KEY hardcoded | 🚨 KRITISCH |
| `backend/agents/openrouter_agent_enhanced.py` | 316 | API_KEY hardcoded | 🚨 KRITISCH |
| `backend/agents/openrouter_saap_agent.py` | 275 | COLOSSUS_KEY hardcoded | 🚨 KRITISCH |
| `backend/test_colossus_integration.py` | 24 | API_KEY hardcoded | ⚠️ Test-Code |
| `backend/scripts/test_colossus_integration.py` | 24 | API_KEY hardcoded | ⚠️ Test-Code |
| `backend/main.py` | 108 | openrouter_key hardcoded | 🚨 KRITISCH |
| `backend/agent.py` | 244, 273, 302 | api_key hardcoded | 🚨 KRITISCH |
| `backend/api/openrouter_client.py` | 355 | api_key hardcoded | 🚨 KRITISCH |
| `backend/agent_templates.json` | 21, 48, 75, 102, 123 | api_key in JSON | ⚠️ Template-Daten |
| `backend/agent_schema.json` | 200, 226, 251 | api_key in JSON | ⚠️ Schema-Daten |
| `backend/models/agent_templates.json` | 21, 48, 75, 102, 123 | api_key in JSON | ⚠️ Template-Daten |
| `backend/models/agent_schema.json` | 200, 226, 251 | api_key in JSON | ⚠️ Schema-Daten |
| `backend/models/agent.py` | 244, 273, 302 | api_key hardcoded | 🚨 KRITISCH |
**Total:** 31 Findings
---
## Lösung: API-Keys aus Environment Variables einlesen
### FIX für `backend/agents/colossus_agent.py`
**VORHER (❌ Unsicher):**
```python
@dataclass
class ColossusConfig:
"""colossus Server Configuration"""
base_url: str = "https://ai.adrian-schupp.de"
api_key: str = "sk-dBoxml3krytIRLdjr35Lnw" # 🚨 HARDCODED!
model: str = "mistral-small3.2:24b-instruct-2506"
max_tokens: int = 1000
```
**NACHHER (✅ Sicher):**
```python
import os
from dataclasses import dataclass, field
@dataclass
class ColossusConfig:
"""colossus Server Configuration"""
base_url: str = "https://ai.adrian-schupp.de"
api_key: str = field(default_factory=lambda: os.getenv("COLOSSUS_API_KEY", ""))
model: str = "mistral-small3.2:24b-instruct-2506"
max_tokens: int = 1000
def __post_init__(self):
if not self.api_key:
raise ValueError(
"COLOSSUS_API_KEY environment variable not set. "
"Please configure it in your .env file."
)
```
### Alternative: Normale Klasse statt Dataclass
```python
import os
class ColossusConfig:
"""colossus Server Configuration"""
def __init__(self):
self.base_url = "https://ai.adrian-schupp.de"
self.api_key = os.getenv("COLOSSUS_API_KEY")
self.model = "mistral-small3.2:24b-instruct-2506"
self.max_tokens = 1000
self.temperature = 0.7
self.timeout = 30
# Validation
if not self.api_key:
raise ValueError(
"❌ COLOSSUS_API_KEY not found in environment variables.\n"
"Set it in backend/.env file:\n"
"COLOSSUS_API_KEY=sk-your-actual-key-here"
)
```
### FIX für Test-Code
**VORHER:**
```python
if __name__ == "__main__":
API_KEY = "sk-dBoxml3krytIRLdjr35Lnw" # ❌ HARDCODED
```
**NACHHER:**
```python
import os
from dotenv import load_dotenv
if __name__ == "__main__":
load_dotenv() # Lädt .env Datei
API_KEY = os.getenv("COLOSSUS_API_KEY")
if not API_KEY:
print("❌ Error: COLOSSUS_API_KEY not set in .env file")
exit(1)
```
---
## Sofortige Maßnahmen (MANDATORY)
### 1. `.env` Datei prüfen
```bash
# Prüfe ob .env committed wurde
git status backend/.env
# Falls committed, aus Git entfernen:
git rm --cached backend/.env
git commit -m "security: remove .env from git tracking"
```
### 2. Hardcoded Keys entfernen
**Alle betroffenen Dateien:**
- `backend/agents/colossus_agent.py`
- `backend/agents/colossus_saap_agent.py`
- `backend/agents/openrouter_agent_enhanced.py`
- `backend/agents/openrouter_saap_agent.py`
- `backend/main.py`
- `backend/agent.py`
- `backend/models/agent.py`
- `backend/api/openrouter_client.py`
**Ersetze in allen Dateien:**
```python
# ❌ VORHER
api_key = "sk-dBoxml3krytIRLdjr35Lnw"
# ✅ NACHHER
import os
api_key = os.getenv("COLOSSUS_API_KEY")
```
### 3. .env richtig konfigurieren
**backend/.env** (niemals committen!):
```bash
# Colossus API Configuration
COLOSSUS_API_KEY=sk-dBoxml3krytIRLdjr35Lnw
# OpenRouter API Configuration
OPENROUTER_API_KEY=dein-openrouter-key-hier
```
### 4. .gitignore validieren
**Bereits korrekt:**
```gitignore
# Secrets
.env
.env.*
!.env.example
```
### 5. Dependencies installieren
Falls `python-dotenv` fehlt:
```bash
pip install python-dotenv
```
In allen Python-Dateien am Anfang:
```python
from dotenv import load_dotenv
import os
load_dotenv() # Lädt .env automatisch
```
---
## Template & Schema Dateien
⚠️ **JSON Template/Schema Dateien mit Platzhaltern:**
- `backend/agent_templates.json`
- `backend/agent_schema.json`
- `backend/models/agent_templates.json`
- `backend/models/agent_schema.json`
**Lösung:**
```json
{
"api_key": "{{COLOSSUS_API_KEY}}",
"model": "mistral-small3.2:24b-instruct-2506"
}
```
Beim Laden ersetzen:
```python
import json
import os
with open('agent_templates.json') as f:
template = json.load(f)
# Replace placeholders
for agent in template:
if '{{COLOSSUS_API_KEY}}' in agent.get('api_key', ''):
agent['api_key'] = os.getenv('COLOSSUS_API_KEY')
```
---
## API-Key Rotation (EMPFOHLEN)
Da der Key `sk-dBoxml3krytIRLdjr35Lnw` möglicherweise exponiert wurde:
1. **Neuen API-Key generieren** beim Colossus-Provider
2. **Alten Key deaktivieren/löschen**
3. **Neuen Key in `.env` eintragen**
4. **Deployment aktualisieren**
---
## Best Practices
### ✅ DO's:
- Verwende **Environment Variables** für alle Secrets
- Nutze **python-dotenv** für lokale Entwicklung
- Behalte **.env.example** mit Platzhaltern im Repo
- Validiere Secrets beim App-Start
- Dokumentiere benötigte Env-Vars in README
### ❌ DON'Ts:
- **NIEMALS** API-Keys hardcoded im Code
- **NIEMALS** `.env` in Git committen
- **NIEMALS** Secrets in Logs ausgeben
- **NIEMALS** Test-Keys in Production verwenden
---
## Nächste Schritte
1. [ ] Alle hardcoded API-Keys durch `os.getenv()` ersetzen
2. [ ] `.env` aus Git-Tracking entfernen (falls committed)
3. [ ] API-Key rotieren (neuen Key generieren)
4. [ ] Secrets Management Tool erwägen (z.B. HashiCorp Vault)
5. [ ] Pre-commit Hook für Gitleaks einrichten
6. [ ] Security Audit wiederholen nach Fixes
---
## Gitleaks Pre-Commit Hook (Optional)
**Installation:**
```bash
# Install pre-commit
pip install pre-commit
# Create .pre-commit-config.yaml
cat > .pre-commit-config.yaml << 'EOF'
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.27.2
hooks:
- id: gitleaks
EOF
# Install hook
pre-commit install
```
Verhindert zukünftig das Committen von Secrets!
---
**Erstellt:** 2025-11-11
**Next Scan:** Nach Implementierung der Fixes