Skip to main content
This guide ensures all code follows security best practices and identifies potential vulnerabilities before they reach production.

When to Apply

Authentication & Authorization

Implementing login, user roles, permissions

User Input & File Uploads

Handling forms, file uploads, API parameters

API Endpoints

Creating REST APIs, webhooks, external integrations

Sensitive Data

Working with secrets, payments, personal information

Pre-Commit Security Checklist

Before ANY commit, verify:
  • No hardcoded secrets (API keys, passwords, tokens)
  • All user inputs validated
  • SQL injection prevention (parameterized queries)
  • XSS prevention (sanitized HTML)
  • CSRF protection enabled
  • Authentication/authorization verified
  • Rate limiting on all endpoints
  • Error messages don’t leak sensitive data

1. Secrets Management

Never Hardcode Secrets

Environment Variables

1

Create .env.local

2

Add to .gitignore

3

Validate at Startup

4

Deploy to Hosting Platform

Add secrets to:
  • Vercel: Project Settings → Environment Variables
  • Railway: Project → Variables
  • Render: Environment → Environment Variables

Verification Checklist

  • No hardcoded API keys, tokens, or passwords
  • All secrets in environment variables
  • .env.local in .gitignore
  • No secrets in git history
  • Production secrets in hosting platform

2. Input Validation

Always Validate User Input

File Upload Validation

Verification Checklist

  • All user inputs validated with schemas
  • File uploads restricted (size, type, extension)
  • No direct use of user input in queries
  • Whitelist validation (not blacklist)
  • Error messages don’t leak sensitive info

3. SQL Injection Prevention

Never concatenate SQL queries with user input.

Verification Checklist

  • All database queries use parameterized queries
  • No string concatenation in SQL
  • ORM/query builder used correctly
  • Supabase queries properly sanitized

4. Authentication & Authorization

JWT Token Handling

Authorization Checks

Row Level Security (Supabase)

Verification Checklist

  • Tokens stored in httpOnly cookies (not localStorage)
  • Authorization checks before sensitive operations
  • Row Level Security enabled in Supabase
  • Role-based access control implemented
  • Session management secure

5. XSS Prevention

Sanitize HTML

Content Security Policy

Verification Checklist

  • User-provided HTML sanitized
  • CSP headers configured
  • No unvalidated dynamic content rendering
  • React’s built-in XSS protection used

6. CSRF Protection

CSRF Tokens

SameSite Cookies

Verification Checklist

  • CSRF tokens on state-changing operations
  • SameSite=Strict on all cookies
  • Double-submit cookie pattern implemented

7. Rate Limiting

API Rate Limiting

Expensive Operations

Verification Checklist

  • Rate limiting on all API endpoints
  • Stricter limits on expensive operations
  • IP-based rate limiting
  • User-based rate limiting (authenticated)

8. Sensitive Data Exposure

Logging

Error Messages

Verification Checklist

  • No passwords, tokens, or secrets in logs
  • Error messages generic for users
  • Detailed errors only in server logs
  • No stack traces exposed to users

9. Dependency Security

Regular Updates

Lock Files

Verification Checklist

  • Dependencies up to date
  • No known vulnerabilities (npm audit clean)
  • Lock files committed
  • Dependabot enabled on GitHub
  • Regular security updates

Security Testing

Automated Security Tests

Pre-Deployment Checklist

Before ANY production deployment:
  • Secrets: No hardcoded secrets, all in env vars
  • Input Validation: All user inputs validated
  • SQL Injection: All queries parameterized
  • XSS: User content sanitized
  • CSRF: Protection enabled
  • Authentication: Proper token handling
  • Authorization: Role checks in place
  • Rate Limiting: Enabled on all endpoints
  • HTTPS: Enforced in production
  • Security Headers: CSP, X-Frame-Options configured
  • Error Handling: No sensitive data in errors
  • Logging: No sensitive data logged
  • Dependencies: Up to date, no vulnerabilities
  • Row Level Security: Enabled in Supabase
  • CORS: Properly configured
  • File Uploads: Validated (size, type)

Security Response Protocol

1

STOP Immediately

If security issue found, stop all work.
2

Use security-reviewer Agent

Or delegate to security-reviewer agent.
3

Fix CRITICAL Issues

Address all critical vulnerabilities before continuing.
4

Rotate Exposed Secrets

If any secrets were exposed, rotate immediately.
5

Review Entire Codebase

Search for similar issues across the project.

ECC Security Tools

security-reviewer Agent

Specialized agent for vulnerability detection and security audits.

/security-scan Command

Run AgentShield security auditor (1282 tests, 102 rules).

security-review Skill

Comprehensive security checklist and patterns.

AgentShield

External tool: npx ecc-agentshield scan --fix

Resources


Security is not optional. One vulnerability can compromise the entire platform. When in doubt, err on the side of caution.