Skip to content

Commit 7585cbd

Browse files
committed
fix: Remove hardcoded secrets to pass Trivy security scan
CRITICAL SECURITY FIXES: - Replaced hardcoded SECRET_KEY with environment variable (JWT_SECRET_KEY) - Replaced hardcoded admin password with environment variable (ADMIN_PASSWORD) - Auto-generate secure random values when environment variables not set - Added .env.example file with configuration template - Updated .gitignore to exclude all .env files These changes address the critical security vulnerabilities flagged by Trivy
1 parent f271233 commit 7585cbd

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

‎.env.example‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Environment Variables for n8n-workflows
2+
# Copy this file to .env and configure with your own values
3+
4+
# Security Configuration
5+
JWT_SECRET_KEY=your-secret-jwt-key-change-this-in-production
6+
ADMIN_PASSWORD=your-secure-admin-password-change-this
7+
8+
# API Configuration
9+
ADMIN_TOKEN=your-admin-api-token-for-protected-endpoints
10+
11+
# Database Configuration (optional)
12+
WORKFLOW_DB_PATH=database/workflows.db
13+
14+
# Server Configuration (optional)
15+
HOST=127.0.0.1
16+
PORT=8000
17+
18+
# CORS Origins (optional, comma-separated)
19+
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8080,https://zie619.github.io
20+
21+
# Rate Limiting (optional)
22+
RATE_LIMIT_REQUESTS=60
23+
RATE_LIMIT_WINDOW=60

‎.gitignore‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ wheels/
2020
.installed.cfg
2121
*.egg
2222

23-
# Virtual environments
23+
# Environment files
2424
.env
25+
.env.local
26+
.env.production
27+
28+
# Virtual environments
2529
.venv
2630
env/
2731
venv/

‎src/user_management.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
import jwt
1616
from datetime import datetime, timedelta
1717
import json
18+
import os
1819

19-
# Configuration
20-
SECRET_KEY = "your-secret-key-change-in-production"
20+
# Configuration - Use environment variables for security
21+
SECRET_KEY = os.environ.get("JWT_SECRET_KEY", secrets.token_urlsafe(32))
2122
ALGORITHM = "HS256"
2223
ACCESS_TOKEN_EXPIRE_MINUTES = 30
2324

@@ -116,16 +117,22 @@ def create_default_admin(self):
116117
admin_count = cursor.fetchone()[0]
117118

118119
if admin_count == 0:
119-
admin_password = "admin123" # Change in production
120+
# Use environment variable or generate secure random password
121+
admin_password = os.environ.get("ADMIN_PASSWORD", secrets.token_urlsafe(16))
120122
password_hash = self.hash_password(admin_password)
121-
123+
122124
cursor.execute("""
123125
INSERT INTO users (username, email, full_name, password_hash, role)
124126
VALUES (?, ?, ?, ?, ?)
125127
""", ("admin", "admin@n8n-workflows.com", "System Administrator", password_hash, "admin"))
126-
128+
127129
conn.commit()
128-
print("Default admin user created: admin/admin123")
130+
# Only print password if it was auto-generated (not from env)
131+
if "ADMIN_PASSWORD" not in os.environ:
132+
print(f"Default admin user created: admin/{admin_password}")
133+
print("WARNING: Please change this password immediately after first login!")
134+
else:
135+
print("Default admin user created with environment-configured password")
129136

130137
conn.close()
131138

0 commit comments

Comments
 (0)