Security patterns and hardening practices for this monorepo. Use when implementing authentication, configuring CORS, validating input, handling secrets, securing API endpoints, or reviewing code for vulnerabilities. Triggers on tasks involving security, auth guards, env validation, CORS, CSP, rate limiting, or OWASP compliance.
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Security patterns and hardening practices for this monorepo. Use when implementing authentication, configuring CORS, validating input, handling secrets, securing API endpoints, or reviewing code for vulnerabilities. Triggers on tasks involving security, auth guards, env validation, CORS, CSP, rate limiting, or OWASP compliance.
Define validation in contracts, not in controllers or services
Always set .min() and .max() for strings
Use .int().positive() for IDs
Use .email() for email fields
Use .url() for URL fields
Never trust raw req.body — always go through contract validation
Validation Error Response Format
When validation fails, the HttpExceptionFilter returns:
{"success":false,"error":{"code":"BadRequestException","message":["title: String must contain at least 1 character"],"details":{}},"timestamp":"2025-07-12T00:00:00.000Z"}
Error Masking
The HttpExceptionFilter ensures internal errors never leak to clients:
// Only catches HttpException (not raw Error)// Strips internal details// Returns consistent error format// Logs ZodSerializationException details to console (not response)
Rules:
Never throw raw Error — always wrap in HttpException or subclass
Never include stack traces in responses
Log full error details server-side, return safe messages client-side
Use appropriate HTTP status codes (400, 401, 403, 404, 500)
Network Security (AWS)
Security Group Rules
ALB SG:
Inbound: 80 (HTTP), 443 (HTTPS) from 0.0.0.0/0
Outbound: All
Web ECS SG:
Inbound: 3001 from ALB SG only
Outbound: All
Backend ECS SG:
Inbound: 3000 from ALB SG only
Outbound: All
Rules:
ECS tasks are in private subnets (no public IP)
Only ALB can reach ECS services (SG-to-SG reference)
Outbound allowed for external API calls and database connections