require-call-deadline
Give every gRPC client call a deadline
Next step
require-call-deadline 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];
Give every gRPC client call a deadline.
- CWE: CWE-400 — Uncontrolled Resource Consumption
- OWASP: A04:2021 — Insecure Design
- CVSS: 5.3 (Medium)
- Recommended: off (
strictonly)
Why
A gRPC call has no timeout unless the caller sets a deadline. Against a slow or stalled server, every call without one holds its stream, its memory and whatever is waiting on it, indefinitely. Under load those pile up until the client runs out of resources, and a single slow dependency takes down everything that calls it.
Rule details
The rule identifies a client by structure: new X(target, credentials) whose second argument is gRPC channel credentials (credentials.createSsl(), createInsecure(), combineChannelCredentials(…)). The credentials can be inline or in a const, and X can be any generated service client or Client.
A method call on that client is reported when:
- no argument is an options object with a
deadline(inline or through aconst), and - every argument the file can't read sits where only the request can go. An unreadable later argument might be an options object that holds a deadline, so the rule stays silent. The same goes for a single unreadable argument with no callback, which could be a streaming call's options.
close(), getChannel() and waitForReady() aren't calls and are skipped.
This rule is in strict only. A deadline can also be set by an interceptor or a wrapper the file can't see, so a missing deadline is a best practice the code doesn't prove, not a defect.
Incorrect
const client = new pkg.Orders(target, grpc.credentials.createSsl());
client.GetOrder({ id }, (err, order) => {});Correct
const client = new pkg.Orders(target, grpc.credentials.createSsl());
client.GetOrder({ id }, { deadline: Date.now() + 5000 }, (err, order) => {});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/require-call-deadline': 'error' }, },];npm install -D oxlint-plugin-grpc-security{ "jsPlugins": ["oxlint-plugin-grpc-security"], "rules": { "grpc-security/require-call-deadline": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-grpc-security'], rules: { 'grpc-security/require-call-deadline': '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.