Skip to main content

Overview

The Auth Security Demo consists of two separate Flask applications that demonstrate the contrast between vulnerable and secure coding practices:
  • Vulnerable App: Port 5000 - Demonstrates common security flaws
  • Secure App: Port 5001 - Implements security best practices
Educational Use Only: These applications are designed for learning purposes. Never deploy the vulnerable version in production or on public networks.

Starting the Applications

1

Start the vulnerable application

Open a terminal and run:
cd vulnerable
python3 app.py
Expected output:
* Serving Flask app 'app'
* Debug mode: off
WARNING: This is a development server. Do not use it in production.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.x.x:5000
The vulnerable app runs on port 5000 with debug mode disabled for realistic testing.
2

Start the secure application

Open a new terminal (keep the first one running) and run:
cd secure
python3 app.py
Expected output:
* Serving Flask app 'app'
* Debug mode: off
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5001
The secure app runs on port 5001 to avoid conflicts.
3

Verify both apps are running

Check that both servers are responding:
# Test vulnerable app
curl -I http://localhost:5000

# Test secure app
curl -I http://localhost:5001
Both should return HTTP 200 OK responses.

Accessing the Applications

Vulnerable Application

Local Access:
http://localhost:5000
Default Credentials:
  • Admin: admin / admin123
  • User: usuario / password123

Secure Application

Local Access:
http://localhost:5001
Default Credentials:
  • Admin: admin / admin123
  • User: usuario / password123

Application Features

Both applications include the same features to allow direct comparison:
  • Login Page (/login): User authentication
  • Register Page (/register): New user registration
  • Logout (/logout): Session termination
Test accounts are pre-configured in both databases:
UsernamePasswordRole
adminadmin123admin
usuariopassword123user
  • Dashboard (/dashboard): Main landing page after login
  • Profile (/profile): User profile with query parameter ?id=X
These routes require active sessions and demonstrate authorization vulnerabilities.
Both apps use SQLite with the same schema:
CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL UNIQUE,
    password TEXT NOT NULL,
    email TEXT,
    role TEXT DEFAULT 'user',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
Key Difference:
  • Vulnerable: Passwords stored in plain text
  • Secure: Passwords hashed with bcrypt

Configuration Details

app = Flask(__name__)
app.secret_key = 'clave_super_secreta_123'  # INSECURE: Hardcoded secret
Insecure Practices:
  • Hardcoded secret key
  • No CSRF protection
  • No security headers
  • SQL injection vulnerable
  • XSS vulnerable
  • IDOR vulnerable
Port: 5000 (default Flask development port)

Network Access

By default, both apps listen on 0.0.0.0, making them accessible from:
  • http://localhost:5000 (or 5001)
  • http://127.0.0.1:5000 (or 5001)
  • http://<your-local-ip>:5000 (or 5001)
Other devices on your network can access via your local IP.

Monitoring and Logs

1

View real-time logs

When running in development mode, logs appear in the terminal:
# Watch vulnerable app logs
tail -f vulnerable.log

# Watch secure app logs
tail -f secure.log
The vulnerable app prints SQL queries to console for educational purposes.
2

Check for SQL queries (vulnerable app)

The vulnerable app logs raw SQL queries:
Query ejecutada: SELECT * FROM users WHERE username = 'admin' AND password = 'admin123'
This helps you see exactly how SQL injection works.
3

Monitor HTTP requests

Use browser developer tools (F12) to inspect:
  • Network requests
  • Response headers
  • Cookies and sessions
  • JavaScript errors (for XSS testing)

Stopping the Applications

If running in a terminal, press:
Ctrl + C
This sends a SIGINT signal to gracefully stop the Flask server.

Quick Reference

ApplicationPortURLPurpose
Vulnerable5000http://localhost:5000Demonstrate vulnerabilities
Secure5001http://localhost:5001Show secure implementations
Common Commands:
# Start vulnerable
cd vulnerable && python3 app.py

# Start secure
cd secure && python3 app.py

# Check running apps
lsof -i :5000,5001

# View logs
tail -f *.log

Next Steps

Test Vulnerabilities

Learn how to exploit the vulnerable application

Troubleshooting

Fix common issues with running the apps

Build docs developers (and LLMs) love