| name | security-testing-verification |
| description | Test security features and verify implementation before deployment. Use this skill when you need to test CSRF protection, rate limiting, input validation, verify security headers, run security audits, or check the pre-deployment security checklist. Triggers include "test security", "security testing", "verify security", "security checklist", "pre-deployment", "test CSRF", "test rate limit", "security verification". |
Security Testing & Verification
Built-In Security Tests
This project includes automated tests and verification scripts for all security features.
Testing Rate Limiting
Automated Test Script
node scripts/test-rate-limit.js
What it tests:
- Makes 10 consecutive requests to rate-limited endpoint
- Verifies first 5 succeed (HTTP 200)
- Verifies requests 6-10 are blocked (HTTP 429)
- Tests rate limit reset after 60 seconds
Expected output:
Testing Rate Limiting (5 requests/minute per IP)
Request 1: ✓ 200 - Success
Request 2: ✓ 200 - Success
Request 3: ✓ 200 - Success
Request 4: ✓ 200 - Success
Request 5: ✓ 200 - Success
Request 6: ✗ 429 - Too many requests
Request 7: ✗ 429 - Too many requests
Request 8: ✗ 429 - Too many requests
Request 9: ✗ 429 - Too many requests
Request 10: ✗ 429 - Too many requests
✓ Rate limiting is working correctly!
Manual Testing
for i in {1..10}; do
echo "Request $i:"
curl -s -o /dev/null -w "%{http_code}\n" \
http://localhost:3000/api/test-rate-limit
sleep 0.1
done
Test Reset After Window
for i in {1..5}; do
curl http://localhost:3000/api/test-rate-limit
done
sleep 61
curl http://localhost:3000/api/test-rate-limit
Testing CSRF Protection
Test 1: Request Without Token (Should Fail)
curl -X POST http://localhost:3000/api/example-protected \
-H "Content-Type: application/json" \
-d '{"title": "test"}'
Test 2: Request With Valid Token (Should Succeed)
TOKEN=$(curl -s http://localhost:3000/api/csrf \
-c cookies.txt | jq -r '.csrfToken')
curl -X POST http://localhost:3000/api/example-protected \
-b cookies.txt \
-H "Content-Type: application/json" \
-H "X-CSRF-Token: $TOKEN" \
-d '{"title": "test"}'
Test 3: Token Reuse (Should Fail)
TOKEN=$(curl -s http://localhost:3000/api/csrf \
-c cookies.txt | jq -r '.csrfToken')
curl -X POST http://localhost:3000/api/example-protected \
-b cookies.txt \
-H "X-CSRF-Token: $TOKEN" \
-d '{"title": "test"}'
curl -X POST http://localhost:3000/api/example-protected \
-b cookies.txt \
-H "X-CSRF-Token: $TOKEN" \
-d '{"title": "test2"}'
Test 4: Invalid Token (Should Fail)
curl -X POST http://localhost:3000/api/example-protected \
-H "Content-Type: application/json" \
-H "X-CSRF-Token: fake-token-12345" \
-d '{"title": "test"}'
Testing Input Validation
Test XSS Sanitization
curl -X POST http://localhost:3000/api/example-protected \
-H "Content-Type: application/json" \
-H "X-CSRF-Token: <get-token-first>" \
-d '{"title": "<script>alert(1)</script>"}'
Test Length Validation
curl -X POST http://localhost:3000/api/example-protected \
-H "Content-Type: application/json" \
-H "X-CSRF-Token: <token>" \
-d "{\"title\": \"$(printf 'A%.0s' {1..200})\"}"
Test Email Validation
curl -X POST http://localhost:3000/api/contact \
-H "Content-Type: application/json" \
-d '{
"name": "Test User",
"email": "not-an-email",
"subject": "Test",
"message": "Test message"
}'
Test Required Fields
curl -X POST http://localhost:3000/api/contact \
-H "Content-Type: application/json" \
-d '{
"name": "Test User"
}'
Testing Security Headers
Test All Headers
curl -I http://localhost:3000
Test CSP
curl -I http://localhost:3000 | grep "Content-Security-Policy"
Test HSTS (Production Only)
curl -I https://yourapp.com | grep "Strict-Transport-Security"
Test Protected Route Headers
curl -I http://localhost:3000/dashboard
Testing Authentication
Test Unauthenticated Access
curl http://localhost:3000/api/protected-endpoint
Test Authenticated Access
curl http://localhost:3000/api/protected-endpoint \
-H "Cookie: __session=<clerk-session-token>"
Test Authorization (Resource Ownership)
curl http://localhost:3000/api/posts/user-abc-post-123 \
-H "Cookie: __session=<different-user-token>"
Test Subscription Gating
curl http://localhost:3000/api/premium/generate \
-H "Cookie: __session=<free-user-token>"
Testing Error Handling
Test Production Error Messages
export NODE_ENV=production
curl http://localhost:3000/api/error-test
Test Development Error Messages
curl http://localhost:3000/api/error-test
Testing Dependency Security
Run npm Audit
npm audit
Run Production Audit
npm audit --production
Check Outdated Packages
npm outdated
Run Security Check Script
bash scripts/security-check.sh
Online Security Testing Tools
Security Headers Scanner
Tool: https://securityheaders.com/
How to use:
- Deploy your app
- Enter URL in Security Headers scanner
- Check for A+ rating
What it checks:
- Content-Security-Policy
- X-Frame-Options
- X-Content-Type-Options
- Strict-Transport-Security
- Referrer-Policy
- Permissions-Policy
Mozilla Observatory
Tool: https://observatory.mozilla.org/
How to use:
- Enter your deployed URL
- Run scan
- Check score (aim for A+)
What it checks:
- Security headers
- Cookie security
- HTTPS configuration
- Subresource integrity
- Content Security Policy
SSL Labs
Tool: https://www.ssllabs.com/ssltest/
How to use:
- Enter your domain
- Wait for scan (takes ~2 minutes)
- Check for A+ rating
What it checks:
- SSL/TLS configuration
- Certificate validity
- Protocol support
- Cipher suite strength
- HSTS configuration
Pre-Deployment Security Checklist
Run through this checklist before every production deployment:
Environment & Configuration
Dependencies
Security Features
Authentication & Authorization
API Security
Payment Security (if applicable)
Testing
Monitoring
Automated Testing Script
security-test.sh
Create a comprehensive test script:
#!/bin/bash
echo "================================="
echo "Security Testing Suite"
echo "================================="
echo ""
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
PASSED=0
FAILED=0
run_test() {
local test_name=$1
local command=$2
local expected=$3
echo -n "Testing $test_name... "
result=$(eval $command 2>&1)
if echo "$result" | grep -q "$expected"; then
echo -e "${GREEN}✓ PASS${NC}"
((PASSED++))
else
echo -e "${RED}✗ FAIL${NC}"
echo " Expected: $expected"
echo " Got: $result"
((FAILED++))
fi
}
echo "=== Dependency Security ==="
run_test "npm audit" "npm audit --production" "found 0 vulnerabilities"
echo ""
echo "=== Rate Limiting ==="
echo "Running rate limit test script..."
node scripts/test-rate-limit.js
echo ""
echo "=== Security Headers ==="
run_test "X-Frame-Options" "curl -I http://localhost:3000" "X-Frame-Options: DENY"
run_test "X-Content-Type-Options" "curl -I http://localhost:3000" "X-Content-Type-Options: nosniff"
run_test "Content-Security-Policy" "curl -I http://localhost:3000" "Content-Security-Policy"
echo ""
echo "================================="
echo "Tests Passed: $PASSED"
echo "Tests Failed: $FAILED"
echo "================================="
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}All tests passed!${NC}"
exit 0
else
echo -e "${RED}Some tests failed!${NC}"
exit 1
fi
Run it:
bash scripts/security-test.sh
Continuous Security Testing
Add to CI/CD Pipeline
name: Security Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run npm audit
run: npm audit --production
- name: Check for outdated packages
run: npm outdated || true
- name: Build application
run: npm run build
- name: Start server (background)
run: npm run dev &
env:
NODE_ENV: test
- name: Wait for server
run: npx wait-on http://localhost:3000
- name: Run security tests
run: bash scripts/security-test.sh
- name: Stop server
run: pkill -f "npm run dev"
Manual Penetration Testing
Test XSS in All Input Fields
-
Try these payloads in every input:
<script>alert('XSS')</script>
<img src=x onerror=alert('XSS')>
<svg onload=alert('XSS')>
javascript:alert('XSS')
"><script>alert('XSS')</script>
-
Verify all are sanitized
Test SQL Injection
-
Try these in search/query fields:
' OR '1'='1
'; DROP TABLE users; --
' UNION SELECT * FROM users --
-
Verify input validation blocks or sanitizes
Test CSRF
-
Create malicious HTML file:
<form action="http://localhost:3000/api/delete-account" method="POST">
<input type="hidden" name="confirm" value="yes" />
</form>
<script>document.forms[0].submit();</script>
-
Open while logged in
-
Verify request blocked (403 Forbidden)
Test Authorization
- Create resource as User A
- Try to access/modify as User B
- Verify 403 Forbidden
What To Monitor Post-Deployment
Daily
- Error rates (Vercel dashboard)
- Failed authentication attempts (Clerk dashboard)
- Rate limit violations (check logs for 429 responses)
Weekly
- Run
npm audit --production
- Check GitHub Dependabot alerts
- Review error logs for patterns
Monthly
- Full security audit
- Update dependencies
- Re-run security testing suite
- Check security headers (securityheaders.com)
References
Next Steps
- For fixing issues: Use appropriate security skill (csrf-protection, rate-limiting, etc.)
- For deployment: Complete pre-deployment checklist above
- For monitoring: Set up automated security scans in CI/CD
- For ongoing maintenance: Run monthly security audit