Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Permissive CORS Policy Fix

Fixed a permissive CORS policy by restricting allowed origins to those specified in the `ALLOWED_ORIGINS` environment variable.

### Key Learnings
- Use the `cors` middleware with an `origin` whitelist instead of the default `*`.
- Robustly parse environment variables by splitting and trimming strings to avoid configuration errors.
- Default to a safe local development origin (e.g., `http://localhost:5173`) when the environment variable is not set.
- Avoid committing auto-generated lock files unless explicitly required, especially if they contain invalid or hallucinated dependency versions.
9 changes: 8 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ const app = express();
const PORT = process.env.PORT || 3000;

// Middleware
app.use(cors());
const allowedOrigins = process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',').map(origin => origin.trim()).filter(origin => origin.length > 0)
: ['http://localhost:5173'];

app.use(cors({
origin: allowedOrigins,
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CORS configuration is missing the credentials option. Since the application uses JWT tokens sent via Authorization headers and may use cookies in the future, you should add credentials: true to allow browsers to include credentials in cross-origin requests. Without this, authenticated requests from the frontend may fail when deployed to different domains.

Suggested change
origin: allowedOrigins,
origin: allowedOrigins,
credentials: true,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added credentials: true to the CORS configuration to support cookie-based authentication.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added credentials: true to the CORS configuration.

credentials: true,
}));
app.use(express.json());

// Routes
Expand Down