fix(security): gate test-only /test/broadcast behind env flag (#753) - #833
Conversation
The /test/broadcast endpoint was mounted unconditionally with only require_auth, so any authenticated principal could push arbitrary JSON to every WebSocket subscriber. Register it only when CODEFRAME_ENABLE_TEST_ENDPOINTS is set (read once at import time), so the route is genuinely absent — not in OpenAPI, 404 on request — in production. Tests: auth_app fixture now enables the flag (existing requires-auth test unchanged); new test_test_broadcast_gated_off_without_flag asserts a valid authenticated principal gets 404 when the flag is unset.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 2 minutes Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Review (Claude)Small, well-scoped fix that does exactly what #753 and the PR description promise. This is the first substantive review on this PR (the only other comment is a rate-limited CodeRabbit stub with no actual findings). Correctness
Tests
Scope / architecture fit
Nits (non-blocking)
No blocking issues found. This looks ready to merge as-is. |
Review (Claude) — follow-upNo new commits since my prior review on this PR — the diff is unchanged (2 commits: the
No blocking issues. Standing assessment: ready to merge as-is. |
Summary
Closes #753. The test-only
POST /test/broadcastendpoint was mounted unconditionally with onlyrequire_auth. Any authenticated principal could push arbitrary JSON to every WebSocket subscriber — a low-severity but real authenticated-broadcast injection.This gates registration behind
CODEFRAME_ENABLE_TEST_ENDPOINTS, satisfying the acceptance criterion ("Registered only whenCODEFRAME_ENABLE_TEST_ENDPOINTSis set"). The flag is read once at import time, so when unset the route is genuinely absent — not in OpenAPI,404on request — rather than gated inside the handler body.Changes
codeframe/ui/server.py— wrap the/test/broadcastregistration inif os.getenv("CODEFRAME_ENABLE_TEST_ENDPOINTS").tests/ui/test_v2_auth_enforcement.py— extract fixture setup into_build_auth_app(..., enable_test_endpoints=);auth_appenables the flag (existingtest_test_broadcast_requires_authunchanged → still asserts 401), newauth_app_no_test_endpointsfixture leaves it unset.test_test_broadcast_gated_off_without_flag— a valid authenticated principal gets404when the flag is unset, directly proving the vulnerability is closed.Verification
uv run pytest tests/ui/test_v2_auth_enforcement.py→ 54 passeduv run ruff check→ clean;uv run --extra dev mypy codeframe/→ no issues (192 files)/test/broadcastregistered? False/test/broadcastregistered? TrueKnown Limitations
tests/ui/test_websocket_integration.py(fullyskipif(True)-skipped) launches a real subprocess server that hits/test/broadcast. When those tests are un-skipped, the subprocess must be launched withCODEFRAME_ENABLE_TEST_ENDPOINTS=1. Left untouched here since the suite does not run.Review note
Change is a ~3-line security gate plus tests, fully verified (tests/lint/mypy/demo). Review is Claude-internal (advisory);
/code-review ultraavailable as manual escalation.