sonarjs/unverified-hostname
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/unverified-hostname": "error",
},
},
];Server hostnames should be verified during SSL/TLS connections
let options = {
hostname: 'www.example.com',
port: 443,
path: '/',
method: 'GET',
secureProtocol: 'TLSv1_2_method',
checkServerIdentity: function() {} // Noncompliant: hostname is not verified
};
let req = https.request(options, (res) => {
res.on('data', (d) => {
process.stdout.write(d);
});
}); // Noncompliantlet options = {
secureProtocol: 'TLSv1_2_method',
checkServerIdentity: function() {} // Noncompliant: hostname is not verified
};
let socket = tls.connect(443, "www.example.com", options, () => {
process.stdin.pipe(socket);
process.stdin.resume();
}); // Noncompliantlet socket = request.get({
url: 'https://www.example.com',
secureProtocol: 'TLSv1_2_method',
checkServerIdentity: function() {} // Noncompliant: hostname is not verified
});let options = {
hostname: 'www.example.com',
port: 443,
path: '/',
method: 'GET',
secureProtocol: 'TLSv1_2_method'
};
let req = https.request(options, (res) => {
res.on('data', (d) => {
process.stdout.write(d);
});
}); // Compliant: default checkServerIdentity function is securelet options = {
secureProtocol: 'TLSv1_2_method',
checkServerIdentity: (servername, peer) => {
if (servername !== "www.example.com") {
return new Error ('Error'); // Compliant: there is at least one check
}
}
};
let socket = tls.connect(443, "www.example.com", options, () => {
process.stdin.pipe(socket);
process.stdin.resume();
}); // Compliantlet socket = request.get({
url: 'https://www.example.com/',
secureProtocol: 'TLSv1_2_method' // Compliant
}); // Compliant: default checkServerIdentity function is secureExamples from the ESLint documentation.
sonarjs/unverified-hostname
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/unverified-hostname": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Server certificates should be verified during SSL/TLS connections
Names of regular expressions named groups should be used
Loop counters should not be assigned within the loop body