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
23
app.py
23
app.py
@ -32,13 +32,21 @@ from steganography import embed_message, extract_message
|
|||||||
|
|
||||||
# Add this function to handle secret key persistence
|
# Add this function to handle secret key persistence
|
||||||
def get_or_create_secret_key():
|
def get_or_create_secret_key():
|
||||||
|
"""Get existing secret key or create a new one"""
|
||||||
secret_key_file = Path("secret.key")
|
secret_key_file = Path("secret.key")
|
||||||
if secret_key_file.exists():
|
try:
|
||||||
return secret_key_file.read_bytes()
|
if secret_key_file.exists():
|
||||||
else:
|
logger.info("Loading existing secret key")
|
||||||
secret_key = os.urandom(24)
|
return secret_key_file.read_bytes()
|
||||||
secret_key_file.write_bytes(secret_key)
|
else:
|
||||||
return secret_key
|
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 = {
|
DEFAULT_CONFIG = {
|
||||||
"server": {"host": "0.0.0.0", "port": 5000},
|
"server": {"host": "0.0.0.0", "port": 5000},
|
||||||
@ -221,9 +229,6 @@ limiter = Limiter(
|
|||||||
storage_uri="memory://",
|
storage_uri="memory://",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate a strong secret key at startup
|
|
||||||
app.secret_key = secrets.token_hex(32)
|
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
g.csp_nonce = secrets.token_hex(16)
|
g.csp_nonce = secrets.token_hex(16)
|
||||||
|
Loading…
Reference in New Issue
Block a user