Skip to main content

SKY-D271 · Security in code

Stack trace or SQL error sent to the client

Medium

When a request fails, a server should log the details and send the caller a short, generic message. SKY-D271 reports a response call such as res.json() or res.send() whose argument includes an error's stack or the SQL details a database driver attaches (sql, sqlMessage, sqlState).

Languages
TypeScript/JavaScript
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
Error information disclosure over HTTP
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A stack trace shows file paths, library versions and the code path that failed; a MySQL error can echo the query and table names. An attacker who can make a request fail learns how to aim the next one, for example how to finish a half-working SQL injection.

What Skylos flags

src/server/errors.ts · TypeScriptReported on line 9
import type { NextFunction, Request, Response } from "express"; export function errorHandler(  err: Error,  req: Request,  res: Response,  next: NextFunction,): void {  res.status(500).json({ error: err.message, stack: err.stack });}

What Skylos leaves alone

src/server/errors.ts · TypeScript
import type { NextFunction, Request, Response } from "express"; export function errorHandler(  err: Error,  req: Request,  res: Response,  next: NextFunction,): void {  console.error(err.stack);  res.status(500).json({ error: "Internal server error" });}

Why Skylos leaves it alone

The stack trace still exists, but it goes to the server log through console.error(), which is not a response method. The client only receives a fixed message.

How Skylos decides

  1. Runs with --danger on TypeScript and JavaScript files. Walks every call whose method name is json, send, write or end, on any receiver: res.json(…), res.status(500).send(…), reply.send(…).
  2. Searches all of the call's arguments, however deeply nested, for a property access ending in .stack, .sql, .sqlMessage or .sqlState, and reports the call when it finds one.
  3. It does not check that the receiver is an HTTP response or that the object is an error, and it does not follow values through variables: const details = err.stack; res.json({ details }) is not reported.
  4. Other ways to leak details, such as err.message or String(err), are not checked.

How to fix it

Log the full error on the server, return a generic message, and give the caller an identifier they can quote to support so the log entry can be found.

src/server/errors.ts · TypeScript · the fix, against the flagged file
Added: import { randomUUID } from "node:crypto";Added:  import type { NextFunction, Request, Response } from "express"; export function errorHandler(  err: Error,  req: Request,  res: Response,  next: NextFunction,): void {Removed:   res.status(500).json({ error: err.message, stack: err.stack });Added:   const errorId = randomUUID();Added:   console.error(errorId, err.stack);Added:   res.status(500).json({ error: "Internal server error", errorId });}

When it can be wrong

  • Any write, send or end call counts, so writing a stack trace to a log stream, such as process.stdout.write(err.stack) or logFile.write(err.stack), is reported.
  • A stack trace sent only in development, such as res.json({ stack: isProd ? undefined : err.stack }), is reported: the condition is not evaluated.
  • Missed: err.message, String(err), err.toString() and a stack copied into a variable before the response.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed line with a comment on the same line.

    TypeScript
    logStream.write(err.stack); // skylos: ignore[SKY-D271] server log, not a response
  • [tool.skylos] ignore = ["SKY-D271"] turns the rule off for the whole project.

  • skylos baseline . and then --baseline accept the existing calls and report only new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.