← Back to Pull requests

fix(csp): ensure Content Security Policy compliance for OAuth connect popup and callback flow #149

Closed
unknown closed this pull request without merging on Oct 28, 2026 05:22 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 17:29 UTC
Author

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).

  • fixes : #144
  • Problem


    1. Popup Opening in Full Tab: Under strict production CSP (script-src 'self'), inline onclick attributes are blocked by the browser. Clicking "Connect to VoxBento" or "Reconnect" failed to execute window.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_id or base_url was missing from Global Settings, VoxbentoOAuthConnectView issued a redirect to dashboard_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 onclick attributes from Connect and Reconnect buttons.
    - Added js-voxbento-popup class and declarative HTML data attributes (data-popup-width="600" data-popup-height="700").
    - Implemented a delegated click listener in dashboard.js using external JavaScript permitted under script-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') and window.opener.postMessage to 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 VoxbentoOAuthConnectView and VoxbentoOAuthCallbackView._popup_response to utilize the new CSP-safe templates.

    ---

    Key Changes


    | File | Changes |
    | :--- | :--- |
    | interpretation/templates/interpretation/overview.html | Removed inline onclick; added .js-voxbento-popup and popup dimension data attributes; cache-busted dashboard.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_response and connect view to render new templates. |
    | tests/test_authz.py | Added test cases verifying template rendering for callback and error flows. |

    ---

    Verification & Testing


  • Local CSP Simulation: Tested with DEBUG = False and 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.
  • Linter & Formatter:

  • - ruff check . passed with 0 errors.
    - ruff format --check . passed (all files formatted).
  • Unit Tests:

  • - 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:

  • Add CSP-compliant VoxBento OAuth popup and callback pages with external JavaScript and styling.

  • Bind OAuth attempts and token exchanges to the initiating event for safer authorization handling.
  • Bug Fixes:

  • Prevent OAuth connect and reconnect actions from opening full-page authorization flows when inline handlers are blocked by CSP.

  • Ensure OAuth callback windows communicate completion, close correctly, and provide a fallback for full-tab flows.

  • Show a dedicated configuration error page instead of embedding the dashboard in the OAuth popup.

  • Prevent overlapping OAuth attempts from overwriting each other and reject invalid, expired, or unauthorized callbacks.
  • Enhancements:

  • Normalize dashboard CSP configuration and move dashboard interaction logic out of inline scripts.

  • Improve OAuth error handling and preserve existing grants when token exchange fails.
  • Tests:

  • Add coverage for CSP headers, inline-script removal, popup error and callback rendering, concurrent OAuth attempts, and event-bound authorization validation.
  • <!-- 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 -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ArnavBallinCode Review duration: 713m
    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
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%