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

no-credential-metadata-logging

Do not log gRPC metadata that carries credentials

Next step

no-credential-metadata-logging ships in eslint-plugin-grpc-security, with 7 of its 8 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 log gRPC metadata that carries credentials.

Why

gRPC metadata carries the caller's credentials: the bearer token, the session cookie, the API key. Logging the whole metadata object, a dump of it, or a credential header's value writes those secrets into every log store, aggregator and support export downstream. Anyone with log access can then replay them.

Rule details

The rule reports an argument of a logging call when it contains any of:

  • The metadata object itself: a gRPC handler's call.metadata (or a destructured { metadata }), or a new Metadata() the file builds.
  • A dump of it: getMap(), toJSON() or toHttp2Headers().
  • A credential header's value: get('authorization') (or its [0]), or getMap().cookie, for authorization, proxy-authorization, cookie or x-api-key in any case.

The rule looks inside objects, arrays, spreads, templates, +, ||, ternaries, consts, String() and JSON.stringify().

A logger is the global console, or a receiver bound to a logging library: an import of pino, winston, bunyan, log4js, loglevel, consola or signale, or the result of calling one (pino(), winston.createLogger()).

Two choices keep this structural rather than name-based. The Metadata API is the anchor, so only gRPC metadata counts. The header set is the HTTP definition of a credential header (RFC 9110, RFC 6265, plus x-api-key), not a guess at a name.

Incorrect

server.addService(svc, {
  GetAccount(call, callback) {
    logger.info({ headers: call.metadata.getMap() }, 'GetAccount');
    console.log('auth', call.metadata.get('authorization'));
  },
});

Correct

server.addService(svc, {
  GetAccount(call, callback) {
    logger.info(
      { requestId: call.metadata.get('x-request-id')[0] },
      'GetAccount',
    );
  },
});

If a logger receives whole objects, configure its redaction (pino redact, a winston format) for those keys as well.

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-credential-metadata-logging': 'error'    },  },];
npm install -D oxlint-plugin-grpc-security
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-grpc-security"],  "rules": {    "grpc-security/no-credential-metadata-logging": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-grpc-security'],    rules: {      'grpc-security/no-credential-metadata-logging': '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.