Uh oh!
There was an error while loading. Please reload this page.
fix(security): gate /api/gemini-test behind require_admin (#198) - #219
Conversation
The endpoint made a real, billable call_gemini round-trip on every hit with
no auth, so anonymous callers could burn Gemini quota and use the {"ok": ...}
response as an oracle for whether the API key is configured. Gate it behind
require_admin so only admins can trigger LLM spend.
Adds a regression test: an unauthenticated GET returns 401 and never reaches
call_gemini (fails on pre-fix code, which returned 200).Deploying with |
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs | frontend | f4344b9 | Commit Preview URL Branch Preview URL | Jun 13 2026, 03:40 AM |
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesAdmin-gated Gemini endpoint
Sequence DiagramsequenceDiagram
participant AnonymousClient
participant AdminClient
participant Handler as /api/gemini-test Handler
participant Auth as require_admin
participant Gemini as call_gemini
AnonymousClient->>Handler: GET /api/gemini-test
Handler->>Auth: require_admin(request)
Auth-->>Handler: 401 Unauthorized
Handler-->>AnonymousClient: {"error": "Unauthorized"}
AdminClient->>Handler: GET /api/gemini-test (authenticated)
Handler->>Auth: require_admin(request)
Auth-->>Handler: allowed
Handler->>Gemini: call_gemini()
Gemini-->>Handler: "Gemini response"
Handler-->>AdminClient: {"ok": true, "reply": "Gemini response"}
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes#198.
Problem
GET /api/gemini-testhad no auth and made a real, billablecall_gemini(...)round-trip on every hit. Anonymous callers could burn Gemini quota at will and use the{"ok": ...}response as an oracle for whether the API key is configured/valid — a debug endpoint left wired into the production app.Fix
Gate the endpoint behind
require_admin(the existing guard inservices/auth_guard.py). Anonymous → 401, non-admin → 403, admin → reaches the connectivity check. Kept (rather than removed) so operators retain a deliberate, auth-gated Gemini probe;/api/healthremains the unauthenticated liveness check.Test (vuln-closing)
tests/test_gemini_test_auth.py:test_unauthenticated_returns_401_and_makes_no_llm_call— restores the real auth guard (undoing conftest's autouse bypass) and asserts an anonymous GET returns 401 andcall_geminiis never called. Fails on pre-fix code (returned 200 + a live LLM call); passes post-fix.test_admin_reaches_handler— admin-equivalent request reaches the handler (LLM mocked).Scope
One file + one test. No behavior change for authenticated admins.
Summary by CodeRabbit
Bug Fixes
Tests