Skip to content

fix: disable public Flask debug defaults#5474

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
RYB-404:fix/public-flask-debug-4810
May 18, 2026
Merged

fix: disable public Flask debug defaults#5474
Scottcjn merged 2 commits into
Scottcjn:mainfrom
RYB-404:fix/public-flask-debug-4810

Conversation

@RYB-404
Copy link
Copy Markdown

@RYB-404 RYB-404 commented May 16, 2026

Summary

Changed entrypoints

  • bridge/bridge_api.py -> BRIDGE_API_DEBUG
  • contributor_registry.py -> CONTRIBUTOR_REGISTRY_DEBUG
  • explorer/app.py -> RUSTCHAIN_EXPLORER_DEBUG
  • keeper_explorer.py -> KEEPER_EXPLORER_DEBUG
  • security_test_payment_widget.py -> SECURITY_TEST_WIDGET_DEBUG

Validation

  • python -m py_compile bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py
  • direct AST regression test invocation -> passed
  • uv run --no-project --with pytest --with flask --with flask-cors --with requests python -m pytest tests/test_public_flask_debug_defaults.py -q -> 1 passed

Payout address can be provided if/when this is accepted for the RTC bounty.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

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!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) security Security-related change tests Test suite changes size/M PR: 51-200 lines labels May 16, 2026
Copy link
Copy Markdown

@ZacharyZhang-NY ZacharyZhang-NY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed PR #5474 at 92e7c9e.

Validation performed on Windows Python 3.12:

  • python -m py_compile bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py passed. Existing keeper_explorer.py emitted the current invalid-escape SyntaxWarning, but compilation completed.
  • python -m pytest tests/test_public_flask_debug_defaults.py -q passed with 1 passed, 1 warning in 0.07s.
  • git diff --check origin/main...HEAD passed.
  • Static scan confirmed the affected public entrypoints now pass env-controlled debug values instead of literal debug=True on 0.0.0.0 binds.

The change matches #4810's intent: debug mode is off by default for public-facing helper services, while local development can opt in per service through explicit environment flags. I did not find a blocking issue.

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@kekehanshujun kekehanshujun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I verified the public Flask entrypoints covered by #4810 no longer pass a literal debug=True for 0.0.0.0 binds, and the new AST regression test catches that pattern.

Validation run on the PR diff:

  • python -m py_compile bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py
  • python -m pytest tests/test_public_flask_debug_defaults.py -q --tb=short -> 1 passed, with the existing keeper_explorer.py invalid-escape warning
  • git diff --check -- bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py

No blocking issues found.

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing. Approved.

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown

@TJCurnutte TJCurnutte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I focused on the public Flask entrypoint debug defaults and the regression test that prevents reintroducing debug=True on 0.0.0.0 servers.

Validation I ran against head 92e7c9ed94e3ad9b4b9e41e05715f3f0a07da760:

git diff --check origin/main...HEAD -- bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py
python3 -B -m py_compile bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py
uv run --no-project --with pytest python -B -m pytest -q tests/test_public_flask_debug_defaults.py --noconftest

The focused pytest passed with 1 passed, 1 warning in 0.04s (keeper_explorer.py already has an invalid-escape deprecation warning unrelated to this change).

I also ran an AST probe over the modified entrypoints and confirmed the app.run(..., debug=...) arguments now route through opt-in helpers instead of a literal True: bridge/bridge_api.py uses _debug_enabled(), and contributor_registry.py, explorer/app.py, keeper_explorer.py, and security_test_payment_widget.py use debug_enabled().

That preserves a deliberate local-debug escape hatch through environment variables while making the public/default launch path fail closed.

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown

@ZacharyZhang-NY ZacharyZhang-NY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed PR #5474 at head 92e7c9e.

