Skip to content

Servers rules

Finds request size limits above 8 MB for file uploads with formidable and multer, and above 2 MB for other requests with body-parser, also when the limit stays at a larger default or is missing.

On in the recommended and all configs.

A server that accepts very large requests lets a client fill its memory or disk and stop it from serving other users.

Set a limit that fits the largest request the route needs: maxFileSize for formidable, limits.fileSize for multer, and limit for body-parser.

The call multer({ dest: "uploads/" }) reports unlimited. Use multer({ dest: "uploads/", limits: { fileSize: 4_000_000 } }).

Finds CORS policies that let any site read the responses: an Access-Control-Allow-Origin of *, the cors middleware with no origin or an origin of * or true, and a handler that copies the request Origin unchecked.

On in the recommended and all configs.

A permissive CORS policy lets any site read the responses that a signed-in user receives.

Allow only the origins that need access: set origin to a list of trusted sites, and compare a request origin with that list before you send it back.

The call app.use(cors()) reports permissive. Use app.use(cors({ origin: ["https://app.example.com"] })).

Reports explicitly disabled secure and HttpOnly cookie flags in session, CSRF, and cookie APIs.

On in the recommended and all configs.

Secure cookies stay on encrypted connections, and HttpOnly keeps browser scripts from reading them.

Set secure and httpOnly to true. For csurf, configure cookie options explicitly instead of cookie: true.

session({ cookie: { secure: true, httpOnly: true } }) keeps both cookie protections enabled.

Requires an Express application to disable its X-Powered-By header.

On in the recommended and all configs.

The default response header tells clients which server framework handles their requests.

Call app.disable(‘x-powered-by’) after creating the application, or install middleware that removes the header.

const app = express(); app.disable('x-powered-by'); disables the framework header.

Finds use calls that add the errorhandler middleware outside an if statement, so that it runs in every environment.

On in the recommended and all configs.

The errorhandler middleware sends stack traces and other details of the server to the client, which helps attackers.

Add the middleware only in development, inside a check such as if (process.env.NODE_ENV === "development").

The call app.use(errorhandler()) at the top level of a module reports debugMiddleware. Wrap it in if (process.env.NODE_ENV === "development") { app.use(errorhandler()); }.

Follows a field of req or request, such as req.query, through the variables of one function, and reports it where it reaches a redirect, an HTML response, a view name, a file path, an outbound request, SQL text, a regular expression, a shell, or a property name.

On in the recommended and all configs.

Request data comes from the client, so in these places it opens a redirect, reflected XSS, a path traversal, a request forgery, SQL injection, a slow regular expression, command injection, or prototype pollution.

Check the value against a fixed list, escape it for the place it goes, or pass it as a parameter, such as a query parameter in SQL.

const file = req.query.file; fs.readFile(path.join(root, file), done); reports path. Look the file up by a key, or keep only path.basename(file).

Finds formidable forms without an uploadDir or with keepExtensions: true, and multer.diskStorage storages without a destination.

On in the recommended and all configs.

An uploaded file that lands in a shared folder, or that keeps an extension such as .html or .js, can be served or run by the server.

Set an upload folder that the server never serves, and give stored files a name and extension that the server chooses.

The call formidable({ keepExtensions: true }) reports extensionAndFolder. Use formidable({ uploadDir: "/var/uploads" }).

Reports disabled Helmet security headers and unsafe referrer or HSTS settings in Express middleware.

On in the recommended and all configs.

These headers restrict browser access, prevent MIME guessing, and require encrypted connections.

Keep the Helmet defaults. Use a restrictive referrer policy and HSTS for at least six months with subdomains included.

app.use(helmet()); keeps the default security headers enabled.

Reports await req.json() and await request.json() whose result no schema parses with parse or safeParse. No config turns it on; gspot turns it on for the Supabase edge functions.

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

A request body comes from the client, so any field can be missing or of the wrong type. Code that trusts it can write bad data or fail in ways that leak details.

Parse the body with a schema, such as a Zod schema, before the code reads it.

const body = await req.json(); with no schema reports unvalidated. Write const body = Order.parse(await req.json());.

In a file that imports csurf, finds post, put, delete, and patch routes that run without the csurf middleware, and an ignoreMethods option that skips a method other than GET, HEAD, and OPTIONS.

On in the recommended and all configs.

A route that changes data without a CSRF check lets another site send that change in the name of a signed-in user.

Add the csurf middleware with app.use before the routes, or pass it to each route that changes data. Keep only safe methods in ignoreMethods.

After const csrf = csurf();, the route app.post("/transfer", transfer) reports unprotectedRoute. Use app.post("/transfer", csrf, transfer).

Finds route callbacks that come after passport.authenticate in the same route and never call regenerate, unless the authentication passes session: false.

On in the recommended and all configs.

A session that keeps its identifier after login lets an attacker who planted that identifier take over the signed-in session.

Call req.session.regenerate in the callback that runs after authentication, and copy the data you keep into the new session.

The route app.post("/login", passport.authenticate("local"), function (req, res) { res.redirect("/"); }) reports keptSession. Call req.session.regenerate(...) in the callback.

Finds app.use(express.static(…)) calls that come after the express-session or cookie-session middleware on the same Express app.

On in the recommended and all configs.

Static files then pass through the session middleware, which sets session cookies on responses that caches and other users can receive.

Add the static middleware before the session middleware.

The calls app.use(session(options)); app.use(express.static("public")); report staticAfterSession on the second call. Swap the two calls.