Security Testing
Security testing must be performed before every deployment. This guide covers how to test for common vulnerabilities.
SQL Injection Testing
Test Procedure
- Identify all user input points in your code
- Test with malicious SQL payloads
- Verify queries are parameterized
Test Cases
# Test with SQL injection payloads
curl -X POST https://reformer-platform.onrender.com/api/vimeo/search \
-H "Content-Type: application/json" \
-d '{
"keywords": ["'\'' OR '\''1'\''='\''1"],
"workout_type": "pilates"
}'
# Expected: Empty results or validation error
# NOT: Database error or unexpected data returned
Payloads to Test
const sqlInjectionPayloads = [
"' OR '1'='1",
"'; DROP TABLE users; --",
"' UNION SELECT * FROM accounts --",
"1' OR '1'='1' --",
"admin'--",
"' OR 1=1--",
"' OR 'a'='a"
];
What to Look For
- ❌ Database errors in response
- ❌ Unexpected data returned
- ❌ Stack traces showing SQL queries
- ✅ Validation errors or empty results
- ✅ No database errors in logs
CORS Testing
Test Procedure
# Test from unauthorized origin (should fail)
curl -H "Origin: https://evil.com" \
-H "Access-Control-Request-Method: POST" \
-X OPTIONS \
https://reformer-platform.onrender.com/api/health
# Expected: CORS error or 403 Forbidden
# NOT: 200 OK with Access-Control-Allow-Origin: *
Test Cases
- Authorized origin - Should succeed
- Unauthorized origin - Should fail with CORS error
- No origin - Should succeed (mobile apps, Postman)
- Malformed origin - Should fail
Authentication Testing
Test Procedure
# Test without authentication (should fail)
curl https://reformer-platform.onrender.com/api/protected-endpoint
# Expected: 401 Unauthorized
# NOT: 200 OK with data
# Test with invalid token (should fail)
curl -H "Authorization: Bearer invalid-token" \
https://reformer-platform.onrender.com/api/protected-endpoint
# Expected: 401 Unauthorized
# NOT: 200 OK
Test Cases
- No token - Should return 401
- Invalid token - Should return 401
- Expired token - Should return 401
- Valid token - Should return 200
Input Validation Testing
Test Procedure
# Test with invalid input types
curl -X POST https://reformer-platform.onrender.com/api/users \
-H "Content-Type: application/json" \
-d '{
"email": "not-an-email",
"age": "not-a-number"
}'
# Expected: 400 Bad Request with validation errors
# NOT: 200 OK or 500 Internal Server Error
Test Cases
- Wrong data types - Should return 400
- Missing required fields - Should return 400
- Invalid formats (email, URL, etc.) - Should return 400
- Extremely long strings - Should return 400 or truncate
- Special characters - Should sanitize or reject
Authorization Testing
Test Procedure
# Test accessing another user's resource
curl -H "Authorization: Bearer user1-token" \
https://reformer-platform.onrender.com/api/users/user2-id/data
# Expected: 403 Forbidden
# NOT: 200 OK with user2's data
Test Cases
- Access own resource - Should succeed
- Access other user's resource - Should fail with 403
- Admin accessing any resource - Should succeed
- Regular user accessing admin endpoint - Should fail with 403
Rate Limiting Testing
Test Procedure
# Send rapid requests
for i in {1..10}; do
curl https://reformer-platform.onrender.com/api/auth/login \
-X POST \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"test"}'
done
# Expected: First few succeed, then 429 Too Many Requests
Test Cases
- Normal rate - Should succeed
- Exceeding rate limit - Should return 429
- Rate limit headers - Should include X-RateLimit-* headers
Secrets Exposure Testing
Test Procedure
-
Search codebase for hardcoded secrets:
grep -r "sk_live\|api_key\|password\|secret" --include="*.js" --include="*.ts" -
Check git history for committed secrets:
git log --all --full-history --source -- "*secret*" "*password*" "*api_key*" -
Check environment variables are set:
# In production, verify all required env vars exist
What to Look For
- ❌ Hardcoded API keys
- ❌ Committed secrets in git
- ❌ Secrets in logs
- ❌ Secrets in error messages
- ✅ All secrets in environment variables
Automated Security Testing
Pre-commit Checks
# Run security linter
npm run lint:security
# Check for known vulnerabilities
npm audit
# Run security tests
npm run test:security
CI/CD Integration
Security tests should run automatically:
- On every pull request
- Before deployment
- On schedule (daily/weekly)
Security Testing Checklist
Before deploying, verify:
- SQL injection tests pass
- CORS tests pass
- Authentication tests pass
- Authorization tests pass
- Input validation tests pass
- Rate limiting tests pass
- No secrets exposed
- Dependencies scanned for vulnerabilities
- Security audit completed
Reporting Security Test Results
Document test results in:
- Pull request comments
- Security audit reports
- Deployment logs
Include:
- Test cases executed
- Results (pass/fail)
- Vulnerabilities found
- Fixes applied