A startup validation system that ensures GITHUB_WEBHOOK_SECRET is configured before the application starts, preventing unauthorized webhook events.
| File | Type | Purpose |
|---|---|---|
backend/src/validation/webhookSecretValidation.ts |
NEW | Validation logic |
backend/src/index.ts |
MODIFIED | Calls validation before startup |
backend/test/webhookSecretValidation.test.ts |
NEW | 13 comprehensive tests |
.env.example |
MODIFIED | Enhanced documentation |
$ NODE_ENV=production npm start
# If GITHUB_WEBHOOK_SECRET is missing:
# Error: GITHUB_WEBHOOK_SECRET environment variable is not configured...
# Exit code: 1$ npm run dev
# If GITHUB_WEBHOOK_SECRET is missing:
# [WARN] startup_validation_warning
# [INFO] server_listen { port: 3001 }# 1. Generate secret
SECRET=$(openssl rand -hex 20)
# 2. Set environment
export NODE_ENV=production
export GITHUB_WEBHOOK_SECRET=$SECRET
# 3. Start app
npm start# 1. Copy environment template
cp .env.example .env
# 2. Optional: Set test secret
echo "GITHUB_WEBHOOK_SECRET=test-secret-123" >> .env
# 3. Start dev server
npm run dev# Run webhook secret validation tests
npm test -- webhookSecretValidation.test.ts
# Expected: 13 tests, all passing ✓Error: GITHUB_WEBHOOK_SECRET environment variable is not configured.
This is required to verify GitHub webhook signatures and prevent
unauthorized webhook events. Set GITHUB_WEBHOOK_SECRET to a secure
random string (e.g., openssl rand -hex 20).
[WARN] startup_validation_warning
reason: "missing_github_webhook_secret"
environment: "development"
message: "GitHub webhooks will not be verified. This is only acceptable in development."
- Generate secure secret:
openssl rand -hex 20 - Set
GITHUB_WEBHOOK_SECRETin production - Set
NODE_ENV=productionin production - Verify
.envis in.gitignore - Test startup with secret configured
- Test webhook signature verification
- Configure GitHub webhook with same secret
| Problem | Solution |
|---|---|
| "GITHUB_WEBHOOK_SECRET not configured" | Set environment variable: export GITHUB_WEBHOOK_SECRET=... |
| Webhook returns 401 | Verify secret matches GitHub webhook settings |
| Webhook returns 500 | Check that secret is set at runtime |
- WEBHOOK_SECRET_VALIDATION.md - Complete technical documentation
- IMPLEMENTATION_SUMMARY.md - Overview and deployment guide
- WEBHOOK_SECURITY_GUIDE.md - Visual guide with examples
- CODE_EXAMPLES.md - Complete code reference
✅ All 13 tests passing:
- Production environment: 5 tests
- Development environment: 4 tests
- Default environment: 1 test
- Edge cases: 3 tests
✅ Production startup fails with clear error if secret missing ✅ Development startup logs warning if secret missing ✅ .env.example documents the variable ✅ Unit tests cover all scenarios ✅ Error messages are clear and actionable ✅ Validation runs before routes/servers initialized ✅ Integrates with existing webhook verification
- Review documentation
- Deploy to staging
- Test webhook verification
- Deploy to production with secret configured
- Monitor webhook delivery logs
- Set up alerts for failures
For detailed information, see:
- Technical details:
WEBHOOK_SECRET_VALIDATION.md - Quick overview:
IMPLEMENTATION_SUMMARY.md - Visual guide:
WEBHOOK_SECURITY_GUIDE.md - Code reference:
CODE_EXAMPLES.md