A Faculty Secure Portal built twice: first full of real-world security mistakes, then rebuilt after a proper security audit. Placing both versions side by side shows exactly how an attack works and how the fix stops it.
Warning
The vulnerable version is intentionally insecure. Run it only on your own machine for testing. Never deploy it.
| Security Area | Vulnerable Version | Secure Version |
|---|---|---|
| Passwords | Stored as plaintext | Hashed |
| SQL Queries | Injection risk | Parameterized queries |
| CSRF | No protection | Token validation |
| OTP | Stored as plaintext | Hashed |
| File Upload | Weak validation | Type, size and content checks |
| Sessions | Default settings | Secure cookies |
| Rate Limiting | Missing | Login and OTP throttling |
| Security Headers | Limited | Enabled |
| Debug Mode | Enabled | Disabled |
| Secrets | Weak fallback | Environment variables |
Click to expand
# Vulnerable: user input goes straight into the query
query = f"SELECT * FROM users WHERE username = '{username}'"
# Secure: parameterized query
db.execute("SELECT * FROM users WHERE username = ?", (username,))Entering ' OR '1'='1 in the login form logs you in on the vulnerable version. The secure version rejects it.
| Layer | Technology |
|---|---|
| Frontend | HTML, CSS, JavaScript |
| Backend | Python, Flask |
| Database | SQLite |
| Environment | Local security lab |
CodeAlpha-SecureWeb-App/
├── assets/
│ ├── CodeAlpha-logo.png
│ └── flow.svg
├── vulnerable/
│ ├── frontend/
│ └── backend/
│ └── v-app.py
└── secure/
├── frontend/
└── backend/
└── s-app.py
git clone https://github.com/<your-username>/CodeAlpha-SecureWeb-App.git
cd CodeAlpha-SecureWeb-Apppip install flaskpython vulnerable/backend/v-app.pyexport SECRET_KEY="your-long-random-secret"
python secure/backend/s-app.pyThis project is for educational and authorized security testing only. The author is not responsible for misuse.
