Skip to content

Web rules

Finds <script> elements that document.createElement makes and that load a versioned file from another host without an integrity hash and crossOrigin = "anonymous".

On in the recommended and all configs. It reports nothing without the type information of a TypeScript project.

Without a subresource integrity check, the page runs whatever script the other host serves, also after an attacker changes it.

Set integrity to the hash of the expected file and crossOrigin to "anonymous".

The code const script = document.createElement("script"); script.src = "https://cdn.example.com/lib@1.2.3/lib.js"; reports missingBoth. Add script.integrity = "sha384-..." and script.crossOrigin = "anonymous".

Finds DOMPurify.sanitize configurations that let dangerous markup through, such as script in ADD_TAGS, an event handler attribute in ADD_ATTR, or ALLOW_UNKNOWN_PROTOCOLS set to true.

On in the recommended and all configs.

These options let script and event handler markup through the sanitizer, so an attacker can inject code into the page.

Keep the default configuration, or allow only harmless tags and attributes.

The call DOMPurify.sanitize(html, { ADD_TAGS: ["iframe"] }) reports unsafe. Use DOMPurify.sanitize(html).

Finds postMessage calls on a window with the target origin *, and message listeners on a window that never compare event.origin in an if statement.

On in the recommended and all configs. It reports nothing without the type information of a TypeScript project.

A message sent to * reaches any page that the window shows, and a listener that does not check the origin accepts messages from any site.

Pass the exact origin of the receiver to postMessage, and return early in the listener when event.origin is not a trusted origin.

The call frame.contentWindow.postMessage(data, "*") reports anyTarget. Use frame.contentWindow.postMessage(data, "https://app.example.com").

Finds private environment reads in client modules, such as process.env.SECRET_KEY, Bun.env, Deno.env.get, and import.meta.env. The publicPrefixes and allowedNames options name the public values.

On in the recommended and all configs.

Client code needs public configuration. Private environment values are unavailable in the browser by default, and exposing a secret to satisfy the read is unsafe.

Keep private configuration and the work that needs it in a server-only module. Pass only public results to client code, or use NEXT_PUBLIC_ variables for values intended for the browser.

In a module beginning with "use client", const key = process.env.SECRET; reports private. Move the secret read and the work that needs it to a server module. A genuinely public URL can use process.env.NEXT_PUBLIC_URL in the client. Never rename a secret to make it public. See Next.js environment variables.

Option Type Default What it does
client true or false false Treat selected files as client code without a use-client directive.
publicPrefixes List ["NEXT_PUBLIC_"] Prefixes allowed for public environment variables.
allowedNames List ["NODE_ENV"] Environment variable names allowed in client code.

Reports Angular sanitizer bypass calls whose value is not a known literal.

On in the recommended and all configs.

Bypassing sanitization lets untrusted HTML, scripts, styles, or URLs reach the browser.

Keep Angular sanitization enabled for dynamic values. Bypass it only for a reviewed literal.

Bind a dynamic value through the normal Angular template binding instead of bypassSecurityTrustHtml.

Finds window.open and this.window.open calls that open an http or https URL without noopener in the window features.

On in the recommended and all configs.

The opened page gets a reference to the page that opened it, so it can send that page to another address, such as a phishing copy.

Pass noopener in the window features: window.open(url, "_blank", "noopener").

The call window.open("https://example.com", "_blank") reports opener. Use window.open("https://example.com", "_blank", "noopener").

Checks that a selected server module imports “server-only” in a form that stays in the built code, or declares “use server”.

No config turns it on; turn it on in your ESLint config.

A server-only marker lets Next.js reject client imports of a module that uses private server capabilities. A marker that the compiler removes protects nothing.

Add import “server-only” to the imports. Use “use server” only for a module that follows the Server Actions contract. If the file is not server code, remove it from the files this rule selects.

A selected server module containing export const secret = 1; reports missing. With the server-only package installed, add import "server-only"; before that declaration. import type {} from "server-only", import {} from "server-only" and an import whose names are all type-only do not count, because TypeScript or Bun drop them from the output.