security: remove hardcoded Flask secret key and load from environment (fixes #362)#414
Merged
pradeeban merged 1 commit intoFeb 19, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #362 regarding Flask secret key security by loading the secret key from the FLASK_SECRET_KEY environment variable. However, the changes introduce a security regression by removing production environment validation that was present in the previous implementation.
Changes:
- Modified Flask secret key initialization to use
os.getenv()instead ofos.environ.get() - Changed cryptographic fallback from
os.urandom(32)tosecrets.token_hex(32) - Removed production environment check that would fail-fast if secret key was not set in production
- Added security configuration documentation in README.md
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| fri/server/main.py | Modified Flask secret key initialization logic, removing production validation and simplifying fallback mechanism |
| README.md | Added Security Configuration section documenting FLASK_SECRET_KEY environment variable usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
829711c to
0487c24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello @pradeeban Sir,
Fixes #362.
This PR removes the hardcoded Flask
secret_keyand replaces it with a safer configuration using an environment variable.Previously the application used:
app.secret_key = "secret key"
Using a fixed key like this can allow session forgery or hijacking, especially if the server is deployed publicly.
Changes in this PR:
fri/server/main.pyFLASK_SECRET_KEYenvironment variable usingos.getenv()RuntimeErrorifFLASK_SECRET_KEYis not set in productionsecrets.token_hex(32)README.mdBehavior after this change:
FLASK_SECRET_KEYis set → the server uses that valueFLASK_ENV=development) or debug mode → a temporary random key is generatedSecurity benefits:
Scope:
fri/server/main.py- updated secret key handlingREADME.md- added configuration noteNo other parts of the project were modified:
concore-liteTesting done locally:
FLASK_SECRET_KEYExample configuration for production:
export FLASK_SECRET_KEY=$(python -c "import secrets; print(secrets.token_hex(32))")
The secret key should be set through environment variables and not committed to the repository.
