Security plugins in one flat config
One eslint.config.js that runs eslint-plugin-security, no-unsanitized and the Interlace security plugins together on ESLint 9 and 10, with overlapping rules turned off.
To run eslint-plugin-security, eslint-plugin-no-unsanitized and the Interlace security plugins in one flat config, scope each preset to the files it fits with files, then turn off the eslint-plugin-security rules that another preset already reports. The file below does both. Edit the three glob constants at the top to match your folders.
Covers ESLint 9 and 10 (flat config). Last updated 2026-11-19. ESLint 8 is out of scope because eslint-plugin-no-unsanitized 4.x requires ESLint 9 or later. The Interlace plugins (ours) need Node 22.13 or later.
import security from 'eslint-plugin-security';
import noUnsanitized from 'eslint-plugin-no-unsanitized';
import browserSecurity from 'eslint-plugin-browser-security';
import nodeSecurity from 'eslint-plugin-node-security';
import secureCoding from 'eslint-plugin-secure-coding';
const client = ['src/client/**/*.{js,jsx,ts,tsx}'];
const server = ['src/server/**/*.{js,ts}'];
const tests = ['**/*.{test,spec}.{js,jsx,ts,tsx}'];
// Apply a preset to some files, and keep it off test files.
const scope = (config, files, extra = {}) => ({
...config,
files,
ignores: tests,
...extra,
});
export default [
// Browser code
scope(browserSecurity.configs.recommended, client),
scope(noUnsanitized.configs.recommended, client, {
rules: {
// browser-security/no-innerhtml already reports these sinks.
'no-unsanitized/property': 'off',
// Keep only the two sinks browser-security does not cover.
'no-unsanitized/method': [
'error',
{ defaultDisable: true },
{ import: { properties: [0] }, setHTMLUnsafe: { properties: [0] } },
],
},
}),
// Node code
scope(security.configs.recommended, server),
scope(nodeSecurity.configs.recommended, server),
// Both
scope(secureCoding.configs.recommended, [...client, ...server]),
// Overlaps. This block must come after the presets it edits.
{
files: server,
ignores: tests,
rules: {
// Each of these is also reported by a node-security or secure-coding rule.
'security/detect-eval-with-expression': 'off',
'security/detect-child-process': 'off',
'security/detect-non-literal-require': 'off',
'security/detect-new-buffer': 'off',
'security/detect-unsafe-regex': 'off',
'security/detect-possible-timing-attacks': 'off',
'node-security/no-timing-unsafe-compare': [
'warn',
{ reportLiteralComparands: true },
],
// eslint-plugin-security reports every non-literal here; these two
// report a subset of the same call sites.
'secure-coding/no-unsafe-regex-construction': 'off',
'node-security/detect-non-literal-fs-filename': 'off',
},
},
{
files: [...client, ...server],
ignores: tests,
rules: {
// The rule's default list minus eval(): eval is already reported by
// browser-security/no-eval and node-security/detect-eval-with-expression.
'secure-coding/no-unsafe-deserialization': [
'warn',
{
dangerousFunctions: [
'Function',
'setTimeout',
'setInterval',
'unserialize',
'deserialize',
'parseUnsafe',
],
},
],
},
},
];npm install --save-dev eslint-plugin-security eslint-plugin-no-unsanitized \
eslint-plugin-browser-security eslint-plugin-node-security eslint-plugin-secure-codingTypeScript files need a parser (typescript-eslint) configured before these objects. This file was run on .js samples only.
What was run
On 2026-11-19 this file was run on ESLint 9.39.4 and 10.15.0 with eslint-plugin-security 4.2.1, eslint-plugin-no-unsanitized 4.1.5, eslint-plugin-browser-security 3.0.2, eslint-plugin-node-security 6.0.4 and eslint-plugin-secure-coding 6.1.1. The latest npm versions of our three are 3.1.0, 6.0.6 and 6.1.2; the run has not been repeated on them. Both ESLint versions gave identical results.
The test input was three small files written to contain one statement per overlapping rule, not real code; two more small files checked the timing and eval rows. With the five recommended presets applied to every file and nothing turned off, they produced 44 messages. With the file above, they produced 25. That count says the config removes repeats on constructed input. It says nothing about the number of findings or the precision on your repository, which we have not measured on real projects.
Which rules to turn off, and why
eslint-plugin-security's rules and ours are separate rules with separate names, so ESLint reports each one. When two of them match the same call you get two messages on one line. The table lists what was observed in the 44-message run, and what the config does.
| Code | Rules that reported it with nothing turned off | What the config does |
|---|---|---|
eval(req.body.code) in server code | security/detect-eval-with-expression, browser-security/no-eval, node-security/detect-eval-with-expression, secure-coding/no-unsafe-deserialization | Turns off the security rule, runs browser-security only on client globs, drops eval from the secure-coding list |
exec('ls ' + req.query.dir) | security/detect-child-process, node-security/detect-child-process, node-security/no-shell-injection | Turns off the security rule |
require(req.query.name) | security/detect-non-literal-require, node-security/no-unsafe-dynamic-require | Turns off the security rule |
token === req.query.token | security/detect-possible-timing-attacks, node-security/no-timing-unsafe-compare, and browser-security/no-client-side-auth-logic | Turns off the security rule; scoping keeps the browser rule off server code |
new Buffer(req.query.size) | security/detect-new-buffer, node-security/no-deprecated-buffer, node-security/no-unsafe-buffer-alloc, secure-coding/no-unlimited-resource-allocation | Turns off the security rule |
/(a+)+$/ | security/detect-unsafe-regex, secure-coding/no-redos-vulnerable-regex | Turns off the security rule |
new RegExp(req.query.pattern) | security/detect-non-literal-regexp, secure-coding/no-unsafe-regex-construction | Turns off the secure-coding rule |
fs.readFileSync(req.query.file) | security/detect-non-literal-fs-filename, node-security/detect-non-literal-fs-filename, node-security/no-arbitrary-file-access, secure-coding/no-unlimited-resource-allocation | Turns off the node-security filename rule |
el.innerHTML = userInput in browser code | no-unsanitized/property, browser-security/no-innerhtml | Turns off no-unsanitized/property, limits no-unsanitized/method to import() and setHTMLUnsafe |
The reasons, one per choice:
- Same pattern, a rule in our plugin reports it. For the first six rows the other rule reports the same call, so one owner is enough. The config keeps ours because
eslint-plugin-security's preset sets all fifteen rules towarn, while five of these six areerrorin ours. The choice is open: you can turn off thenode-securityorsecure-codingside instead and keepsecurity. What matters is that exactly one side is on. - Timing comparison. By default
node-security/no-timing-unsafe-compareskips a comparison against a string literal, whichsecurity/detect-possible-timing-attacksreports. WithoutreportLiteralComparands: true, turning off thesecurityrule losttoken === 'abc123'in our test. The option is documented on the rule page and the test above confirms it. - Non-literal
RegExpandfspaths. Hereeslint-plugin-securityreports every non-literal argument, including a bare function parameter.secure-coding/no-unsafe-regex-constructionandnode-security/detect-non-literal-fs-filenamereport only values they can trace to a request, so they never reported somethingsecuritymissed. We turned off the narrower side. If you want CWE-tagged messages instead of coverage of bare parameters, reverse that: turn off the twosecurityrules and accept that bare parameters go unreported. - DOM sinks. The two DOM plugins report the same
innerHTML,outerHTML,insertAdjacentHTML,document.writeandcreateContextualFragmentstatements. See Detect XSS with ESLint flat config for the per-sink table and thedefaultDisablespelling. evalandsecure-coding/no-unsafe-deserialization. That rule's default list includeseval, which made a fourth report on the same line. SettingdangerousFunctionsreplaces the default list, so the config lists the defaults excepteval. DroppingFunction,setTimeoutandsetIntervalas well removed coverage of string-argumentsetTimeoutin server files in our test, so they stay.
Rules left on because the test input showed no overlap: security/detect-non-literal-fs-filename and security/detect-non-literal-regexp on bare parameters, security/detect-object-injection, detect-buffer-noassert, detect-pseudoRandomBytes, detect-no-csrf-before-method-override, and the three character and escaping rules (detect-bidi-characters, detect-invisible-characters, detect-disable-mustache-escape). The test input did not contain a statement for every one of them. detect-object-injection reports every obj[key] access it cannot prove safe. Whether to turn it off is a question about your code. Add 'security/detect-object-injection': 'off' to the overlap block to do so; secure-coding/detect-object-injection is not in recommended.
Rule pages: detect-eval-with-expression, detect-child-process, no-unsafe-dynamic-require, no-timing-unsafe-compare, no-deprecated-buffer, detect-non-literal-fs-filename, no-redos-vulnerable-regex, no-unsafe-regex-construction and no-eval.
Repeats that remain
The file does not reach one message per line. In the 25-message run, these remain:
exec(...):node-security/detect-child-processandnode-security/no-shell-injection, both ours.new Buffer(n):no-deprecated-buffer,no-unsafe-buffer-allocandsecure-coding/no-unlimited-resource-allocation. The third is a different concern (resource use).fs.readFileSync(req.query.file):security/detect-non-literal-fs-filename,node-security/no-arbitrary-file-accessandsecure-coding/no-unlimited-resource-allocation.new Function(x)andsetTimeoutwith a string:browser-security/no-evalon client files, ornode-security/detect-eval-with-expressionon server files, plussecure-coding/no-unsafe-deserialization. The rule'sdangerousFunctionslist did not stop it reportingnew Function.- A
messagehandler that writese.datatoinnerHTML:require-postmessage-origin-checkandno-postmessage-innerhtml. These ask different questions, about the sender and about the sink.
browser-security/no-eval has a deferDynamicPayloads option meant for the case where both it and node-security run on the same files. We did not use it because the globs keep them on different files.
Scope rules to file globs
A flat config is a list. Each object applies to the files its files globs match, or to every file when it has none, and later objects override earlier ones. Three consequences:
- Put each preset on the code it was written for.
browser-securityrules assume a browser. Run on server code with no scoping,browser-security/no-client-side-auth-logicreportedtoken === req.query.tokenin a request handler. In the file above,clientandserverkeep it away from Node code. - A rule needs its plugin in the same match. Setting
'secure-coding/...'in an object that matches a file the preset object does not match fails on ESLint 9.39.4 withcould not find plugin "secure-coding". This happened when the presets usedignores: testsand the override objects did not. Every object in the file above carries the samefilesandignores. - Keep tests out. The
ignores: testsentry stops all five presets on*.test.*and*.spec.*files. A test file holding the four client statements from our fixture reported four messages without it and none with it. Some rules have their own switch instead;browser-security/no-innerhtmltakesallowInTests: true.
To scope by package in a monorepo, change the constants:
const client = ['apps/web/**/*.{js,jsx,ts,tsx}', 'packages/ui/**/*.{js,jsx,ts,tsx}'];
const server = ['apps/api/**/*.{js,ts}', 'packages/db/**/*.{js,ts}'];Shared code that runs in both places belongs in neither list, or in both with the overlap block adjusted. A file that matches both client and server gets both sets of rules, so the overlaps in the table apply to it.
Globs match paths relative to the directory holding eslint.config.js. To lint a single preset on everything, drop the scope call and spread the preset as in Flat config migration.
Related
- Alternatives to eslint-plugin-security compares these tools and Semgrep and CodeQL.
- Use alongside eslint-plugin-security has the corpus run behind the coverage claims.
- Plugin pages:
browser-security,node-security,secure-coding.
Building secure JavaScript with Interlace? Star the repo to get new rules and CWE coverage as we ship them — or follow the AI-code-security benchmarks behind them.
Detect XSS in JavaScript with ESLint flat config
A copy-paste eslint.config.js that flags DOM XSS sinks on ESLint 9 and 10, and what eslint-plugin-xss, no-unsanitized and browser-security each miss.
eslint-plugin-security alternatives
A neutral comparison of eslint-plugin-security, no-unsanitized, eslint-plugin-n, secure-coding, node-security, Semgrep and CodeQL: coverage, release dates, and which to combine.