File size: 7,536 Bytes
4343907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# 🚨 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