Skip to content

Security rules

Finds template and Markdown options that turn off HTML escaping: noEscape: true in handlebars.compile, sanitize: false in marked.setOptions and kramed.Renderer, html: true in markdown-it, autoescape: false in swig.setDefaults, and a Mustache.escape that returns its input unchanged.

On in the recommended and all configs.

Without escaping, a value that holds HTML runs as markup in the page, so an attacker can inject scripts.

Keep the escaping on. Mark only reviewed markup as safe, one value at a time.

The call Handlebars.compile(source, { noEscape: true }) reports unescaped. Use Handlebars.compile(source).

Finds compile and render calls of pug and ejs whose template text is not a literal: a template literal with an expression, a concatenation with a computed part, or any other value that is not written in the code.

On in the recommended and all configs.

A template engine runs the code inside a template, so a template built from input lets an attacker run code on the server.

Keep templates in fixed files or constants, and pass the values as template data.

The call pug.render("p Hello " + name) reports builtTemplate. Use pug.render("p Hello #{name}", { name }).

Finds code that runs a string as code: eval, Function, and the vm module functions called with an argument that is not a literal, and javascript: URLs built from a template literal or a concatenation with a computed part.

On in the recommended and all configs.

Code built at run time can run whatever an attacker puts into its input.

Call the code directly, or select it from a fixed table of functions. Pass data as data, such as through JSON.parse.

The call eval(userInput) reports dynamicCode. Call the function that the input names from a fixed table, such as handlers[name]().

Finds query calls of pg, mysql, mysql2, sqlite3, better-sqlite3, mssql, oracledb, pg-promise, knex, sequelize, and typeorm whose query text is a template literal with an expression, a concatenation with a computed part, or the result of concat or replace.

On in the recommended and all configs.

A query built from values lets an attacker who controls a value change the query: read, change, or delete other data.

Write the query text as a constant, and pass the values as query parameters.

The call client.query(`SELECT * FROM users WHERE id = ${id}`) reports builtQuery. Use client.query("SELECT * FROM users WHERE id = $1", [id]).

Reports child_process commands whose literal executable depends on PATH lookup.

On in the all config.

A writable directory in PATH can replace the intended program with an attacker-controlled executable.

Use an explicit executable path and ensure its directory cannot be changed by untrusted users.

spawn("/usr/bin/git", ["status"]) names the executable explicitly.

Finds chmod, fchmod, and lchmod calls, and their Sync forms, that give other users any permission, and process.umask calls that do not remove every permission of other users.

On in the recommended and all configs.

A file that every user of the machine can read or change leaks its data or lets another process change it.

Give no permission to other users: end the mode in 0, such as 0o750, and the umask in 7, such as 0o027.

The call fs.chmodSync("/tmp/report", 0o777) reports permissive. Use fs.chmodSync("/tmp/report", 0o750).

Reports public temporary directory literals and process.env temporary-directory values.

On in the all config.

Other users can create or replace files in shared writable directories.

Create a private temporary directory with restrictive permissions and use its returned path.

mkdtemp(join(tmpdir(), "job-")) creates a unique private directory for the job.

Finds parseXml and parseXmlString calls of libxmljs and libxmljs2 whose options set noent to true.

On in the recommended and all configs.

The noent option replaces external entities with the content that they point to, so a crafted document can read files from the server or make it send requests.

Remove noent: true, so that the parser keeps external entities unresolved.

The call libxmljs.parseXmlString(text, { noent: true }) reports entities. Use libxmljs.parseXmlString(text).