Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ temp/
.gcp/firebase-adminsdk-fbsvc-cc86734eaf.json
.env.staging
.env.development
package-lock.json
1 change: 1 addition & 0 deletions docs/DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export async function GET() {

- [ ] All environment variables are set correctly
- [ ] JWT secrets are cryptographically secure (32+ characters)
- [ ] No environment variables start with "GITHUB_" (reserved for GitHub Actions)
- [ ] Database security rules are configured
- [ ] API rate limiting is enabled
- [ ] CORS is properly configured
Expand Down
8 changes: 8 additions & 0 deletions lib/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ The configuration system validates:
- **Secret strength** meets requirements
- **Environment-specific** requirements
- **Security best practices**
- **GitHub Actions compatibility** (no GITHUB_ prefixed variables)

### Validation Errors

Expand All @@ -236,6 +237,7 @@ The system will exit with an error if:
- Variables have invalid formats
- Security requirements are not met
- Environment-specific requirements are not satisfied
- Environment variables start with "GITHUB_" (reserved for GitHub Actions)

### Validation Warnings

Expand All @@ -254,6 +256,12 @@ The system will warn about:
- **ENCRYPTION_KEY**: Must be exactly 32 characters
- **WEBHOOK_SECRET**: Must be at least 16 characters

### GitHub Actions Compatibility

- **No GITHUB_ prefixed variables**: Environment variables starting with "GITHUB_" are reserved for GitHub Actions and will cause validation to fail
- This prevents conflicts with GitHub Actions reserved environment variables
- Use alternative naming conventions (e.g., `GH_CUSTOM_VAR` instead of `GITHUB_CUSTOM_VAR`)

### Production Security

- No debug mode in production
Expand Down
37 changes: 37 additions & 0 deletions lib/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,43 @@ describe('Configuration System', () => {
result.warnings.some(warning => warning.includes('placeholder'))
).toBe(true)
})

it('should fail validation with GITHUB_ prefixed environment variables', () => {
process.env.GITHUB_SECRET = 'my-secret-value'
process.env.GITHUB_TOKEN = 'my-token-value'

const result = validateConfiguration()
expect(result.success).toBe(false)
expect(
result.errors.some(error => error.includes('GITHUB_SECRET'))
).toBe(true)
expect(
result.errors.some(error => error.includes('GITHUB_TOKEN'))
).toBe(true)
expect(
result.errors.some(error =>
error.includes('reserved for GitHub Actions')
)
).toBe(true)

// Clean up
delete process.env.GITHUB_SECRET
delete process.env.GITHUB_TOKEN
})

it('should pass validation without GITHUB_ prefixed environment variables', () => {
// Ensure no GITHUB_ variables exist
Object.keys(process.env).forEach(key => {
if (key.startsWith('GITHUB_')) {
delete process.env[key]
}
})

const result = validateConfiguration()
expect(
result.errors.some(error => error.includes('GITHUB_'))
).toBe(false)
})
})

describe('Environment-Specific Configuration', () => {
Expand Down
14 changes: 14 additions & 0 deletions lib/config/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ function validateSecurityConfig(
result.errors.push('WEBHOOK_SECRET must be at least 16 characters long')
}

// Check for GitHub reserved environment variable names
const githubReservedVars = Object.keys(process.env).filter(key =>
key.startsWith('GITHUB_')
)

if (githubReservedVars.length > 0) {
githubReservedVars.forEach(varName => {
result.errors.push(
`Environment variable "${varName}" starts with "GITHUB_" which is reserved for GitHub Actions. ` +
'Please rename this variable to avoid conflicts with GitHub Actions reserved environment variables.'
)
})
}

// Check for weak secrets in production
if (env === 'production') {
const weakPatterns = ['password', '123456', 'secret', 'admin']
Expand Down