Most JavaScript and TypeScript teams already run ESLint on every save and every pull request, yet few configure it to flag the code patterns that lead to injection and DOM XSS. Linting is the cheapest security check you can add: it runs in milliseconds, in the editor, before code review. This guide covers the security-relevant core rules, the main open source security plugins and their maintenance status as shown in their repositories, a working flat config, and how to run and triage the results in the IDE and CI. It also sets out what linting cannot find, so you can place it correctly next to SAST and dependency scanning. It is written for JavaScript and TypeScript developers and the application security engineers who support them.
Plugins are listed alphabetically by package name; order is never a ranking. Maintenance status was checked on the projects' repository pages in November 2026 and changes over time.
Key takeaways
- Turn on the core rules first.
no-eval,no-implied-evalandno-new-funccost nothing, have almost no false positives and block code-from-string patterns behind eval injection (CWE-95). - Add plugins for your framework and runtime. DOM sink rules for browser code, React rules for JSX, Node rules for server code, and type-aware rules for TypeScript.
- Lint is pattern matching on one file. It sees risky calls, not data flow, so it cannot tell you whether user input reaches them. That is SAST's job.
- Make CI the gate, the IDE the coach. Run the same config in both, fail the build on errors, and stop developers silencing rules with inline comments unreviewed.
- Check plugin maintenance before you depend on one. One plugin covered here has been archived by its owner; a lint plugin is also a dependency that runs in your build.
What linting can and cannot find
ESLint parses each file into a syntax tree and runs rules over it. A security rule matches a shape: a call to eval, an assignment to innerHTML, a require() with a variable argument. That makes lint fast and precise about where a risky construct is, but blind to whether it is exploitable.
| Question | ESLint security rules | SAST (taint analysis) | Dependency scanning (SCA) |
|---|---|---|---|
| Is a dangerous API used? | Yes, per file, at edit time | Yes | No |
| Does untrusted input reach it? | No | Yes, across files and functions | No |
| Is a library version vulnerable? | No | Sometimes | Yes |
| Is authorisation logic correct? | No | Rarely | No |
| Feedback time | Seconds, in the editor | Minutes, usually in CI | Minutes, in CI or registry |
Use lint to stop known-dangerous constructs being introduced, SAST to find exploitable flows (see the CodeQL Guide and Semgrep Guide), and SCA for the dependency tree (see the Software Composition Analysis (SCA) Guide). Business logic and access control flaws need code review and testing.
Security-relevant core rules
These ship with ESLint itself, need no plugin and rarely produce noise in modern code.
| Rule | What it flags | Notes |
|---|---|---|
no-eval | Calls to eval(), including indirect forms such as (0, eval)(...), aliasing eval to a variable, and window.eval or global.eval | Option allowIndirect defaults to false; leave it false. Cannot see renamed globals such as const foo = window; foo.eval() |
no-implied-eval | setTimeout(), setInterval() and execScript() with a string first argument, including window. forms | Passing a function is correct. For TypeScript use the type-aware version (below) |
no-new-func | new Function(...), Function(...) and Function.call, .apply and .bind | ESLint notes the engine parses the string much as it would with eval, and CSP may block it anyway |
For TypeScript, typescript-eslint provides @typescript-eslint/no-implied-eval, which uses type information to identify eval-like functions, adds setImmediate() and new Function(), and is part of the recommended-type-checked config. Its documentation says to turn the core no-implied-eval off when you enable it, because the base rule can report incorrect errors.
Security plugins overview
| Package | Focus | Example rules | Repository status (Nov 2026) |
|---|---|---|---|
| eslint-plugin-no-unsanitized (Mozilla) | DOM XSS sinks in browser code | method (e.g. insertAdjacentHTML(), document.write()), property (e.g. innerHTML) | Active repository; flat config and configs.recommended documented |
| eslint-plugin-react (jsx-eslint) | React and JSX | no-danger, no-danger-with-children, jsx-no-script-url, jsx-no-target-blank, iframe-missing-sandbox | Active repository; flat configs flat.recommended, flat.all, flat['jsx-runtime'] |
| @microsoft/eslint-plugin-sdl (Microsoft) | Baseline for projects following the Microsoft SDL; browser, Node, Angular, Electron, React | no-inner-html, no-document-write, no-postmessage-star-origin, no-insecure-url, no-electron-node-integration | Archived by the owner on 13 August 2026 and read-only; README states it is no longer actively maintained |
| eslint-plugin-security (eslint-community) | Node.js security hotspots | detect-child-process, detect-non-literal-fs-filename, detect-unsafe-regex, detect-object-injection, detect-bidi-characters | Active repository; flat config configs.recommended (ESLint 8.23.0 or later) |
| typescript-eslint | Type-aware TypeScript rules | @typescript-eslint/no-implied-eval | Active project; type-checked configs need type information |
eslint-plugin-no-unsanitized
Two rules: method disallows calls such as document.write() and insertAdjacentHTML(), and property disallows assignments such as innerHTML. Calls to .setHTML() are allowed by default, and the escaping functions Sanitizer.escapeHTML and escapeHTML are accepted when called with a template string. Pair it with the Trusted Types and DOM XSS Prevention Guide.
eslint-plugin-react
Security-relevant rules are mostly outside the recommended config: no-danger (dangerous JSX properties such as dangerouslySetInnerHTML), jsx-no-script-url (javascript: URLs) and iframe-missing-sandbox must be enabled explicitly. no-danger-with-children and jsx-no-target-blank are in recommended. The shareable configs do not set files or globals, so add those yourself.
@microsoft/eslint-plugin-sdl
Provides configs named angular, angularjs, common, electron, node, react, recommended, required and typescript, and reuses rules from ESLint core, eslint-plugin-react, typescript-eslint, eslint-plugin-security and the node plugin alongside its own 15 @microsoft/sdl/ rules. Because the repository is archived, teams already using it can treat its rule list as a reference and enable the equivalent core and plugin rules directly.
eslint-plugin-security
Fourteen rules, all in recommended, aimed at Node.js hotspots: child process use, non-literal file paths, require() and regular expressions, unsafe regexes (see the Regular Expression Denial of Service (ReDoS) Guide), possible timing attacks and bidirectional Unicode characters. The README warns that it produces many false positives that need human triage, so treat findings as review prompts, especially detect-object-injection (see the Prototype Pollution Guide).
typescript-eslint
Supplies the parser and rules for TypeScript. Its type-checked configs, including @typescript-eslint/no-implied-eval, need type information, which makes linting slower; run them in CI even if the editor uses a lighter config.
Configuring flat config for security
ESLint's current configuration format is the flat config: an eslint.config.js (or .mjs, .cjs, .ts, .mts, .cts) in the project root exporting an array of config objects. Objects that match a file merge in order, with later objects overriding earlier ones. By default ESLint lints only **/*.js, **/*.cjs and **/*.mjs, so TypeScript and JSX need explicit files patterns. A minimal security layer for a browser and Node codebase:
1 Sample only, based on the public documentation cited. Assess it independently against the current official documentation, test outside production and back up first.
import { defineConfig, globalIgnores } from "eslint/config";
import nounsanitized from "eslint-plugin-no-unsanitized";
import pluginSecurity from "eslint-plugin-security";
export default defineConfig([
globalIgnores(["dist/**", "coverage/**"]),
{
name: "security/core",
files: ["**/*.{js,mjs,cjs,ts,tsx}"],
linterOptions: {
noInlineConfig: false,
reportUnusedDisableDirectives: "error"
},
rules: {
"no-eval": "error",
"no-implied-eval": "error",
"no-new-func": "error"
}
},
{
name: "security/browser",
files: ["src/client/**/*.{js,ts,tsx}"],
plugins: { nounsanitized },
rules: {
"nounsanitized/method": "error",
"nounsanitized/property": "error"
}
},
{
name: "security/server",
files: ["src/server/**/*.{js,ts}"],
extends: [pluginSecurity.configs.recommended]
}
]);- Scope by directory: apply DOM rules to browser code and Node rules to server code, so each team sees relevant findings only.
- TypeScript: add the typescript-eslint parser and, for type-aware rules, turn off
no-implied-evaland enable@typescript-eslint/no-implied-evalin the TypeScript block. - Unused disables:
reportUnusedDisableDirectivesflags staleeslint-disablecomments so suppressions do not outlive the code they covered. - Inline config: setting
noInlineConfig: true(or the--no-inline-configflag) stops comments from changing rules. It is strict; many teams instead require a justification and code owner review for any disable comment touching a security rule. - Shared config: publish the security block as an internal shareable config so every repository inherits the same baseline through
extends.
Running in IDE and CI
- Baseline: run the new rules as
warnacross the codebase and export results with--format json --output-file. Count findings per rule. - Fix the cheap ones: core eval rules usually have few hits; fix them and promote to
errorstraight away. - Gate new code: in CI, fail on errors (exit code 1) and use
--max-warningswith the current count so warnings cannot grow. Exit code 2 means a configuration or internal error; treat it as a failed build, not a pass. - Editor: use the same
eslint.config.jsin the editor extension so developers see findings before commit; optionally add a pre-commit hook (see the Git Hooks and Pre-commit Security Guide). - Cache carefully:
--cachespeeds up local runs, but ESLint warns it does not track dependencies between files, so type-aware results can be stale. Run CI without a stale cache. - Roll back: if a rule floods a team, demote it to
warnfor that directory in config rather than removing it, and record a date to revisit.
Lint plugins run inside your build with whatever credentials CI has. Pin versions with a lockfile and review plugin updates like any dependency: the eslint-scope npm compromise in 2018 showed a malicious version of a widely used ESLint dependency stealing npm tokens through an install script. See the npm Install-Time Security Guide.
Triage and false positives
| Finding type | Typical cause | Triage action |
|---|---|---|
| eval, implied eval, new Function | Legacy templating, dynamic code loading, string timers | Refactor: pass functions, use JSON.parse, use a lookup table |
| DOM sink (innerHTML, insertAdjacentHTML, document.write) | Rendering HTML strings | Use textContent, a framework binding or a vetted sanitiser; confirm the input source |
| Non-literal fs path, require or RegExp | Config-driven paths, plugin loaders | Check whether the value can come from a request; constrain to an allowlist or a fixed base directory |
Object injection (obj[key]) | Any bracket access with a variable | High noise; check only where the key comes from user input, then use Map or a key allowlist |
| dangerouslySetInnerHTML | Rich text rendering | Require sanitisation and a justification comment reviewed by a code owner |
- Suppress narrowly: use
// eslint-disable-next-line rule-name -- reasonfor one line and one rule, never a file-wide disable without a rule name. - Measure: track security rule errors on the main branch (target zero), count of security-rule disable comments and their trend, percentage of repositories on the shared security config, and time from finding to fix.
- Feed SAST: when a lint finding turns out to be exploitable, write or enable a SAST rule for the data flow so it is caught across the codebase. See the SAST Triage Guide.
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | SA-11 Developer Testing and Evaluation; SA-11(1) Static Code Analysis; SA-15 Development Process, Standards, and Tools | Lint in the editor and CI is a form of static code analysis with defined tooling |
| NIST CSF 2.0 | PR.PS-06 | Secure development practices integrated into the life cycle |
| MITRE CWE | CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code; CWE-79 Cross-site Scripting | Weaknesses targeted by eval and DOM sink rules |
| ISO/IEC 27001:2022 | Annex A 8.28 Secure coding | Tool-enforced coding rules as evidence of secure coding practice |
Practitioner checklist
- Enable
no-eval,no-implied-evalandno-new-funcas errors in every JavaScript and TypeScript repository. - Use
@typescript-eslint/no-implied-evalwith the core rule off in type-checked TypeScript projects. - Add DOM sink rules for browser code and React security rules (including the ones outside recommended) for JSX.
- Add Node.js hotspot rules for server code and plan for human triage of their findings.
- Check each plugin's repository for archive status and recent activity before adopting it, and re-check yearly.
- Scope rules with
filespatterns and publish one shared security config. - Fail CI on errors and on exit code 2; cap warnings with
--max-warnings. - Report unused disable directives and require a reason on every security rule suppression.
- Pin lint plugins in the lockfile and review their updates as dependencies.
- Run SAST and dependency scanning alongside lint; do not treat a clean lint run as a security sign-off.
Standards and references
- ESLint: Configuration Files
- ESLint: no-eval
- ESLint: no-implied-eval
- typescript-eslint: no-implied-eval
- Mozilla: eslint-plugin-no-unsanitized
- jsx-eslint: eslint-plugin-react
- Microsoft: eslint-plugin-sdl
- eslint-community: eslint-plugin-security
Related NHI Mgmt Group resources: TypeScript and JavaScript Secure Coding Guide, Cross-Site Scripting (XSS) Prevention Guide, Node.js Security Guide, SAST vs SCA.