Skip to content

monxcode/secure-web-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

126 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

INTERNSHIP PROJECT [ 01 ]

Organization: Cryptonic Area
Duration: 1 - 8 February 2026

Secure Web Application & Threat Hardening

Project Overview

A cybersecurity-focused web application built for learning defensive security principles and threat mitigation strategies. This project demonstrates secure coding practices, authentication/authorization mechanisms, and protection against common web vulnerabilities.

Project Type: Cybersecurity & Ethical Hacking Internship Project-01
Technology Stack: Python Flask, SQLite, HTML/CSS
Focus: Defensive Security, Secure Development Lifecycle

Security Features Implemented

1. Authentication & Authorization

  • User Registration & Login:
    • Secure account creation and authentication
  • Role-Based Access Control (RBAC):
    • User and Admin roles with different privileges
  • Session Management:
    • Secure session handling with timeout (30 minutes)

2. Password Security

  • bcrypt Hashing:
    • Passwords stored using bcrypt with unique salts
  • Strong Password Policy:
    • Minimum 12 characters
    • Mixed case letters
    • Numbers and special characters
    • Common pattern detection
  • Account Lockout:
    • 5 failed attempts lock account for 5 minutes
  • Password Change:
    • Secure password update mechanism

3. Input Validation & Sanitization

  • SQL Injection Prevention:
    • Parameterized queries exclusively
    • Input pattern validation
    • No string concatenation in SQL
  • Cross-Site Scripting (XSS) Prevention:
    • HTML entity encoding
    • Input sanitization on server-side
    • Content Security Policy headers
  • Email Validation:
    • Proper email format verification

4. Session Security

  • Secure Cookies:
    • HTTP-only
    • Secure flags
  • Session Fixation Prevention:
    • Regeneration on login
  • Timeout:
    • Automatic session expiration
  • Forced Re-authentication:
    • For sensitive operations

5. Additional Security Controls

  • Security Headers:
    • Content-Security-Policy
    • X-Frame-Options: DENY
    • X-Content-Type-Options: nosniff
    • Strict-Transport-Security
    • X-XSS-Protection
  • Audit Logging:
    • All security events logged
  • Error Handling:
    • Generic error messages (no information leakage)
  • Database Security:
    • Least privilege principle in schema design

Threats and Mitigations

Threats Addressed:

Threat Mitigation Implemented
SQL Injection Parameterized queries, input validation, SQL keyword filtering
Cross-Site Scripting (XSS) Input sanitization, HTML encoding, CSP headers
Brute Force Attacks Account lockout, rate limiting, strong password requirements
Session Hijacking Secure cookies, session regeneration, timeouts
Information Disclosure Generic error messages, no stack traces in production
Weak Authentication bcrypt hashing, password complexity, account lockout
CSRF State-changing operations require authentication
Clickjacking X-Frame-Options: DENY header

Security Layers:

  1. Perimeter Defense:
    • Security headers
    • Rate limiting
  2. Authentication Layer:
    • Strong password hashing
    • Session management
  3. Authorization Layer:
    • Role-based access control
  4. Input Validation Layer:
    • Sanitization
    • Validation
    • Encoding
  5. Data Layer:
    • Parameterized queries
    • Prepared statements
  6. Monitoring Layer:
    • Audit logging
    • Security event tracking

Application Flow

1. Registration Process


User Input β†’ Input Validation β†’ Password Strength Check β†’ 
Sanitization β†’ bcrypt Hashing β†’ Database Insert β†’ Success/Error Response

2. Authentication Flow


Login Request β†’ Input Sanitization β†’ Database Lookup β†’ 
Password Verification β†’ Session Creation β†’ Access Control β†’ Dashboard Redirect

3. Request Processing


HTTP Request β†’ Security Headers β†’ Session Validation β†’ 
Input Sanitization β†’ Business Logic β†’ Secure Response β†’ Audit Logging

Installation & Setup

Prerequisites

  • Python 3.8+
    • Install Python

-> For Linux πŸ‘‡πŸ»:

sudo apt update
sudo apt install python3 python3-pip -y

-> For Windows πŸ‘‡πŸ»:

winget install Python.Python.3
  • pip package manager
    • flask
    • bcrypt
    • Werkzeug

-> For Windows πŸ‘‡πŸ»:

py -m pip install flask bcrypt werkzeug

-> For Linux πŸ‘‡πŸ»:

python3 -m pip install flask bcrypt werkzeug

Installation Steps

  1. Clone/Download the project:
git clone https://github.com/monxcode/secure-web-app.git
  1. Move into the project directory:
cd secure-web-app
  1. Create virtual environment:
python -m venv venv

-> For Linux πŸ‘‡πŸ»:

source venv/bin/activate

-> For Windows πŸ‘‡πŸ»:

venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Initialize the database:
The app will create database.db with initial schema
python app.py
  1. Run the application:
python app.py
  1. Access the application:

Application Structure

secure-web-app/
β”‚
β”œβ”€β”€ app.py                    # Main Flask application
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ database.db               # SQLite database (Auto Generated)
β”œβ”€β”€ README.md                 # Project documentation
β”‚
β”œβ”€β”€ templates/                # HTML templates
β”‚   β”œβ”€β”€ login.html            # Login page
β”‚   β”œβ”€β”€ register.html         # Registration page
β”‚   β”œβ”€β”€ dashboard.html        # User dashboard
β”‚   β”œβ”€β”€ admin.html            # Admin dashboard
β”‚   └── error.html            # Error handling page
β”‚
└── screenshots/              # Application screenshots
    β”œβ”€β”€ register.png
    β”œβ”€β”€ login.png
    β”œβ”€β”€ post.png
    β”œβ”€β”€ User_dashboard.png
    β”œβ”€β”€ Admin_sec_dash.png
    └── Admin_dashboard.png

