Fixes CSP for Nango#2907
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
TL;DR — Nango uses WebSocket connections at runtime, but the Content Security Policy's Key changes
Summary | 1 file | 1 commit | base:
The helper is defensive — it returns
|
There was a problem hiding this comment.
Clean, correct fix. toWebSocketOrigin properly maps https: → wss: and http: → ws: using URL constructor, handles null/invalid inputs gracefully, and URL.origin returns the expected value for WebSocket protocols. No issues found.
Claude Opus | 𝕏
There was a problem hiding this comment.
PR Review Summary
(0) Total Issues | Risk: Low
This PR adds WebSocket protocol support to the CSP (Content Security Policy) for Nango connections. The change is minimal, well-implemented, and follows existing patterns in the codebase.
What Changed
A new helper function toWebSocketOrigin() converts HTTP/HTTPS URLs to their WebSocket equivalents (WS/WSS), which is then used to add the Nango server's WebSocket origin to the CSP connect-src directive. This allows WebSocket connections to Nango to pass CSP validation.
Review Coverage
| Reviewer | Returned | Main Findings | Consider | Discarded |
|---|---|---|---|---|
pr-review-standards |
0 | 0 | 0 | 0 |
pr-review-appsec |
0 | 0 | 0 | 0 |
| Total | 0 | 0 | 0 | 0 |
Analysis
Code Quality ✅
- The
toWebSocketOriginfunction is well-implemented with proper null/undefined handling - Uses
URLconstructor for safe parsing with appropriate try/catch - Returns
.origin(not full URL) which is correct for CSP sources - Only converts known protocols (http → ws, https → wss)
Security ✅
- CSP modification is secure — values come from environment variables, not user input
- Follows existing patterns for other CSP sources in the file
- Fail-safe behavior (returns null on errors, which is filtered out)
Consistency ✅
- Follows existing helper function patterns in the file
- Uses the same
filter(Boolean)pattern for CSP array construction
✅ APPROVE
Summary: Clean, minimal fix that correctly adds WebSocket origin support for Nango to the CSP. The implementation is secure, well-tested against edge cases, and follows existing codebase patterns. Ship it! 🚀
Ito Test Report ✅12 test cases ran. 12 passed. All 12 test cases passed, confirming expected behavior across auth boundaries, CSP/security headers, provider navigation/setup resilience, mobile usability, adversarial security checks, and OAuth callback handling in non-cloud mode. Key findings were that protected and public routes (including 307 redirects) consistently carried required CSP/X-Frame-Options/X-Content-Type-Options headers with Nango HTTP and WebSocket origins, unauthenticated deep-links correctly redirected to /login with returnUrl preservation, invalid provider links safely recovered without crashes while back/forward/refresh and rapid-click stress remained responsive, websocket egress to ws://evil.invalid/ws was blocked by CSP, and /oauth/callback could not be coerced into an open redirect (returning 404 JSON with no Location), with provider-flow checks executed via deterministic local fallback when Nango was unavailable. ✅ Passed (12)Commit: Tell us how we did: Give Ito Feedback |
No description provided.