sonarjs/post-message
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/post-message": "error",
},
},
];Origins should be verified during cross-origin communications
var iframe = document.getElementById("testiframe");
iframe.contentWindow.postMessage("secret", "*"); // Noncompliant: * is usedwindow.addEventListener("message", function(event) { // Noncompliant: no checks are done on the origin property.
console.log(event.data);
});var iframe = document.getElementById("testsecureiframe");
iframe.contentWindow.postMessage("hello", "https://secure.example.com"); // Compliantwindow.addEventListener("message", function(event) {
if (event.origin !== "http://example.org") // Compliant
return;
console.log(event.data)
});Examples from the ESLint documentation.
sonarjs/post-message
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/post-message": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Similar tests should be grouped in a single Parameterized test
"<object>" tags should provide an alternative content
Properties of variables with "null" or "undefined" values should not be accessed
Native APIs should be preferred over Axios utility methods