A full-stack web application designed to teach developers about common web vulnerabilities through intentionally insecure code examples. This platform demonstrates real-world security risks including SQL injection and Cross-Site Scripting (XSS) attacks.
This project is an educational tool for learning about web application security vulnerabilities. It provides a safe environment to understand SQL injection, XSS, and authentication mechanisms by exposing them in a controlled learning environment.
The application consists of three main components:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Next.js + React + TS) β
β β’ Authentication UI β
β β’ CRUD interface for Ingredients, Models, Process β
β β’ Intentionally vulnerable XSS demo β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β API Calls (JSON)
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β Backend (Express.js + PostgreSQL) β
β β’ JWT Authentication β
β β’ Raw SQL queries (vulnerable) β
β β’ RESTful API endpoints β
β β’ Intentional SQL injection vulnerabilities β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Database Operations
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β Database (PostgreSQL) β
β β’ Ingredients table β
β β’ Models table β
β β’ Processes table β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Authentication:
- POST
/auth/login- Generate JWT token (any non-empty username/password accepted for demo) - GET
/health- Health check
Ingredients:
- POST
/ingredients- Create new ingredient - GET
/ingredients?q=<query>- Search ingredients (vulnerable to SQL injection) - PUT
/ingredients/:id- Update ingredient - DELETE
/ingredients/:id- Delete ingredient
Models:
- POST
/models- Create new model - GET
/models?q=<query>- Search models - PUT
/models/:id- Update model - DELETE
/models/:id- Delete model
Processes:
- POST
/processes- Create new process - GET
/processes?q=<query>- Search processes - PUT
/processes/:id- Update process - DELETE
/processes/:id- Delete process
- Docker & Docker Compose (recommended)
- OR
- Node.js 16+, PostgreSQL 12+, npm
# Clone the repository
git clone https://github.com/slimskhab/cybersecurity.git
cd cybersecurity
# Start all services (db, backend, frontend)
docker-compose up
# The application will be available at:
# Frontend: <http://localhost:3000>
# Backend: <http://localhost:4000>
# Database: <localhost:5432># Create PostgreSQL database
createdb cybersecuritycd backend
npm install
# Create .env file
cat > .env << EOF
NODE_ENV=development
PORT=4000
PGHOST=localhost
PGPORT=5432
PGUSER=postgres
PGPASSWORD=postgres
PGDATABASE=cybersecurity
JWT_SECRET=dev-secret
EOF
# Start backend
npm run dev # Development mode with auto-reload
# or
npm start # Production modecd frontend
npm install
# Create .env.local file (if backend on different host)
echo "NEXT_PUBLIC_API_URL=http://localhost:4000" > .env.local
# Start frontend
npm run devOpen http://localhost:3000 in your browser.
Location: Search endpoints (GET /ingredients?q=<payload>)
Vulnerable Code Pattern:
// Backend uses raw SQL string concatenation
const query = `SELECT * FROM ingredients WHERE name LIKE '%${searchTerm}%'`;Attack Examples:
GET /ingredients?q=%' OR 1=1 --
GET /ingredients?q=%' UNION SELECT * FROM users --
GET /ingredients?q=%'; DROP TABLE ingredients; --
Learning: How parameterized queries and prepared statements prevent SQL injection.
Location: Item descriptions in the frontend
Vulnerable Code Pattern:
// React component rendering user input without sanitization
<div dangerouslySetInnerHTML={{ __html: item.description }} />Attack Examples:
<img src=x onerror=alert('XSS')>
<script>alert('Stored XSS successfully')</script>
<svg onload=fetch('/api/steal-data')>Learning: How to properly sanitize user input and use safe rendering methods.
Method: JWT (JSON Web Tokens)
Credentials: Any non-empty username/password combination works (for demo purposes)
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Usage: Include token in Authorization: Bearer <token> header for protected endpoints.
cybersecurity/
βββ backend/
β βββ src/
β β βββ index.js # Express app setup
β β βββ controllers/ # Request handlers
β β β βββ ingredientController.js
β β β βββ modelController.js
β β β βββ processController.js
β β βββ middleware/
β β β βββ auth.js # JWT verification
β β βββ routers/ # Route definitions
β β β βββ ingredientRouter.js
β β β βββ modelRouter.js
β β β βββ processRouter.js
β β βββ services/
β β β βββ db.js # Database connection
β β β βββ ingredientService.js
β β β βββ modelService.js
β β β βββ processService.js
β β βββ models/
β β βββ README.md
β βββ Dockerfile
β βββ package.json
β βββ .env (create locally)
β
βββ frontend/
β βββ src/
β β βββ app/
β β β βββ page.tsx # Home (redirects to /ingredients or /login)
β β β βββ layout.tsx # Root layout
β β β βββ globals.css # Global styles
β β β βββ login/
β β β β βββ page.tsx # Login page
β β β βββ ingredients/
β β β β βββ page.tsx # Ingredients CRUD + search (SQL injection demo)
β β β βββ models/
β β β β βββ page.tsx # Models CRUD
β β β βββ processes/
β β β βββ page.tsx # Processes CRUD
β β βββ components/
β β β βββ AuthProvider.tsx # Auth context provider
β β β βββ Protected.tsx # Protected route wrapper
β β β βββ CrudSuite.tsx # Reusable CRUD component
β β β βββ Nav.tsx # Navigation bar
β β βββ lib/
β β βββ api.ts # API client utilities
β β βββ auth.ts # Token management
β βββ Dockerfile
β βββ package.json
β βββ next.config.ts
β βββ tsconfig.json
β βββ .env.local (create if needed)
β
βββ docker-compose.yml # Multi-container setup
βββ README.md # This file
- Runtime: Node.js
- Framework: Express.js v5.1.0
- Database: PostgreSQL 16 (Alpine)
- Authentication: JWT (jsonwebtoken)
- Middleware: CORS, body-parser, dotenv
- Framework: Next.js 15.5.3
- Language: TypeScript
- UI Framework: React 19.1.0
- Styling: Tailwind CSS 4
- Package Manager: npm
- Containers: Docker & Docker Compose
- Database Image: postgres:16-alpine
- Node Image: node:latest (default from alpine)
After working through this platform, you will understand:
-
SQL Injection Attacks
- How to identify vulnerable SQL patterns
- Impact of unsanitized user input in queries
- Proper mitigation using parameterized queries
-
XSS (Cross-Site Scripting)
- Reflected vs. Stored XSS vulnerabilities
- DOM-based XSS attacks
- Content Security Policy (CSP) headers
- Safe HTML rendering techniques
-
Authentication & Authorization
- JWT token generation and validation
- Token expiration and refresh mechanisms
- Bearer token authentication
-
Secure Development Practices
- Input validation and sanitization
- Output encoding
- Environment variable management
- HTTPS/CORS considerations
DO NOT USE THIS CODE IN PRODUCTION!
This codebase is intentionally vulnerable for educational purposes only. Never deploy applications with:
- SQL string interpolation
- Unsanitized dynamic HTML rendering
- Weak secret keys
- Demo authentication logic
For production applications, implement:
- Parameterized queries / ORMs (Sequelize, TypeORM, Prisma)
- Input validation libraries (joi, yup, validator)
- Output encoding / HTML escaping (xss, sanitize-html)
- Proper secret management (AWS Secrets Manager, HashiCorp Vault)
- Rate limiting, HTTPS, CSRF protection, etc.
# Login
curl -X POST <http://localhost:4000/auth/login> \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"password"}' \
| jq '.token' # Extract token
# Use token for protected endpoints
TOKEN="<your-token-here>"
curl -H "Authorization: Bearer $TOKEN" \
<http://localhost:4000/health>
# Try SQL injection
curl -H "Authorization: Bearer $TOKEN" \
"<http://localhost:4000/ingredients?q=%27%20OR%201=1%20-->"- Navigate to http://localhost:3000
- Login with any credentials (e.g., username:
admin, password:password) - Try entering SQL injection payloads in search fields
- Try entering XSS payloads in description fields
- OWASP Top 10: https://owasp.org/Top10/
- SQL Injection: https://owasp.org/www-community/attacks/SQL_Injection
- XSS Prevention: https://owasp.org/www-community/attacks/xss/
- NIST Cybersecurity Framework: https://www.nist.gov/cyberframework
This educational project is provided as-is for learning purposes.
Suggestions for additional vulnerabilities or improvements are welcome!
Last Updated: 2026
Version: 1.0.0
Status: Educational - Do Not Use in Production