Skip to main content
Skip to Content
interlace
SecurityPlugin: grpc-securityRules

no-error-detail-leak

Do not send a caught error's stack or message to the gRPC client

Next step

no-error-detail-leak ships in eslint-plugin-grpc-security, with 4 of its 4 rules in the recommended preset.

Install
npm install -D eslint-plugin-grpc-security
eslint.config.js
import { configs } from 'eslint-plugin-grpc-security';

export default [configs.recommended];

Plugin pagenpmSource on GitHub

Do not send a caught error's stack or message to the gRPC client.

Why

A gRPC status's details travel to the client. Filled from a caught error, they carry whatever the error carried: a stack trace with file paths and dependency versions, a database error quoting the query, the URL of an internal service. Each one is a map of the server for whoever called it.

Rule details

The rule decides from structure, not from names.

  • Sink: something a gRPC handler was given, where a handler is a method of the object passed to .addService(service, implementation). That covers the handler's callback (cb({ details }), callback(status)) and its call object (call.emit('error', status), call.destroy(status)).
  • Source: a caught error, identified by its binding: a catch (e) parameter, or the first parameter of a .catch((e) => …) callback.
  • Flow: the details or message of the status object (inline or through a const) is reported when it is built from e, e.stack, e.message, String(e) or e.toString(). Templates, +, ||, ??, ternaries and consts in between are followed.

Passing the caught error itself (cb(e)) is not reported. gRPC then sends its message, and applications often throw errors whose message is meant for the client.

Incorrect

server.addService(svc, {
  GetOrder(call, cb) {
    try {
      cb(null, db.find(call.request.id));
    } catch (err) {
      cb({ code: grpc.status.INTERNAL, details: err.stack });
    }
  },
});

Correct

server.addService(svc, {
  GetOrder(call, cb) {
    try {
      cb(null, db.find(call.request.id));
    } catch (err) {
      log.error(err);
      cb({ code: grpc.status.INTERNAL, details: 'internal error' });
    }
  },
});

Further reading

Use this rule

npm install -D eslint-plugin-grpc-security
eslint.config.js
import grpcSecurity from 'eslint-plugin-grpc-security';export default [  {    plugins: { 'grpc-security': grpcSecurity },    rules: {      'grpc-security/no-error-detail-leak': 'error'    },  },];
npm install -D oxlint-plugin-grpc-security
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-grpc-security"],  "rules": {    "grpc-security/no-error-detail-leak": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-grpc-security'],    rules: {      'grpc-security/no-error-detail-leak': 'error',    },  },});

oxlint-plugin-grpc-security re-exports eslint-plugin-grpc-security/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.