Skip to content

fix(explorer): tolerate malformed API env#7559

Open
yyswhsccc wants to merge 1 commit into
Scottcjn:mainfrom
yyswhsccc:codex/explorer-api-env-guard
Open

fix(explorer): tolerate malformed API env#7559
yyswhsccc wants to merge 1 commit into
Scottcjn:mainfrom
yyswhsccc:codex/explorer-api-env-guard

Conversation

@yyswhsccc

Copy link
Copy Markdown
Contributor

Problem

tools/explorer-api/api.py parsed EXPLORER_PORT, CACHE_TTL, and REQUEST_TIMEOUT directly at import time. A malformed deployment env value raises ValueError before the Explorer API can start.

Impact

A single bad numeric env value can crash the lightweight Explorer API during startup, making explorer endpoints unavailable until the environment is corrected.

Fix

Add small local _safe_int_env and _safe_float_env helpers that log malformed numeric env values and fall back to the existing defaults. Valid numeric env overrides are preserved.

Tests

  • uv run --no-project --with pytest --with flask --with flask-cors --with requests python -B -m pytest -q tests/test_explorer_api_query_validation.py -> 10 passed
  • python3 -m py_compile tools/explorer-api/api.py tests/test_explorer_api_query_validation.py -> passed
  • git diff --check -> passed

Boundaries

Related to the general bug bounty surface (#305). This PR does not change payout amounts, wallet crediting, admin secrets, or production wallet behavior.

wallet: RTC47bc28896a1a4bf240d1fd780f4559b242bcd945

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) api API endpoint related tests Test suite changes size/M PR: 51-200 lines labels Jun 23, 2026
@yyswhsccc

Copy link
Copy Markdown
Contributor Author

@Scottcjn Please take a look when you have a chance. This is a small startup hardening fix for the Explorer API: malformed numeric env values now fall back to existing defaults instead of crashing import/startup.

Validation:

  • uv run --no-project --with pytest --with flask --with flask-cors --with requests python -B -m pytest -q tests/test_explorer_api_query_validation.py -> 10 passed
  • python3 -m py_compile tools/explorer-api/api.py tests/test_explorer_api_query_validation.py -> passed
  • git diff --check -> passed

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified.

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified. Good work on the changes.

@jaxint

jaxint commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Good job! The changes look solid and well-tested.

Reviewed for Bounty #71
Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified. Per bounty #71.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants