Performance: Configuring allowed origins
MEDIUM IMPACT
This affects how the server handles cross-origin requests, impacting network latency and browser security checks.
const allowedOrigins = ['https://example.com', 'https://app.example.com']; app.use(cors({ origin: (origin, callback) => { if (!origin || allowedOrigins.includes(origin)) { callback(null, true); } else { callback(new Error('Not allowed by CORS')); } }}));
app.use(cors({ origin: '*' }));| Pattern | Network Requests | Preflight Requests | Security Risk | Verdict |
|---|---|---|---|---|
| Allow all origins (*) | High - all requests allowed | High - many preflights | High - security risk | [X] Bad |
| Allow specific origins | Low - only trusted domains | Low - fewer preflights | Low - secure | [OK] Good |