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.
npm install -D eslint-plugin-grpc-securityimport { configs } from 'eslint-plugin-grpc-security';
export default [configs.recommended];
Do not log gRPC metadata that carries credentials.
- CWE: CWE-532 — Insertion of Sensitive Information into Log File
- OWASP: A09:2021 — Security Logging and Monitoring Failures
- CVSS: 6.5 (Medium)
- Recommended:
error
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 anew Metadata()the file builds. - A dump of it:
getMap(),toJSON()ortoHttp2Headers(). - A credential header's value:
get('authorization')(or its[0]), orgetMap().cookie, forauthorization,proxy-authorization,cookieorx-api-keyin 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-securityimport 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{ "jsPlugins": ["oxlint-plugin-grpc-security"], "rules": { "grpc-security/no-credential-metadata-logging": "error" }}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.