RBAC Bypass Audit - Direct BigQuery Fetches
Critical Issues Found
1. CHURN Intent Handler - Direct BigQuery Call Without RBAC (CRITICAL)
Location:api/routes/ai_query.py lines 3579-3615
Problem:
get_agent_churn_intel():
2. COMPANY_LOST_BUSINESSES Intent - No RBAC Check (CRITICAL)
Location:api/routes/ai_query.py line 3553
Problem:
3. fetch_agent_data() - Many Functions Don’t Use authorized_agent_id
Location:api/routes/ai_query.py lines 781-1200
Functions that accept authorized_agent_id but don’t use it:
get_agent_portfolio_metrics()- Line 805get_agent_lifecycle_events()- Line 817get_agent_lost_businesses()- Line 829get_agent_business_summary()- Line 841get_agent_commission_with_authoritative_pepm()- Line 870get_agent_mom_comparison()- Line 897get_agent_churn_intel()- Line 932get_focus_accounts()- Line 952get_agent_commission_range()- Line 1105get_agent_commission_single_period()- Line 1124
authorized_agent_id:
get_agent_ytd_summary()- Line 884 ✅get_agent_qoq_comparison()- Line 911 ✅get_agent_commission_by_business()- Line 1136 ✅
4. fetch_business_data() - Agent Queries Pass None for authorized_agent_id
Location:api/routes/ai_query.py line 722
Problem:
5. Direct BigQuery Client Calls - Reverse Lookup (OK)
Location:api/routes/ai_query.py lines 3470-3489, 4377-4396
Status: ✅ These are reverse lookups (agent_id → agent_name) and use authorized_agent_id from RBAC check, so they’re safe.
Required Fixes
Priority 1: CHURN Intent Handler
Add RBAC enforcement before line 3600:Priority 2: Verify BigQuery Query Functions Use authorized_agent_id
Check if these functions inapi/bigquery/queries.py actually enforce RBAC:
get_agent_churn_intel()get_agent_portfolio_metrics()get_agent_lifecycle_events()get_agent_lost_businesses()get_agent_business_summary()get_agent_commission_with_authoritative_pepm()get_agent_mom_comparison()get_agent_commission_range()get_agent_commission_single_period()get_agent_report_from_view()get_agent_trends_from_view()
authorized_agent_id or agent_name that was already authorized.
Priority 3: COMPANY_LOST_BUSINESSES Intent
Verify this is CEO-level data and add role check if needed:Verification Checklist
- CHURN intent handler enforces RBAC before BigQuery call
- All
fetch_agent_data()calls passauthorized_agent_idwhen available - All BigQuery query functions that accept
authorized_agent_idactually use it - COMPANY_LOST_BUSINESSES intent has role check if needed
- No direct BigQuery calls bypass RBAC checks