Skip to content
arrival-spacePublic

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MFA-Test-

A small Node.js server that implements Time-Based One-Time Password (TOTP) Multi-Factor Authentication (MFA) using the Authenticator app protocol.

Features

  • 🔐 Generate MFA secret keys
  • 📱 QR code generation for easy Authenticator app setup
  • ✅ Verify TOTP tokens
  • 🌐 Simple web interface for testing
  • 🔒 Compatible with Google Authenticator, Authy, Microsoft Authenticator, and other TOTP apps

Installation

  1. Clone this repository:
git clone https://github.com/arrival-space/MFA-Test-.git
cd MFA-Test-
  1. Install dependencies:
npm install

Usage

  1. Start the server:
npm start
  1. Open your browser and navigate to:
http://localhost:3000
  1. Follow the on-screen instructions:
    • Enter a username and generate an MFA secret
    • Scan the QR code with your Authenticator app
    • Enter the 6-digit code from your app to verify

API Endpoints

Generate Secret

POST /api/generate-secret

Request body:

{
  "username": "your-username"
}

Response:

{
  "secret": "BASE32_ENCODED_SECRET",
  "qrCode": "data:image/png;base64,...",
  "otpauth_url": "otpauth://totp/..."
}

Verify Token

POST /api/verify-token

Request body:

{
  "username": "your-username",
  "token": "123456"
}

Response (success):

{
  "success": true,
  "message": "Token verified successfully!"
}

Check Status

GET /api/status/:username

Response:

{
  "username": "your-username",
  "hasSecret": true,
  "verified": true
}

Health Check

GET /api/health

Response:

{
  "status": "ok",
  "message": "MFA Server is running"
}

Dependencies

  • express - Web framework for Node.js
  • speakeasy - TOTP/HOTP library for two-factor authentication
  • qrcode - QR code generation

Security Notes

⚠️ Important: This is a demonstration/testing application. For production use, you MUST:

  • Store secrets securely in a database with encryption (currently stored in-memory)
  • Use HTTPS for all connections to prevent secret interception
  • Implement rate limiting on verification endpoints to prevent brute force attacks (Critical - not implemented in this demo)
  • Add user authentication before MFA setup
  • Implement proper session management
  • Add backup codes for account recovery
  • Never expose secrets in API responses after initial setup
  • Follow security best practices for your specific use case

Known Security Limitations in Demo

This demo application has the following security limitations that must be addressed before production use:

  1. ⚠️ No rate limiting - The /api/verify-token endpoint is vulnerable to brute force attacks
  2. ⚠️ In-memory storage - Secrets are lost on restart and not encrypted
  3. ⚠️ Secret exposure - The API returns the secret in responses (should only be shown once)
  4. ⚠️ No authentication - Anyone can create/verify MFA secrets without authentication

How It Works

  1. Secret Generation: Creates a unique base32-encoded secret key for each user
  2. QR Code: Generates a QR code containing the secret and app name
  3. TOTP Algorithm: Uses the Time-Based One-Time Password algorithm (RFC 6238)
  4. Verification: Validates 6-digit codes that change every 30 seconds

License

ISC

Releases

Packages

Contributors

Languages