Skip to content

fix: fail closed webhook admin api#4895

Open
ethever wants to merge 1 commit into
Scottcjn:mainfrom
ethever:ethever/fix-webhook-admin-4785
Open

fix: fail closed webhook admin api#4895
ethever wants to merge 1 commit into
Scottcjn:mainfrom
ethever:ethever/fix-webhook-admin-4785

Conversation

@ethever
Copy link
Copy Markdown

@ethever ethever commented May 12, 2026

Summary

Validation

  • git diff --check origin/main...HEAD
  • python3 -m py_compile tools/webhooks/webhook_server.py tests/test_webhook_admin_auth.py
  • uv run --no-project --with pytest --with requests --with flask python -m pytest tests/test_webhook_admin_auth.py -q -> 3 passed
  • python3 tools/bcos_spdx_check.py --base-ref origin/main -> OK

Wallet/miner ID for bounty payout: b3a58f80a97bae5e2b438894aa85600cb0c066RTC

Tests use a local 127.0.0.1 HTTPServer and temporary SQLite database only; no external webhook target was contacted.

 - reject webhook admin routes when WEBHOOK_ADMIN_API_KEY is unset

 - keep health public and add admin auth regression coverage
@github-actions
Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Your PR has a BCOS-L1 or BCOS-L2 label
  • 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 size/M PR: 51-200 lines BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes labels May 12, 2026
@ethever
Copy link
Copy Markdown
Author

ethever commented May 12, 2026

Checklist note: I do not have permission to apply repository labels from this fork. This is a fail-closed security hardening fix for #4785; I would classify it as BCOS-L1 or BCOS-L2 depending on maintainer severity policy. Local validation and BCOS SPDX check are listed in the PR body.

Copy link
Copy Markdown

@lavishsaluja lavishsaluja left a comment

Choose a reason for hiding this comment

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

Approved current head 61686973c0d214a6c6c6c79767df4f7816e6bdba.

This is a focused fix for #4785. The webhook admin routes now fail closed with 503 when WEBHOOK_ADMIN_API_KEY is unset instead of treating missing configuration as successful authentication, while /health remains public for monitoring. With a configured key, unauthenticated admin writes still return 401 and a matching X-Admin-API-Key can subscribe normally.

Validation performed locally:

  • python -m pytest tests/test_webhook_admin_auth.py -q -> 3 passed
  • python -m py_compile tools/webhooks/webhook_server.py tests/test_webhook_admin_auth.py -> passed
  • git diff --check origin/main...codex-review-pr-4895 -> passed
  • python tools/bcos_spdx_check.py --base-ref origin/main -> OK

The tests use a local 127.0.0.1 HTTPServer and temporary SQLite database only. No external webhook target or production service was exercised. I do not see a blocker in this diff.

Copy link
Copy Markdown

@idan57570-art idan57570-art left a comment

Choose a reason for hiding this comment

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

Solid implementation. Looks good to me.

Copy link
Copy Markdown

@saim256 saim256 left a comment

Choose a reason for hiding this comment

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

Approved current head 61686973c0d214a6c6c6c79767df4f7816e6bdba.

This is a focused live-path fix for #4785. The webhook admin management routes now fail closed with 503 when WEBHOOK_ADMIN_API_KEY is unset, /health remains public, and configured-key behavior still rejects missing/wrong keys while allowing a matching X-Admin-API-Key.

Validation run locally:

  • python -m pytest tests\test_webhook_admin_auth.py -q -> 3 passed
  • python -m py_compile tools\webhooks\webhook_server.py tests\test_webhook_admin_auth.py -> passed
  • git diff --check origin/main...HEAD -> passed
  • python tools\bcos_spdx_check.py --base-ref origin/main -> OK
  • Manual local HTTPServer smoke with configured key and non-ASCII X-Admin-API-Key -> 401 response, not a server crash

The tests and smoke checks used only a local 127.0.0.1 HTTPServer and temporary/local subscriber storage; no external webhook target or production service was contacted.

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.

Code Review: Fail Closed Webhook Admin API

Summary

Fixes the webhook admin API to fail closed: when WEBHOOK_ADMIN_API_KEY is not configured, returns 503 (service unavailable) for all admin endpoints except /health which remains public.

What Works Well

  1. Fail-closed: Correct security posture — unconfigured = denied (not allowed)
  2. Health endpoint exemption: /health remains accessible without auth (for monitoring)
  3. 503 status code: "Service unavailable" — correct for "admin not configured"
  4. Test coverage: Verifies both admin rejection and health accessibility when key is unconfigured
  5. Fixes the vulnerability from my earlier review: This addresses the default-allow pattern

This is the correct fix pattern

This matches my recommendations on #4841, #4877, #4879. All admin APIs should fail closed when their key is not configured.

Verdict: Approve ✅

Correct fail-closed implementation. The health endpoint exemption is a thoughtful addition.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: ✅ Correct Pattern

Fail-closed on webhook admin API is the correct security posture. Webhook endpoints are high-value targets for SSRF and injection attacks.

Suggestions:

  1. Confirm the webhook signature verification happens before any processing.
  2. Document which IP ranges are allowed to call admin webhooks (if applicable).

Verdict: Approve.

Copy link
Copy Markdown

@loganoe loganoe left a comment

Choose a reason for hiding this comment

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

Reviewed the webhook admin fail-closed change. Admin routes now return 503 when no WEBHOOK_ADMIN_API_KEY is configured, configured deployments still require the header, and /health remains public for monitoring. The regression tests exercise the unconfigured, public health, and valid/invalid configured-key paths against a local HTTPServer.

Validation run locally:

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=. /tmp/rustchain-flask-venv/bin/python -m pytest -q tests/test_webhook_admin_auth.py
  • /tmp/rustchain-flask-venv/bin/python -m py_compile tools/webhooks/webhook_server.py tests/test_webhook_admin_auth.py

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix. Addresses the issue correctly.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix. Addresses the issue correctly.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

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) size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Webhook admin API fails open when admin key is unset

7 participants