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

no-unguarded-reflection

Register gRPC server reflection only behind a guard

Next step

no-unguarded-reflection ships in eslint-plugin-grpc-security, with 1 of its 1 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

Register gRPC server reflection only behind a guard.

Why

Server reflection answers one question for any client, with no credentials: which services and methods does this listener serve? It is what lets grpcurl and Postman work without a .proto file, and that is why it gets turned on during development.

Registered unconditionally, it ships to production. A team that put an internal admin service on the same server as the public API, trusting that nobody outside knew its name, has published that name: grpcurl -plaintext host:port list prints it, and describe prints every method and message. Reflection is rarely the whole bug, but it is the step that turns a hidden method into a discovered one.

Rule details

Fires only in files that load @grpc/reflection or grpc-server-reflection. Reports a registration when nothing in the file stands between it and the program running:

  • new ReflectionService(def).addToServer(server) from @grpc/reflection, through a named, namespace, default or CommonJS import, and through a const the service was bound to first;
  • addReflection(server, descriptorSetPath) from grpc-server-reflection.

The decision is made from structure, not from names or values. Any branch counts as a guard, because a branch is a decision the code made and the rule cannot know the deployment:

  • the body or else arm of an if, a ternary arm, the right side of && / || / ??, a switch case;
  • a statement that follows if (…) return; (or throw, break, continue) in the same block.

Functions are followed within the file. A callback or an IIFE runs whenever its caller does, so the rule looks through it. A named helper is answered by its call sites: it reports if any call site is itself unguarded. A helper with no call site in the file (exported, a default export, a class method) is left to its caller.

A loop or a try block is not a guard: the code inside still runs.

Incorrect

import { ReflectionService } from '@grpc/reflection';

const server = new grpc.Server();
server.addService(pkg.shop.Catalog.service, catalog);
server.addService(pkg.ops.Maintenance.service, maintenance);
new ReflectionService(def).addToServer(server);
import { addReflection } from 'grpc-server-reflection';

addReflection(server, 'descriptor_set.bin');

Correct

import { ReflectionService } from '@grpc/reflection';

if (process.env.NODE_ENV === 'development') {
  new ReflectionService(def).addToServer(server);
}

Reflection being off in production does not make an internal service private. Serve internal services from a separate server bound to a private interface, behind authentication.

When not to use it

If reflection is an intended part of a public API, and every service on the listener is meant to be public, disable this rule for that file with a comment that says so.

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