-
Notifications
You must be signed in to change notification settings - Fork 4
Add CORS for authentication #1047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughCORS middleware is integrated into the server by adding the cors package as a dev dependency and configuring it during server initialization to permit cross-origin requests from http://localhost:5000. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
server/index.js (1)
13-13: Consider making the CORS origin configurable.The origin is hardcoded to
http://localhost:5000. While this works for the specific use case with Sofia, consider using an environment variable for better flexibility during development.Apply this diff to make the origin configurable:
- const cors = require('cors'); + const cors = require('cors'); + const corsOrigin = process.env.CORS_ORIGIN || 'http://localhost:5000'; const globSync = require('glob').sync; const mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); const proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map( require ); - app.use(cors({ origin: 'http://localhost:5000' })); + // Enable CORS for cross-origin authentication with Sofia + app.use(cors({ origin: corsOrigin }));Also applies to: 20-20
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (2)
package.json(1 hunks)server/index.js(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (2)
package.json (1)
43-43: No action required—cors version is current and secure.The specified version ^2.8.5 is the latest stable release on npm, and no known security vulnerabilities exist for this package. The dependency is appropriately configured.
server/index.js (1)
20-20: Verify Sofia's authentication integration pattern with your backend.The codebase analysis shows Sofia as an external service (linked in the UI and configurable via environment variables), but contains no evidence of credentialed HTTP communication between Sofia and this server. Specifically:
- No
credentialsorwithCredentialsusage found in the codebase- No authentication middleware or endpoints handling Sofia requests
- CORS origin is already correctly set to a specific origin (
'http://localhost:5000'), not'*'The suggested
credentials: trueflag is only necessary if Sofia (or requests from Sofia) actually send credentials (cookies, auth headers). If this authentication pattern exists in your backend services (outside this frontend codebase) or is a new requirement from the PR, then the suggestion is valid. Otherwise, it may be unnecessary.Confirm whether:
- Sofia makes HTTP requests to this server with credentials
- Your backend sets cookies intended for Sofia
- This is a new requirement for the PR
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## staging #1047 +/- ##
===========================================
- Coverage 13.07% 13.05% -0.02%
===========================================
Files 450 450
Lines 3113 3117 +4
===========================================
Hits 407 407
- Misses 2706 2710 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
We need CORS on amber-ui for proper authentication with Sofia.
This was not needed in the past because we did not use a proper AJAX request
https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS
Summary by CodeRabbit