remove duplicate secret key handling
All checks were successful
Docker Build and Publish / build (push) Successful in 6s
All checks were successful
Docker Build and Publish / build (push) Successful in 6s
This commit is contained in:
parent
4c993ebacd
commit
13e61b7bef
13
app.py
13
app.py
@ -32,13 +32,21 @@ from steganography import embed_message, extract_message
|
||||
|
||||
# Add this function to handle secret key persistence
|
||||
def get_or_create_secret_key():
|
||||
"""Get existing secret key or create a new one"""
|
||||
secret_key_file = Path("secret.key")
|
||||
try:
|
||||
if secret_key_file.exists():
|
||||
logger.info("Loading existing secret key")
|
||||
return secret_key_file.read_bytes()
|
||||
else:
|
||||
secret_key = os.urandom(24)
|
||||
logger.info("Generating new secret key")
|
||||
secret_key = os.urandom(32) # Use 32 bytes for better security
|
||||
secret_key_file.write_bytes(secret_key)
|
||||
return secret_key
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling secret key: {e}")
|
||||
# Fallback to a memory-only key if file operations fail
|
||||
return os.urandom(32)
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"server": {"host": "0.0.0.0", "port": 5000},
|
||||
@ -221,9 +229,6 @@ limiter = Limiter(
|
||||
storage_uri="memory://",
|
||||
)
|
||||
|
||||
# Generate a strong secret key at startup
|
||||
app.secret_key = secrets.token_hex(32)
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.csp_nonce = secrets.token_hex(16)
|
||||
|
Loading…
Reference in New Issue
Block a user