Added firebase in Content Security Policy and implemented firestore transport fallback - #33
Merged
Merged
Conversation
…ransport fallback
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The CSP change is overly permissive (*.googleapis.com) and should be tightened or environment-gated to preserve CSP’s security value.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates the Next.js app’s security headers and Firestore client initialization to prevent CSP-blocked Firebase/Firestore network requests and to improve resilience/observability of realtime listeners.
Changes:
- Expanded
connect-srcCSP allowlist to include Firebase/Firestore/Google APIs and Analytics endpoints. - Switched Firestore initialization to
initializeFirestorewith long-polling auto-detection enabled. - Added explicit
onSnapshoterror callbacks for message/conversation/chat listeners.
File summaries
| File | Description |
|---|---|
| next.config.mjs | Expands CSP connect-src to allow Firebase/Firestore/Google APIs/Analytics network calls. |
| lib/firebase.ts | Initializes Firestore via initializeFirestore with long-polling fallback enabled. |
| hooks/useMessages.tsx | Adds onSnapshot error callback for message listener. |
| hooks/useConversations.tsx | Adds onSnapshot error callback for conversations listener. |
| hooks/useChat.tsx | Adds onSnapshot error callback for chat message listener. |
Review details
Suppressed comments (3)
hooks/useMessages.tsx:32
- This listener error log lacks the
conversationId, making it harder to diagnose which subscription failed when multiple conversations are active.
console.error("Unable to listen for messages", error);
hooks/useConversations.tsx:33
- This listener error log lacks the
userId, which makes it difficult to identify which user’s conversation list subscription failed in logs.
console.error("Unable to listen for conversations", error);
hooks/useChat.tsx:32
- This listener error log lacks the
conversationId, which makes it hard to trace failures when multiple chat listeners are active.
console.error("Unable to listen for chat messages", error);
- Files reviewed: 5/5 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| { | ||
| key: 'Content-Security-Policy', | ||
| value: "default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://challenges.cloudflare.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://getlancer.1a3c2f86a3386038e3a37e793a2777b5.r2.cloudflarestorage.com; font-src 'self' data:; connect-src 'self' https://challenges.cloudflare.com; frame-src 'self' https://challenges.cloudflare.com; object-src 'none'; base-uri 'self';", | ||
| value: "default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://challenges.cloudflare.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://getlancer.1a3c2f86a3386038e3a37e793a2777b5.r2.cloudflarestorage.com; font-src 'self' data:; connect-src 'self' https://challenges.cloudflare.com https://firestore.googleapis.com https://*.googleapis.com https://*.firebaseio.com https://*.firebaseapp.com https://www.google-analytics.com https://region1.google-analytics.com https://analytics.google.com https://firebaselogging.googleapis.com; frame-src 'self' https://challenges.cloudflare.com; object-src 'none'; base-uri 'self';", |
Comment on lines
+31
to
+34
| (error) => { | ||
| console.error("Unable to listen for chat messages", error); | ||
| } | ||
| ); |
Comment on lines
+32
to
+35
| (error) => { | ||
| console.error("Unable to listen for conversations", error); | ||
| } | ||
| ); |
Comment on lines
+31
to
+34
| (error) => { | ||
| console.error("Unable to listen for messages", error); | ||
| } | ||
| ); |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
next.config.js blocked Firebase in the Content Security Policy. Firestore requests were rejected by the browser, causing TypeError: Failed to fetch.
Changes