Secret Key
All checks were successful
Docker Build and Publish / build (push) Successful in 6s

This commit is contained in:
Tanishq Dubey 2024-11-05 19:36:44 -05:00
parent 9c1e6f0e94
commit 4c993ebacd

16
app.py
View File

@ -11,7 +11,6 @@ from datetime import datetime
from pathlib import Path from pathlib import Path
from logging import getLogger from logging import getLogger
import logging import logging
from logging import getLogger
from logging.config import dictConfig from logging.config import dictConfig
import toml import toml
@ -31,13 +30,23 @@ from models import Session as DBSession
from models import SiteConfig, init_db from models import SiteConfig, init_db
from steganography import embed_message, extract_message from steganography import embed_message, extract_message
# Add this function to handle secret key persistence
def get_or_create_secret_key():
secret_key_file = Path("secret.key")
if secret_key_file.exists():
return secret_key_file.read_bytes()
else:
secret_key = os.urandom(24)
secret_key_file.write_bytes(secret_key)
return secret_key
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
"server": {"host": "0.0.0.0", "port": 5000}, "server": {"host": "0.0.0.0", "port": 5000},
"directories": {"upload": "uploads", "thumbnail": "thumbnails"}, "directories": {"upload": "uploads", "thumbnail": "thumbnails"},
"admin": {"password": secrets.token_urlsafe(16)}, # Generate secure random password "admin": {"password": secrets.token_urlsafe(16)}, # Generate secure random password
} }
# Add this logging configuration before creating the Flask app # Configure logging
dictConfig({ dictConfig({
'version': 1, 'version': 1,
'formatters': { 'formatters': {
@ -66,8 +75,9 @@ dictConfig({
# Get logger for this module # Get logger for this module
logger = getLogger(__name__) logger = getLogger(__name__)
# Create Flask app with persistent secret key
app = Flask(__name__) app = Flask(__name__)
app.secret_key = os.urandom(24) app.secret_key = get_or_create_secret_key()
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS