fix(csp): ensure Content Security Policy compliance for OAuth connect popup and callback flow #149
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #149"
general
weight: 0.35
ArnavBallinCode
Description
This PR resolves Content Security Policy (CSP) violations and user experience issues in the VoxBento OAuth integration flow on production environments (
DEBUG=False, e.g.,dev.eventyay.com).Problem
1. Popup Opening in Full Tab: Under strict production CSP (
script-src 'self'), inlineonclickattributes are blocked by the browser. Clicking "Connect to VoxBento" or "Reconnect" failed to executewindow.open/return false;, causing the browser to fall back to native<a target="voxbento_oauth">navigation and open the authorization screen in a full browser tab rather than a 600×700 popup.2. Blank White Callback Screen: Upon completing OAuth consent, the callback view previously served an inline
<script>snippet (window.opener.postMessage(...); window.close();). Because inline scripts are blocked under production CSP, the script was never executed, leaving users stuck on an empty white window that never closed.3. App-in-Popup Nesting on Misconfiguration: If
voxbento_client_idorbase_urlwas missing from Global Settings,VoxbentoOAuthConnectViewissued a redirect todashboard_url, causing the entire Eventyay application interface to embed and render inside the 600×700 popup window.---
Solution
1. Zero-Inline Script Popup Handler (
overview.html&dashboard.js):- Removed all inline
onclickattributes from Connect and Reconnect buttons.- Added
js-voxbento-popupclass and declarative HTML data attributes (data-popup-width="600" data-popup-height="700").- Implemented a delegated click listener in
dashboard.jsusing external JavaScript permitted underscript-src 'self'.2. CSP-Compliant Callback View (
oauth_callback.html&oauth_callback.js):- Replaced raw inline HTML string responses with a dedicated template and external static asset (
oauth_callback.js).- Uses
BroadcastChannel('voxbento_oauth')andwindow.opener.postMessageto communicate authorization state back to the parent dashboard.- Automatically closes popup windows or redirects full-tab fallbacks without inline script execution.
3. Dedicated OAuth Error Page (
oauth_error.html):- Renders a clean error page directly inside the popup when OAuth configuration is incomplete, preventing recursive redirects that embedded Eventyay inside itself.
4. View Refactoring (
views_oauth.py):- Updated
VoxbentoOAuthConnectViewandVoxbentoOAuthCallbackView._popup_responseto utilize the new CSP-safe templates.---
Key Changes
| File | Changes |
| :--- | :--- |
|
interpretation/templates/interpretation/overview.html| Removed inlineonclick; added.js-voxbento-popupand popup dimension data attributes; cache-busteddashboard.js. ||
interpretation/static/interpretation/js/dashboard.js| Added capture-phase delegated event listener for popup links and BroadcastChannel message listener. ||
interpretation/templates/interpretation/oauth_callback.html| New CSP-compliant template for OAuth callback handoff. ||
interpretation/static/interpretation/js/oauth_callback.js| External script to post message, broadcast channel update, and close popup. ||
interpretation/templates/interpretation/oauth_error.html| New standalone error template rendered inside popups on configuration failure. ||
interpretation/views_oauth.py| Updated_popup_responseand connect view to render new templates. ||
tests/test_authz.py| Added test cases verifying template rendering for callback and error flows. |---
Verification & Testing
DEBUG = Falseand production CSP header (default-src 'self'; script-src 'self' ...without'unsafe-inline').- Verified the popup opens in a 600×700 window.
- Verified OAuth authorization completes, posts message, closes popup, and parent dashboard auto-refreshes.
- Verified no CSP violation warnings appear in the browser console.
-
ruff check .passed with 0 errors.-
ruff format --check .passed (all files formatted).-
pytest tests/passed: 82 passed, 0 failed.Summary by Sourcery
Make the VoxBento OAuth flow CSP-compliant, event-bound, and resilient across popup and full-page authorization scenarios.
New Features:
Bug Fixes:
Enhancements:
Tests:
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
VoxBento connection and reconnection open in a popup, with clear success or error messages and options to close the window or return to the dashboard.
OAuth completion refreshes the dashboard. Dashboard links can open the Rooms tab and expand and scroll to a specified room.
Bug Fixes
The dashboard warns when VoxBento is not configured, and connection setup errors provide a route back to the dashboard.
If a connection popup cannot be opened, the link continues in the current window.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->