Validation performed:

  • Checked issue #4810. The scoped security bug is public Flask entrypoints binding to 0.0.0.0 while hard-coding debug=True by default.
  • git fetch origin pull/5474/head:review-pr-5474 --force
  • git diff --check origin/main...review-pr-5474 -- bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py -> passed.
  • python -m py_compile bridge/bridge_api.py contributor_registry.py explorer/app.py keeper_explorer.py security_test_payment_widget.py tests/test_public_flask_debug_defaults.py on an extracted PR-head tree -> passed.
  • python -m pytest tests/test_public_flask_debug_defaults.py -q --confcutdir= -> 1 passed.
  • Probed the five new debug helpers with lightweight dependency stubs: BRIDGE_API_DEBUG, CONTRIBUTOR_REGISTRY_DEBUG, RUSTCHAIN_EXPLORER_DEBUG, KEEPER_EXPLORER_DEBUG, and SECURITY_TEST_WIDGET_DEBUG all default to False and return True for true.

The public Flask entrypoints now require explicit per-service env opt-in for debug mode, and the AST regression covers the listed public binds. Approving.

@BossChaos
Copy link
Copy Markdown
Contributor

Code Review — Bounty #73

PR: fix: disable public Flask debug defaults by @RYB-404
Files changed: 6 (+76/-5)

  • ✅ Bug fix or input validation

Summary

This is a bug fix PR. Changes appear consistent with project patterns.

Wallet: 0xdaE5d307339074A24F579dB48e7c639359D94904

Reviewing under Bounty #73 — Code Review Bounty Program

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@508704820 508704820 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable public Flask debug defaults. CRITICAL - public debug defaults expose interactive debugger and source code. This is the second Flask debug fix (also #5531). Verify ALL Flask app instances have debug disabled, not just the main one. Consider adding a CI assertion. - Xeophon (security review)

Copy link
Copy Markdown
Contributor

@508704820 508704820 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flask debug defaults fix. SECURITY: Critical hardening — debug=True on 0.0.0.0 exposes Werkzeug debugger, allows arbitrary code execution. The AST regression test is excellent prevention. Reviewed by: Xeophon (security specialist). Recommendation: MERGE — this is a real attack vector.

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@508704820
Copy link
Copy Markdown
Contributor

Security Review ✅

Flask debug mode gated behind explicit per-service env flags instead of defaulting to Werkzeug debug on 0.0.0.0. AST regression test ensures no hardcoded debug defaults. Same class as #5531 and #5488 but covers remaining services.

Reviewed by Xeophon - Solana: Lt9nERv6VHsojw15LpFeiaabuphAggzfLF9sM9UXRrZ

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work on this PR. 🚀

…g-4810

# Conflicts:
#	bridge/bridge_api.py
#	explorer/app.py
@guangningsun
Copy link
Copy Markdown
Contributor

PR Review — PR #5474

Title: fix: disable public Flask debug defaults

Author: RYB-404

What I reviewed

  • bridge/bridge_api.py
  • contributor_registry.py
  • explorer/app.py

Observations

  1. Similar to PR fix: disable public Flask debug entrypoints #5561 — adds debug mode environment variable checks instead of hardcoding debug=True.
  2. Adds _debug_enabled() / debug_enabled() helper functions that check BRIDGE_API_DEBUG / CONTRIBUTOR_REGISTRY_DEBUG environment variables.
  3. Changes: bridge_api.py +5/-1, contributor_registry.py +7/-1, explorer/app.py +8/-1.
  4. This is a cleaner approach than PR fix: disable public Flask debug entrypoints #5561 — it allows debug mode to be enabled via environment variable when needed, without exposing debug on public servers.

LGTM pending CI. Better approach than PR #5561 — the environment variable pattern allows controlled debug access without hardcoded defaults.

Bounty: #2782
Disclosure: I received RTC compensation for this review.

@Scottcjn Scottcjn merged commit a8c1a39 into Scottcjn:main May 18, 2026
10 of 11 checks passed
@RYB-404
Copy link
Copy Markdown
Author

RYB-404 commented May 19, 2026

Hi @Scottcjn, thanks for merging this PR.

I noticed the award-rtc workflow failed after merge. Could you please check whether the RTC award needs a manual retry or manual payout?

PR: #5474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) security Security-related change size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Public Flask entrypoints enable debug mode by default

10 participants