Key Security Functions

  • validate_password(password)

  • Enforces strong password policy and checks for common weak patterns.

  • sanitize_input(input_string)

  • Prevents XSS by encoding HTML entities and removing dangerous characters.

  • is_sql_safe(input_string)

  • Checks for SQL injection patterns using keyword and special character detection.

  • log_security_event(user_id, event_type, details)

  • Logs security events for audit trail and monitoring.

  • add_security_headers(response)

  • Adds security headers to all HTTP responses.

  • Testing Security Features

Manual Testing Checklist:

1. Authentication:

  • Register with weak password (should fail)
  • Login with invalid credentials (account should lock after 5 attempts)
  • Session timeout after 30 minutes of inactivity

2. Authorization:

  • User cannot access admin dashboard
  • Admin can access all areas
  • Unauthenticated users redirected to login

3. Input Validation:

  • Try SQL injection in form fields
  • Attempt XSS payload injection
  • Test special character handling

4. Session Security:

  • Copy session cookie (should be invalid)
  • Test logout functionality
  • Verify session regeneration

Best Practices Demonstrated

  1. Never store plain-text passwords
  2. Always use parameterized queries
  3. Validate and sanitize all user inputs
  4. Implement principle of least privilege
  5. Use secure session management
  6. Employ defense in depth strategy
  7. Log security events for monitoring
  8. Use security headers
  9. Handle errors securely
  10. Keep dependencies updated

For Production Deployment

Important Security Notes ⚠️

  1. Change default admin password immediately
  2. Enable HTTPS with proper certificates
  3. Set debug=False in production
  4. Use environment variables for secrets
  5. Implement additional logging
  6. Add rate limiting
  7. Regular security audits
  8. Keep Flask and dependencies updated

Additional Recommendations:

  1. Use strong password hashing (bcrypt)
  2. Implement proper input validation and sanitization
  3. Protect against CSRF and XSS attacks
  4. Restrict admin panel access (IP or role-based)
  5. Use secure session cookies
  6. Disable unnecessary services and ports
  7. Backup the database securely and regularly

Learning Outcomes:

  • Understood secure authentication and authorization concepts
  • Implemented password hashing using bcrypt
  • Gained hands-on experience with Flask framework
  • Learned secure session and cookie management
  • Applied role-based access control (Admin/User)
  • Implemented basic input validation and error handling
  • Understood importance of environment variables for security
  • Learned secure project structure and deployment practices
  • Improved GitHub documentation and version control workflow

This project provides hands-on experience with:

  • Secure authentication and authorization
  • Password security best practices
  • Input validation and sanitization
  • Session management security
  • SQL injection prevention
  • XSS protection
  • Security headers implementation
  • Audit logging and monitoring
  • Secure error handling

License

Educational Use - Cybersecurity Learning Project

Disclaimer

This project is for educational purposes only. Always consult security professionals and conduct thorough penetration testing before deploying applications to production.

Project Summary

This complete secure web application demonstrates:

  1. Authentication Security:
    • bcrypt hashing
    • Strong password policies
    • Account lockout
  2. Authorization:
    • Role-based access control with user/admin separation
  3. Input Security:
    • SQL injection prevention
    • XSS protection
    • Input sanitization
  4. Session Security:
    • Secure cookies
    • Timeout
    • Regeneration
    • Hijacking protection
  5. Defense in Depth:
    • Multiple security layers at different levels
  6. Monitoring:
    • Comprehensive audit logging of security events
  7. Secure Headers:
    • CSP
    • HSTS
    • X-Frame-Options

The application is ready to run immediately and serves as an excellent learning tool for understanding web application security principles. Each security control is clearly commented and explained in the code.


What I Learned During This Project

During the development of this Secure Web Application, I gained strong practical understanding of real-world cybersecurity and secure development practices. Key learnings include:

  • How authentication and authorization systems work internally
  • Implementing Role-Based Access Control (RBAC) for users and admins
  • Secure password handling using bcrypt hashing and salting
  • Designing and enforcing strong password policies
  • Preventing SQL Injection using parameterized queries
  • Protecting applications against Cross-Site Scripting (XSS) attacks
  • Importance of input validation and sanitization
  • Secure session management (timeouts, regeneration, secure cookies)
  • Implementing security headers like CSP, HSTS, X-Frame-Options
  • Handling errors securely without leaking sensitive information
  • Logging and monitoring security events for auditing
  • Applying Defense in Depth security strategy
  • Understanding common web threats and their mitigations
  • Writing cleaner, more secure, and maintainable backend code
  • Following secure development lifecycle best practices

This project helped me bridge the gap between theoretical cybersecurity concepts and their practical implementation in a real web application.


Application Screenshots

Login Page

Login Page

Registration Page

Registration Page

Error Page

Error Page

Admin Security Dashboard

Admin Security Dashboard

User Dashboard

User Dashboard

Admin Dashboard

Admin Dashboard

Terminal + Browser

Terminal + Browser

About

Secure Flask web app with authentication, RBAC, and basic web security protections.

Resources

Stars

Watchers

Forks

Contributors