# Changelog - Full Lockdown Security ## 🔒 Modifications apportĂ©es ### Date : 2025-12-02 ### RĂ©sumĂ© Migration complĂšte vers une architecture "full lockdown" oĂč **TOUS** les endpoints nĂ©cessitent une authentification, sauf les endpoints publics essentiels. --- ## 📝 Modifications dĂ©taillĂ©es ### 1. Backend (`server.js`) #### Nouveaux endpoints publics ```javascript GET /api/health // Health check (status server) GET /api/validate // Validation de token (retourne user info) ``` #### Endpoints sĂ©curisĂ©s (authenticate middleware ajoutĂ©) **Lecture (GET) :** - ✅ `GET /lexique` - Ajout `authenticate` - ✅ `GET /api/lexique/:variant` - Ajout `authenticate` - ✅ `GET /api/stats` - Ajout `authenticate` - ✅ `GET /api/search` - Ajout `authenticate` **Actions (POST) :** - ✅ `POST /translate` - DĂ©jĂ  sĂ©curisĂ© - ✅ `POST /api/reload` - Ajout `authenticate` + `requireAdmin` - ✅ `POST /api/debug/prompt` - Ajout `authenticate` - ✅ `POST /api/analyze/coverage` - Ajout `authenticate` - ✅ `POST /api/translate/raw` - Ajout `authenticate` + `translationLimiter` - ✅ `POST /api/translate/batch` - Ajout `authenticate` + `translationLimiter` - ✅ `POST /api/translate/conf2fr` - Ajout `authenticate` + `translationLimiter` - ✅ `POST /api/translate/conf2fr/llm` - DĂ©jĂ  sĂ©curisĂ© **Admin routes :** - ✅ `POST /api/admin/*` - DĂ©jĂ  sĂ©curisĂ© ### 2. Frontend (`public/index.html`) #### Fonction `authFetch()` amĂ©liorĂ©e ```javascript // Avant : Simple wrapper const authFetch = (url, options) => { return fetch(url, { headers: { 'x-api-key': apiKey } }) } // AprĂšs : Avec auto-logout sur 401/403 const authFetch = async (url, options) => { const response = await fetch(url, { headers: { 'x-api-key': apiKey } }) if (response.status === 401 || response.status === 403) { clearApiKey() checkAuth() throw new Error('Session expirĂ©e') } return response } ``` #### Fonction `login()` amĂ©liorĂ©e ```javascript // Avant : Test avec /api/stats await fetch('/api/stats', { headers: { 'x-api-key': apiKey } }) // AprĂšs : Test avec /api/validate + chargement initial const response = await fetch('/api/validate', { headers: { 'x-api-key': apiKey } }) if (response.ok) { setApiKey(apiKey) await loadLexique() // Charge les donnĂ©es aprĂšs connexion } ``` #### Calls `fetch()` → `authFetch()` ```javascript // Avant await fetch('/api/lexique/ancien') await fetch('/api/stats?variant=ancien') // AprĂšs await authFetch('/api/lexique/ancien') await authFetch('/api/stats?variant=ancien') ``` --- ## 🎯 Comportement attendu ### Sans authentification 1. Page HTML se charge 2. Overlay de connexion affichĂ© 3. **AUCUNE** donnĂ©e chargĂ©e 4. Tous les appels API retournent `401 Unauthorized` ### Avec authentification valide 1. Login rĂ©ussi 2. Overlay disparaĂźt 3. DonnĂ©es chargĂ©es automatiquement (lexique, stats) 4. Interface complĂštement fonctionnelle ### Session expirĂ©e 1. Toute requĂȘte retournant 401/403 2. Auto-dĂ©connexion immĂ©diate 3. Overlay rĂ©affichĂ© 4. Message "Session expirĂ©e" --- ## 🚀 Comment tester ### MĂ©thode 1 : Script automatisĂ© (Linux/Mac/WSL) ```bash cd ConfluentTranslator chmod +x test-security.sh ./test-security.sh ``` ### MĂ©thode 2 : Test manuel Voir le fichier `SECURITY_TEST.md` pour la procĂ©dure complĂšte. ### MĂ©thode 3 : Tests curl rapides ```bash # Test endpoint public (doit rĂ©ussir) curl http://localhost:3000/api/health # Test endpoint protĂ©gĂ© sans auth (doit Ă©chouer avec 401) curl http://localhost:3000/api/stats # Test endpoint protĂ©gĂ© avec auth (doit rĂ©ussir) TOKEN="votre-token-ici" curl http://localhost:3000/api/stats -H "x-api-key: $TOKEN" ``` --- ## 📊 Comparaison Avant/AprĂšs ### Avant (Partial Security) | Endpoint | Auth | Rate Limit | Notes | |----------|------|------------|-------| | GET /api/stats | ❌ Non | ❌ Non | Public | | GET /api/lexique/* | ❌ Non | ❌ Non | Public | | POST /translate | ✅ Oui | ✅ Oui | SĂ©curisĂ© | | POST /api/reload | ❌ Non | ❌ Non | **DANGER** | ### AprĂšs (Full Lockdown) | Endpoint | Auth | Rate Limit | Notes | |----------|------|------------|-------| | GET /api/health | ❌ Non | ❌ Non | Public volontaire | | GET /api/validate | ✅ Oui | ❌ Non | Validation token | | GET /api/stats | ✅ Oui | ❌ Non | **SĂ©curisĂ©** | | GET /api/lexique/* | ✅ Oui | ❌ Non | **SĂ©curisĂ©** | | POST /translate | ✅ Oui | ✅ Oui | SĂ©curisĂ© | | POST /api/reload | ✅ Oui + Admin | ❌ Non | **SĂ©curisĂ©** | | POST /api/translate/* | ✅ Oui | ✅ Oui | **SĂ©curisĂ©** | --- ## 🔧 Fichiers modifiĂ©s ``` ConfluentTranslator/ ├── server.js # ✏ ModifiĂ© (ajout authenticate sur tous endpoints) ├── public/index.html # ✏ ModifiĂ© (authFetch partout, auto-logout) ├── SECURITY_TEST.md # ✹ Nouveau (procĂ©dure de test) ├── test-security.sh # ✹ Nouveau (script de test automatisĂ©) └── CHANGELOG_SECURITY.md # ✹ Nouveau (ce fichier) ``` ### Fichiers NON modifiĂ©s ``` auth.js # ✅ InchangĂ© (systĂšme auth dĂ©jĂ  en place) rateLimiter.js # ✅ InchangĂ© logger.js # ✅ InchangĂ© adminRoutes.js # ✅ InchangĂ© data/tokens.json # ✅ InchangĂ© (gĂ©rĂ© automatiquement) ``` --- ## ⚠ Points d'attention ### Token admin - Au premier dĂ©marrage, le serveur crĂ©e automatiquement un token admin - **IMPORTANT** : Sauvegarder ce token en lieu sĂ»r - Le token est stockĂ© dans `data/tokens.json` - Si perdu : supprimer `data/tokens.json` et redĂ©marrer le serveur ### Rate limiting Les endpoints de traduction ont un rate limit : - 10 requĂȘtes par minute par IP - Les erreurs 429 sont normales si dĂ©passement ### CORS Aucune modification CORS nĂ©cessaire (mĂȘme origine). ### Backward compatibility - L'endpoint legacy `GET /lexique` fonctionne toujours - **Mais nĂ©cessite maintenant l'authentification** - Les anciens clients doivent ĂȘtre mis Ă  jour --- ## 🐛 DĂ©pannage ### Erreur : "API key missing" **Cause :** RequĂȘte sans header `x-api-key` **Solution :** VĂ©rifier que `authFetch()` est utilisĂ© partout dans le frontend ### Erreur : "Session expirĂ©e" en boucle **Cause :** Token invalide ou dĂ©sactivĂ© **Solution :** Se reconnecter avec un token valide ### Interface blanche aprĂšs login **Cause :** Erreur de chargement des donnĂ©es **Solution :** VĂ©rifier la console navigateur et les logs serveur ### 401 mĂȘme avec token valide **Cause :** Format du header incorrect **Solution :** Utiliser `x-api-key` (minuscules, tirets) --- ## 📚 Ressources - **Documentation auth :** Voir `auth.js` (commentaires inline) - **Tests manuels :** Voir `SECURITY_TEST.md` - **Tests automatisĂ©s :** Voir `test-security.sh` - **Tokens :** StockĂ©s dans `data/tokens.json` - **Logs :** Voir console serveur --- ## ✅ Validation ### Checklist de dĂ©ploiement - [ ] Serveur dĂ©marre sans erreur - [ ] Token admin créé et sauvegardĂ© - [ ] Page HTML accessible - [ ] Login fonctionne avec token valide - [ ] Tous les endpoints protĂ©gĂ©s retournent 401 sans auth - [ ] Tous les endpoints protĂ©gĂ©s fonctionnent avec auth - [ ] Auto-logout fonctionne sur 401/403 - [ ] Rate limiting actif sur endpoints traduction - [ ] Script `test-security.sh` passe tous les tests --- ## 🎉 RĂ©sultat **✅ FULL LOCKDOWN OPÉRATIONNEL** Tous les endpoints sont maintenant sĂ©curisĂ©s. L'interface HTML ne peut charger aucune donnĂ©e sans authentification valide. Le systĂšme gĂšre automatiquement les sessions expirĂ©es. **SĂ©curitĂ© : 🔒 MAXIMALE**