Skip to content
Esc

@noctcore/eslint-plugin-security

v1.0.010 rules5 recommended5 opt-innamespace noctcore-security

A bad fit if you want broad taint tracking; this plugin trades recall for reports you can trust.

Injection, path traversal, SSRF, open redirect, unsanitized HTML and timing-unsafe comparison: high-precision syntactic sinks only.

A small set of sinks where a user-controlled string becomes a vulnerability: a shell command built by interpolation, a fetch URL whose host comes from a request, a redirect to an arbitrary origin, a path joined from req.params, HTML handed to dangerouslySetInnerHTML unsanitized, an HMAC signature compared with ===, a password hashed with a cheap bcrypt cost, an auth cookie written without httpOnly, secure or sameSite, a 'use server' action exported without its action client.

It will yell at you rarely, and on purpose: precision is the point. Each rule matches a narrow syntactic shape and stays silent when it cannot prove the value is dynamic, so it will miss taint that flows through a helper. Treat it as a tripwire, not a security audit, and keep a real SAST tool. Five rules are exported but left out of the preset: auth-cookie-flags because a rule entering the preset is a breaking change on 1.x and it matches cookies by name, bcrypt-rounds-min for the same 1.x reason, require-path-containment because it has a high false-positive rate, require-sanitized-html because a real codebase has trusted HTML only you can list, and server-action-through-client because it needs your action-client names. It is a bad fit if you want broad taint tracking; this plugin trades recall for reports you can trust.

Install
npm install --save-dev @noctcore/eslint-plugin-security @typescript-eslint/parser
# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-security @typescript-eslint/parser

The recommended preset enables 5 of 10 rules. The rules board below builds the flat config: start from a preset, switch single rules between error and off, and copy the result.

Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first read is no-shell-interpolation.

5 of 10 at error

--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.

auth-cookie-flags
An auth cookie (session, sid, auth_token, authToken by default) must be written with httpOnly: true, secure and a valid sameSite.
opt-in
bcrypt-rounds-min
A bcrypt hash / hashSync / genSalt / genSaltSync call must not pass a literal cost below minRounds (default 10).
opt-in
no-shell-interpolation
A dynamically-interpolated command string must not flow into a shell runner (exec/execSync, or spawn/execFile with a shell option that is not false), including through promisify(exec). Pass the program and arguments separately.
recommended
no-timing-unsafe-compare
An HMAC digest or signature must not be compared with === / !== / == / != or Buffer#equals; use crypto.timingSafeEqual.
recommended
no-user-controlled-fetch-url
Disallow HTTP requests whose origin is not fixed at authoring time: a runtime-controlled host enables SSRF.
recommended
no-user-controlled-redirect
Disallow redirects whose target origin is not fixed at authoring time: a user-controlled target is an open redirect.
recommended
presigned-post-requires-policy
A createPresignedPost call must pin the upload size and Content-Type in literal Conditions.
recommended
require-path-containment
Request-shaped input (req.*) passed directly into path.join / path.resolve without a containment test on the result is a path-traversal sink.
opt-in
require-sanitized-html
HTML reaching dangerouslySetInnerHTML, innerHTML, outerHTML or insertAdjacentHTML must be static markup or pass through a configured sanitizer.
opt-in
server-action-through-client
In a 'use server' module every exported action must be built from a configured action client; a raw exported function bypasses input validation, error shaping and middleware.
Needs options
opt-in