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.
npm install -D eslint-plugin-grpc-securityimport { configs } from 'eslint-plugin-grpc-security';
export default [configs.recommended];
Do not send a caught error's stack or message to the gRPC client.
- CWE: CWE-209 — Generation of Error Message Containing Sensitive Information
- OWASP: A05:2021 — Security Misconfiguration
- CVSS: 5.3 (Medium)
- Recommended:
error
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
detailsormessageof the status object (inline or through aconst) is reported when it is built frome,e.stack,e.message,String(e)ore.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-securityimport 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{ "jsPlugins": ["oxlint-plugin-grpc-security"], "rules": { "grpc-security/no-error-detail-leak": "error" }}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.