ADR-006: Implementatie van tweefactorauthenticatie
Status
Section titled “Status”Voorgesteld
Context
Section titled “Context”XOOPS heeft verbeterde beveiliging nodig voor gebruikersauthenticatie. Tweefactorauthenticatie (2FA) biedt een extra beveiligingslaag naast wachtwoorden, waardoor accounts worden beschermd, zelfs als wachtwoorden in gevaar komen.
Belangrijkste overwegingen:
- Achterwaartse compatibiliteit met bestaande authenticatie
- Ondersteuning voor meerdere 2FA-methoden
- Gebruikerservaring tijdens installatie en inloggen
- Herstelmechanismen voor verloren apparaten
- Integratie met bestaand toestemmingssysteem
Besluit
Section titled “Besluit”We zullen TOTP (Time-based One-Time Password) implementeren als de primaire 2FA-methode met ondersteuning voor back-upcodes.
Implementatieaanpak
Section titled “Implementatieaanpak”sequenceDiagram participant U as User participant X as XOOPS participant T as TOTP Library participant D as Database
U->>X: Login with password X->>D: Validate password D-->>X: Password valid X->>D: Check 2FA enabled D-->>X: 2FA required X->>U: Request 2FA code U->>X: Submit TOTP code X->>T: Validate code T-->>X: Code valid X->>U: Login successfulDatabaseschema
Section titled “Databaseschema”CREATE TABLE `{PREFIX}_users_2fa` ( `user_id` INT(11) NOT NULL, `secret` VARCHAR(32) NOT NULL, `enabled` TINYINT(1) DEFAULT 0, `backup_codes` TEXT, `last_used` INT(11), `created` INT(11) NOT NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `{PREFIX}_users`(`uid`));Service-interface
Section titled “Service-interface”interface TwoFactorAuthInterface{ public function enable(int $userId): TwoFactorSetup; public function disable(int $userId): void; public function verify(int $userId, string $code): bool; public function generateBackupCodes(int $userId): array; public function isEnabled(int $userId): bool;}Middleware-integratie
Section titled “Middleware-integratie”class TwoFactorMiddleware implements MiddlewareInterface{ public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $session = $request->getAttribute('session');
if ($session->has('pending_2fa_user_id')) { // User needs to complete 2FA if ($this->isVerificationRequest($request)) { return $handler->handle($request); } return new RedirectResponse('/2fa/verify'); }
return $handler->handle($request); }}Gevolgen
Section titled “Gevolgen”Positief
Section titled “Positief”- Aanzienlijk verbeterde accountbeveiliging
- Industriestandaard TOTP-compatibiliteit (Google Authenticator, Authy, enz.)
- Back-upcodes voorkomen accountvergrendeling
- Optioneel per gebruiker: dwingt acceptatie niet af
- PSR-15 middleware maakt schone integratie mogelijk
Negatief
Section titled “Negatief”- Extra inlogstap heeft invloed op de gebruikerservaring
- Gebruikers moeten authenticator-apps beheren
- Voor verloren apparaten is een herstelproces vereist
- Extra databaseopslag en query’s
- Vereist afhankelijkheid van cryptografische bibliotheek
Migratiepad
Section titled “Migratiepad”- Voeg een databasetabel toe voor 2FA-gegevens
- Implementeer de TOTP-service met bibliotheekafhankelijkheid
- Voeg middleware toe aan de authenticatieketen
- Maak een installatie- en verificatie-UI
- Beheerderoptie om 2FA te vereisen voor specifieke groepen
Alternatieven overwogen
Section titled “Alternatieven overwogen”SMS-gebaseerde OTP
Section titled “SMS-gebaseerde OTP”Afgewezen vanwege:
- SIM kwetsbaarheden bij het wisselen
- Kosten van SMS-gateway
- Complexiteit van telefoonnummerverificatie
- Privacyproblemen
Hardwarebeveiligingssleutels (WebAuthn)
Section titled “Hardwarebeveiligingssleutels (WebAuthn)”Uitgesteld voor toekomstig ADR:
- Complexere implementatie
- Historisch gezien beperkte browserondersteuning
- Hogere gebruikerskosten
- Kan later naast TOTP worden toegevoegd
Op e-mail gebaseerd OTP
Section titled “Op e-mail gebaseerd OTP”Afgewezen vanwege:
- Het compromitteren van e-mailaccounts verslaat het doel
- Vertragingen in de levering hebben invloed op de UX
- Problemen met spamfilters
Referenties
Section titled “Referenties”- RFC 6238 - TOTP
- Google Authenticator-sleutelindeling
- ../../02-Core-Concepts/Security/Security-Best-Practices - Beveiligingsrichtlijnen
- ../../02-Core-Concepts/Users-Permissions/Authentication - Auth-systeemdocumentatie