SKY-D271 · Security in code
Stack trace or SQL error sent to the client
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
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
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
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
- Runs with
--dangeron TypeScript and JavaScript files. Walks every call whose method name isjson,send,writeorend, on any receiver:res.json(…),res.status(500).send(…),reply.send(…). - Searches all of the call's arguments, however deeply nested, for a property access ending in
.stack,.sql,.sqlMessageor.sqlState, and reports the call when it finds one. - 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. - Other ways to leak details, such as
err.messageorString(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.
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,sendorendcall counts, so writing a stack trace to a log stream, such asprocess.stdout.write(err.stack)orlogFile.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--baselineaccept the existing calls and report only new ones.