sonarjs/cors
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/cors": "error",
},
},
];Cross-Origin Resource Sharing (CORS) policy should be restricted to trusted origins
The documentation shows no incorrect example for this rule.
const http = require('http');
const srv = http.createServer((req, res) => {
res.writeHead(200, { 'Access-Control-Allow-Origin': 'trustedwebsite.com' }); // Compliant
res.end('ok');
});
srv.listen(3000);const cors = require('cors');
let corsOptions = {
origin: 'trustedwebsite.com' // Compliant
};
let app = express();
app.use(cors(corsOptions));function (req, res) {
const origin = req.header('Origin');
if (trustedOrigins.indexOf(origin) >= 0) {
res.setHeader('Access-Control-Allow-Origin', origin);
}
};Examples from the ESLint documentation.
sonarjs/cors
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/cors": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Content security policy fetch directives should not be disabled
Strict equality operators should not be used with dissimilar types