Fix: Remove hardcoded debug=True in Flask entrypoints (#4810)#4859
Fix: Remove hardcoded debug=True in Flask entrypoints (#4810)#4859jonesmate wants to merge 1 commit into
Conversation
Replaced hardcoded debug=True with environment-controlled FLASK_DEBUG variable and added a regression test.
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
godd-ctrl
left a comment
There was a problem hiding this comment.
Requesting changes on current head ae797e8.
The Flask debug regression itself passes, but the PR fails the repository BCOS/SPDX gate because the new tests/test_flask_debug_security.py file has no SPDX header.
Validation performed:
- python -m pytest tests\test_flask_debug_security.py -q -> 1 passed
- python -m py_compile changed Python files -> passed with a pre-existing keeper_explorer.py SyntaxWarning
- git diff --check origin/main...HEAD -> passed
- python tools\bcos_spdx_check.py --base-ref origin/main -> failed: missing SPDX header in tests/test_flask_debug_security.py
- rg over changed entrypoints found no remaining public app.run(... debug=True) literal after the patch
508704820
left a comment
There was a problem hiding this comment.
Code Review: Remove Hardcoded debug=True in Flask Entry Points
Summary
Alternative fix to #4843. Replaces debug=True with os.environ.get('FLASK_DEBUG') == '1' across Flask entrypoints.
Comparison with #4843
- #4843:
os.environ.get("FLASK_DEBUG", "").lower() in {"1", "true", "yes", "on"}— more flexible - #4859:
os.environ.get('FLASK_DEBUG') == '1'— stricter, only "1" enables debug
What Works Well
- Same critical security fix: Prevents Flask debugger RCE on public interfaces
- Stricter default: Only "1" enables debug — no ambiguity
- Cleaner syntax: Simpler one-liner
Issues Found
1. Low — Less flexible than #4843
Rejects FLASK_DEBUG=true, FLASK_DEBUG=yes, FLASK_DEBUG=on. This is arguably more secure (reduces misconfiguration surface) but may surprise users who set FLASK_DEBUG=true (common Docker/Heroku convention).
2. Info — Same host='0.0.0.0' concern as #4843
Both PRs still expose services on all interfaces. This is a separate issue.
Verdict: Approve
Both this and #4843 solve the same problem. #4859 is stricter, #4843 is more conventional. Coordinate merges — only one should be merged.
saim256
left a comment
There was a problem hiding this comment.
Requesting changes on current head ae797e8.
The runtime debug changes compile and the focused test passes locally, but the new regression test does not cover all of the entrypoints this PR modifies: bcos_directory.py is changed from debug=True to FLASK_DEBUG, but it is missing from affected_files in tests/test_flask_debug_security.py. That means a future reintroduction of app.run(debug=True, ...) in bcos_directory.py would not fail this new gate, even though the PR claims to prevent recurrence across the patched Flask entrypoints. Please add bcos_directory.py to the test's file list.
Also confirming the already-visible repository gate failure: the new tests/test_flask_debug_security.py file needs an SPDX header before merge.
Validation performed:
python -m pytest tests/test_flask_debug_security.py -q-> 1 passedpython -m py_compile bcos_directory.py bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py profile_badge_generator.py security_test_payment_widget.py xss_poc_templates.py tests/test_flask_debug_security.py-> passed, with a pre-existingkeeper_explorer.pySyntaxWarninggit diff --check origin/main...HEAD -- bcos_directory.py bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py profile_badge_generator.py security_test_payment_widget.py xss_poc_templates.py tests/test_flask_debug_security.py-> passedpython tools\bcos_spdx_check.py --base-ref origin/main-> failed: missing SPDX header intests/test_flask_debug_security.pyrgover the changed entrypoints found no remaining literalapp.run(... debug=True)after the patch
dazer1234
left a comment
There was a problem hiding this comment.
Code review for RustChain bounty #73.
Summary: This removes several public debug=True Flask entrypoints and adds a regression test for the touched files.
Findings:
- Low: FLASK_DEBUG is only enabled when the value is exactly "1". That is safe-by-default, but it may surprise operators who set the common Flask values "true", "yes", or "on". Consider either documenting the strict value or accepting the usual truthy set.
- Nit: The test is path-list based, so future entrypoints are not automatically covered. That is fine for this patch, but a repo-wide AST scan would be stronger.
Verdict: Good security improvement with minor config/documentation follow-up.
Reviewed with OpenAI Codex assistance.
508704820
left a comment
There was a problem hiding this comment.
Code Review — #4859
1. Same fix as #4843 but simpler env var check
This PR uses os.environ.get('FLASK_DEBUG') == '1' while #4843 uses a more comprehensive check against {1, true, yes, on}. Both achieve the same goal (disable debug by default).
2. Strict equality vs comprehensive check
Only accepting '1' is stricter (fewer false positives) but less user-friendly. A developer who sets FLASK_DEBUG=true would expect it to work. #4843's approach is better for developer experience.
3. Duplicate of #4843
This PR and #4843 fix the exact same files with the same approach. Only one should be merged. #4843 is the better version due to its more comprehensive env var parsing.
— Xeophon
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing. Approved.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing. Approved.
Code Review: Remove hardcoded debug=True in Flask entrypointsSummaryThis PR replaces hardcoded Positive Observations ✅
Issues Found 🔍1. Missing
|
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
Fixed hardcoded debug=True in multiple Flask entrypoints to prevent security exposure. Added a regression test in tests/test_flask_debug_security.py to ensure this doesn't recur. Part of the security hardening bounty.