This document outlines the security practices and policies for the THPMG website project.
| Feature | Status | Implementation |
|---|---|---|
| XSS Protection | ✅ Complete | CSP, input sanitization, React built-in |
| CSRF Protection | ✅ Complete | Origin validation, SameSite cookies |
| Input Validation | ✅ Complete | Server & client-side validation |
| Rate Limiting | ✅ Complete | API rate limiting with headers |
| Security Headers | ✅ Complete | Full header configuration |
| Secret Management | ✅ Complete | Environment variables, .gitignore |
The application implements comprehensive security headers via next.config.ts and middleware.ts:
default-src 'self';
script-src 'self' 'unsafe-inline' https://*.googletagmanager.com https://*.google-analytics.com;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
img-src 'self' data: https:;
connect-src 'self' https:;
frame-src 'none';
object-src 'none';
base-uri 'self';
form-action 'self';
- X-XSS-Protection:
1; mode=block- XSS filtering - X-Frame-Options:
DENY- Clickjacking prevention - X-Content-Type-Options:
nosniff- MIME type sniffing prevention - Referrer-Policy:
strict-origin-when-cross-origin- Referrer control - Strict-Transport-Security:
max-age=63072000; includeSubDomains; preload- HTTPS enforcement (production only) - Permissions-Policy:
geolocation=(), microphone=(), camera=(), payment=()- Feature restriction
All user inputs are validated and sanitized at multiple levels:
- Real-time field validation
- Input length limits
- Format validation (email, phone)
- XSS character filtering
- Comprehensive validation functions
- Input sanitization with character removal
- Length enforcement
- Type checking
// Example validation
validateEmail(email) // RFC 5322 compliant
validatePhone(phone) // International format
validateRequired(value) // Length and presence- React Built-in: Automatic escaping of JSX expressions
- Input Sanitization: Removes
<,>,',",&characters - Content Security Policy: Restricts script execution
- X-XSS-Protection Header: Browser XSS filter
- ❌ No usage of
dangerouslySetInnerHTML - ❌ No direct DOM manipulation with user input
- ✅ All user input is sanitized before use
- ✅ Output encoding handled by React
- Origin Validation: API routes verify
Originheader against allowed origins - SameSite Cookies: Default browser behavior for session cookies
- Content-Type Check: Only accepts
application/jsonfor POST requests
// Allowed origins from environment
ALLOWED_ORIGINS=https://your-domain.com,https://www.your-domain.com| Endpoint | Window | Max Requests |
|---|---|---|
| /api/contact | 1 minute | 5 requests |
X-RateLimit-Limit: 5
X-RateLimit-Remaining: 3
X-RateLimit-Reset: 1234567890
Retry-After: 30
For production, replace in-memory rate limiting with Redis:
// Example Redis implementation
import { Redis } from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);- ✅
.env.localis in.gitignore - ✅
.env.exampleprovides template without values - ✅ Production secrets managed via deployment platform (Vercel)
- ✅ No hardcoded secrets in codebase
ALLOWED_ORIGINS # CORS allowed origins
NEXT_PUBLIC_SITE_URL # Site URL for CSP
REDIS_URL # Optional: for distributed rate limitingRun npm audit to check for vulnerabilities.
- 4 low severity vulnerabilities in
jest-environment-jsdom(dev dependency only) - These do not affect production builds
# Check for vulnerabilities
npm audit
# Fix vulnerabilities
npm audit fix
# Update specific packages
npm update <package>- Verify all forms have proper input validation
- Test XSS injection attempts in all input fields
- Verify security headers are present in responses
- Check that no sensitive information is exposed in errors
- Validate that CSP is properly configured
- Test rate limiting functionality
- Verify CORS configuration
# Security audit
npm audit
# Type checking
npm run build
# Linting (includes security rules)
npm run lintIf you discover a security vulnerability:
- Do not create a public GitHub issue
- Email the security team with details
- Include:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
- Allow 90 days for remediation before disclosure
┌─────────────────────────────────────────────────────────────┐
│ Client (Browser) │
│ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐ │
│ │ Input Validation│ │ XSS Prevention │ │ CSRF Token │ │
│ └────────┬────────┘ └────────┬────────┘ └──────┬───────┘ │
└───────────┼─────────────────────┼─────────────────┼─────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ Middleware Layer │
│ ┌───────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ Security Hdrs │ │ Attack Pattern │ │ CORS Check │ │
│ └───────────────┘ │ Detection │ └────────────────┘ │
│ └────────────────┘ │
└─────────────────────────────┬───────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ API Routes │
│ ┌───────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ Rate Limiting │ │ CSRF Origin │ │ Input Valid. │ │
│ └───────────────┘ │ Validation │ │ & Sanitization │ │
│ └────────────────┘ └────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Implement Redis-based rate limiting for production
- Add CSP reporting endpoint
- Implement security.txt (RFC 9116)
- Add Web Application Firewall (WAF) rules
- Implement automated security scanning in CI/CD
- Add security-focused E2E tests