eslint-plugin-grpc-security 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,94 @@
1
+ <!-- Generated by scripts/generate-plugin-agents-md.ts from package.json and the plugin exports. Do not edit by hand; run `npm run agents-md`. -->
2
+
3
+ # eslint-plugin-grpc-security
4
+
5
+ Guide for AI coding assistants using this plugin in a project. To change the plugin's own source, read https://github.com/ofri-peretz/eslint/blob/main/AGENTS.md instead.
6
+
7
+ > ESLint gRPC security rules — catches server reflection registered with no guard, a caller identity read from client-settable metadata, message size limits removed, caught errors sent to the client, plaintext transport that is exposed or carries secrets, credentials written to logs, and calls with no deadline.
8
+
9
+ ## Enable it
10
+
11
+ ```bash
12
+ npm install --save-dev eslint-plugin-grpc-security
13
+ ```
14
+
15
+ Requires ESLint ^8.40.0 || ^9.0.0 || ^10.0.0 and Node >=22.13.0.
16
+
17
+ Flat config files (`eslint.config.*`) are found by ESLint 8.57 and newer; on ESLint 9 and 10 they are the default.
18
+
19
+ ```js
20
+ // eslint.config.mjs
21
+ import grpcSecurity from 'eslint-plugin-grpc-security';
22
+
23
+ export default [grpcSecurity.configs.recommended];
24
+ ```
25
+
26
+ Each preset is one flat config object: put it in the array as an element, do not spread it. Rule ids are prefixed `grpc-security/`. Add it to the config you already have; do not remove other plugins. TypeScript files need a TypeScript parser in the config (`typescript-eslint`).
27
+
28
+ Use it alongside `eslint-plugin-security`, not instead of it: keep that plugin if the project has it. Measured overlap and the limits of both: https://eslint.interlace.tools/docs/getting-started/with-eslint-plugin-security
29
+
30
+ ## Presets
31
+
32
+ | Preset | Rules | Errors | Warnings |
33
+ | ------------- | ----- | ------ | -------- |
34
+ | `minimal` | 1 | 1 | 0 |
35
+ | `recommended` | 7 | 7 | 0 |
36
+ | `strict` | 8 | 8 | 0 |
37
+
38
+ ### `minimal`
39
+
40
+ 1 rule:
41
+
42
+ - `no-unguarded-reflection` (error): Register gRPC server reflection only behind a guard.
43
+
44
+ ### `recommended`
45
+
46
+ 7 rules:
47
+
48
+ - `no-unguarded-reflection` (error): Register gRPC server reflection only behind a guard.
49
+ - `no-identity-from-metadata` (error): Do not authorize a gRPC caller by an identity read from metadata.
50
+ - `no-unbounded-message-size` (error): Keep gRPC message size limits bounded.
51
+ - `no-error-detail-leak` (error): Do not send a caught error's stack or message to the gRPC client.
52
+ - `no-insecure-server-credentials` (error): Do not serve plaintext gRPC on every interface.
53
+ - `no-insecure-channel-credentials` (error): Do not send credentials over a plaintext gRPC channel.
54
+ - `no-credential-metadata-logging` (error): Do not log gRPC metadata that carries credentials.
55
+
56
+ ### `strict`
57
+
58
+ Everything in `recommended` plus 1 more:
59
+
60
+ - `require-call-deadline` (error): Give every gRPC client call a deadline.
61
+
62
+ ## Other Interlace plugins by dependency
63
+
64
+ If the project also depends on one of these, add the matching plugin the same way:
65
+
66
+ - `express`, `fastify`, `koa`, `@hapi/hapi`, `restify`, `hono`, `next`, `@nestjs/core`, `@nestjs/common`, `aws-lambda`, `@types/aws-lambda`, `@middy/core`, `commander`, `yargs`, `@oclif/core`, `@modelcontextprotocol/*`: `eslint-plugin-node-security`
67
+ - `express`: `eslint-plugin-express-security`
68
+ - `@nestjs/common`, `@nestjs/core`: `eslint-plugin-nestjs-security`
69
+ - `react`, `react-dom`, `preact`, `vue`, `svelte`, `@angular/core`, `solid-js`, `lit`, `next`, `nuxt`: `eslint-plugin-browser-security`
70
+ - `jsonwebtoken`, `jose`, `express-jwt`, `@nestjs/jwt`, `jwks-rsa`, `jwt-decode`: `eslint-plugin-jwt-security`
71
+ - `pg`, `pg-pool`, `pg-promise`, `postgres`, `slonik`: `eslint-plugin-postgresql-security`
72
+ - `mysql2`, `mysql`: `eslint-plugin-mysql-security`
73
+ - `mongodb`, `mongoose`: `eslint-plugin-mongodb-security`
74
+ - `better-sqlite3`, `sqlite3`: `eslint-plugin-sqlite-security`
75
+ - `knex`: `eslint-plugin-knex-security`
76
+ - `@prisma/client`, `prisma`: `eslint-plugin-prisma-security`
77
+ - `drizzle-orm`: `eslint-plugin-drizzle-security`
78
+ - `sequelize`: `eslint-plugin-sequelize-security`
79
+ - `typeorm`: `eslint-plugin-typeorm-security`
80
+ - `@supabase/supabase-js`: `eslint-plugin-supabase-security`
81
+ - `@modelcontextprotocol/*`: `eslint-plugin-mcp-sdk-security`
82
+ - `openai`, `@openai/agents`: `eslint-plugin-openai-security`
83
+ - `@anthropic-ai/sdk`, `@anthropic-ai/claude-agent-sdk`: `eslint-plugin-anthropic-security`
84
+ - `@google/genai`: `eslint-plugin-gemini-security`
85
+ - `ai`: `eslint-plugin-vercel-ai-security`
86
+ - `aws-lambda`, `@types/aws-lambda`, `@middy/core`: `eslint-plugin-lambda-security`
87
+
88
+ The full stack-to-plugin playbook (with config rendering and a proof step) is the `security-linting` skill: https://github.com/ofri-peretz/eslint/tree/main/skills/security-linting
89
+
90
+ ## More
91
+
92
+ - Docs: https://eslint.interlace.tools/docs/security/plugin-grpc-security
93
+ - README.md in this package: every rule with examples.
94
+ - `eslint-plugin-grpc-security/oxlint` is an entry point for oxlint's JS plugin support; see the README.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ofri Peretz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,231 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://eslint.interlace.tools/docs/security/plugin-grpc-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="90" /></picture></a>
3
+ &nbsp;&nbsp;
4
+ <a href="https://oxc.rs" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/oxlint-dark.svg"><img src="https://eslint.interlace.tools/logos/oxlint-light.svg" alt="oxlint" height="90" /></picture></a>
5
+ &nbsp;&nbsp;
6
+ <a href="https://eslint.org" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/eslint-dark.svg"><img src="https://eslint.interlace.tools/logos/eslint-light.svg" alt="ESLint" height="90" /></picture></a>
7
+ </p>
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ <p align="center">
10
+ Security rules for Node gRPC servers built on <a href="https://www.npmjs.com/package/@grpc/grpc-js">@grpc/grpc-js</a>.
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://www.npmjs.com/package/eslint-plugin-grpc-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-grpc-security.svg" alt="NPM Version" /></a>
15
+ <a href="https://www.npmjs.com/package/eslint-plugin-grpc-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-grpc-security.svg" alt="NPM Downloads" /></a>
16
+ <a href="https://packagephobia.com/result?p=eslint-plugin-grpc-security" target="_blank"><img src="https://badgen.net/packagephobia/install/eslint-plugin-grpc-security" alt="Install Size" /></a>
17
+ <a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
18
+ <a href="https://scorecard.dev/viewer/?uri=github.com/ofri-peretz/eslint" target="_blank"><img src="https://api.securityscorecards.dev/projects/github.com/ofri-peretz/eslint/badge" alt="OpenSSF Scorecard" /></a>
19
+ </p>
20
+
21
+ ## Getting Started
22
+
23
+ - To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-grpc-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security). 📚
24
+
25
+ <!-- AUTO-GENERATED:INSTALL:START - Do not edit manually -->
26
+
27
+ ```bash
28
+ npm install --save-dev eslint eslint-plugin-grpc-security
29
+ ```
30
+
31
+ ```js
32
+ // eslint.config.mjs
33
+ import { configs } from 'eslint-plugin-grpc-security';
34
+
35
+ export default [configs.recommended];
36
+ ```
37
+
38
+ `recommended` is the preset to start with. The others are listed under Configuration Presets below.
39
+
40
+ Using oxlint or Vite+? Install `oxlint-plugin-grpc-security`: the same rules under the same `grpc-security/<rule>` IDs, without ESLint. Its [page](https://www.npmjs.com/package/oxlint-plugin-grpc-security) has the setup.
41
+
42
+ <!-- AUTO-GENERATED:INSTALL:END -->
43
+
44
+ ## Description
45
+
46
+ Security rules for Node gRPC servers and clients (unguarded reflection, identity read from metadata, unbounded message sizes, error details, plaintext transport, credential logging, call deadlines).
47
+
48
+ They target servers built on [@grpc/grpc-js](https://www.npmjs.com/package/@grpc/grpc-js).
49
+
50
+ **Scope:** every rule gates on gRPC structure, never on a method name alone. `no-unguarded-reflection` needs a reflection package imported and the call resolved to it. `no-identity-from-metadata` needs a gRPC handler: a method of the object passed to `.addService(service, implementation)` whose first parameter's `metadata` is read. Servers often load `@grpc/grpc-js` through a wrapper module, so this rule does not require the import itself.
51
+
52
+ The first rule is `no-unguarded-reflection`. Server reflection answers "which services does this listener serve?" to any client, unauthenticated. Registered unconditionally it ships to production, and `grpcurl -plaintext host:port list` then names every service on the server, the internal ones included. The rule reports a registration with no branch between it and the program running, and stays silent once any branch decides it (`if (process.env.NODE_ENV !== 'production')`, a config flag, an early return).
53
+
54
+ `no-identity-from-metadata` catches the backend that believes a header a gateway was supposed to set. A value read from a handler's `call.metadata` that reaches an equality check against a per-request record (`acc.owner !== user`) is the caller's identity, and any client can send it. Resolving the header through a server-side lookup or a verifier ends the flow, so the rule stays silent on a verified token.
55
+
56
+ `no-unbounded-message-size` reports `grpc.max_receive_message_length` / `grpc.max_send_message_length` set to `-1` or above 100 MiB, evaluated from literals, arithmetic and consts. `no-error-detail-leak` reports a status sent through a handler's callback or call object whose `details` are built from a caught error's stack or message.
57
+
58
+ `no-insecure-server-credentials` reports `ServerCredentials.createInsecure()` bound to a wildcard address or a bare port, and stays silent on loopback, unix sockets and configured hosts. `no-insecure-channel-credentials` reports a `credentials.createInsecure()` channel only when the file sends a credential header over it.
59
+
60
+ `no-credential-metadata-logging` reports a log call that receives gRPC metadata, a dump of it, or a credential header's value. `require-call-deadline` (strict only) reports a client call with no `deadline` in its options.
61
+
62
+ <!-- AUTO-GENERATED:DOCTRINE:START - Do not edit manually -->
63
+
64
+ - **Why** — a linter nobody reads protects nothing. We would rather miss a finding
65
+ than spend your attention on one that was never real.
66
+ - **How** — evidence, not names. A rule fires on what the code _does_, resolved
67
+ through the AST and ESLint's own scope analysis.
68
+ - **What** — every finding carries its fix, in prose for a human and as structured
69
+ JSON for an agent. Security rules add a CWE mapping and, where assigned, a CVSS score.
70
+
71
+ That trade costs recall, and we measure it:
72
+ [methodology](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-METHODOLOGY.md)
73
+ · [results](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-RESULTS.md)
74
+ · [a false positive is a bug](https://github.com/ofri-peretz/eslint/issues).
75
+
76
+ <!-- AUTO-GENERATED:DOCTRINE:END -->
77
+
78
+ ## ⚙️ Configuration Presets
79
+
80
+ | Preset | Description |
81
+ | :------------ | :----------------------------------------- |
82
+ | `minimal` | `no-unguarded-reflection`. |
83
+ | `recommended` | Every rule except `require-call-deadline`. |
84
+ | `strict` | Every rule. |
85
+
86
+ ## Usage
87
+
88
+ ```js
89
+ // eslint.config.js
90
+ import grpcSecurity from 'eslint-plugin-grpc-security';
91
+
92
+ export default [grpcSecurity.configs.recommended];
93
+ ```
94
+
95
+ Or wire the rules yourself:
96
+
97
+ ```js
98
+ import grpcSecurity from 'eslint-plugin-grpc-security';
99
+
100
+ export default [
101
+ {
102
+ plugins: { 'grpc-security': grpcSecurity },
103
+ rules: {
104
+ 'grpc-security/no-unguarded-reflection': 'error',
105
+ },
106
+ },
107
+ ];
108
+ ```
109
+
110
+ ### oxlint
111
+
112
+ Every rule in this plugin runs on [oxlint](https://oxc.rs) as well as ESLint:
113
+
114
+ ```json
115
+ { "jsPlugins": ["eslint-plugin-grpc-security/oxlint"] }
116
+ ```
117
+
118
+ ## 📦 Compatibility
119
+
120
+ | Package | Version |
121
+ | :----------------- | :---------------------------------------------------------------------------------------------------------------------------- |
122
+ | `@grpc/reflection` | [![npm](https://img.shields.io/npm/v/@grpc/reflection.svg?style=flat-square)](https://www.npmjs.com/package/@grpc/reflection) |
123
+ | ESLint | [![npm](https://img.shields.io/npm/v/eslint.svg?style=flat-square)](https://www.npmjs.com/package/eslint) |
124
+ | Node.js | [![node](https://img.shields.io/badge/node-%5E18.0.0-green?style=flat-square)](https://nodejs.org/) |
125
+
126
+ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) for the full matrix.
127
+
128
+ ### Supported library versions
129
+
130
+ The library ranges the rules were written against. Documentation only: this package installs and requires none of them.
131
+
132
+ - `@grpc/reflection`: `^1.0.0`
133
+ - `grpc-server-reflection`: `^0.1.0`
134
+
135
+ ## Rules
136
+
137
+ **Legend**
138
+
139
+ | Icon | Description |
140
+ | :--: | :------------------------------------------------------------------------ |
141
+ | 💼 | **Recommended**: Included in the recommended preset. |
142
+ | ⚠️ | **Warns**: Set to warn in recommended preset. |
143
+ | 🔧 | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
144
+ | 💡 | **Suggestions**: Providing code suggestions in IDE. |
145
+ | 🚫 | **Deprecated**: This rule is deprecated. |
146
+ | 🟢 | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
147
+ | 🟡 | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
148
+ | 🟠 | **Type-aware (graceful)**: requires TS program; silent without it. |
149
+
150
+ <!-- AUTO-GENERATED:RULES_TABLE:START - Do not edit manually -->
151
+
152
+ | Rule | CWE | OWASP | CVSS | Description | 🧠 | 💼 | ⚠️ | 🔧 | 💡 | 🚫 |
153
+ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-----: | :------: | :--: | :--------------------------------------------------------------- | :-: | :-: | :-: | :-: | :-: | :-: |
154
+ | [no-credential-metadata-logging](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-credential-metadata-logging?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-532 | A09:2021 | | Do not log gRPC metadata that carries credentials | 🟢 | | | | | |
155
+ | [no-error-detail-leak](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-error-detail-leak?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-209 | A05:2021 | | Do not send a caught error's stack or message to the gRPC client | 🟢 | | | | | |
156
+ | [no-identity-from-metadata](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-identity-from-metadata?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-290 | A07:2021 | | Do not authorize a gRPC caller by an identity read from metadata | 🟢 | | | | | |
157
+ | [no-insecure-channel-credentials](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-insecure-channel-credentials?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-319 | A02:2021 | | Do not send credentials over a plaintext gRPC channel | 🟢 | | | | | |
158
+ | [no-insecure-server-credentials](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-insecure-server-credentials?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-319 | A02:2021 | | Do not serve plaintext gRPC on every interface | 🟢 | | | | | |
159
+ | [no-unbounded-message-size](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-unbounded-message-size?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-770 | A04:2021 | | Keep gRPC message size limits bounded | 🟢 | | | | | |
160
+ | [no-unguarded-reflection](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/no-unguarded-reflection?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-306 | A05:2021 | | Register gRPC server reflection only behind a guard | 🟢 | | | | | |
161
+ | [require-call-deadline](https://eslint.interlace.tools/docs/security/plugin-grpc-security/rules/require-call-deadline?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security) | CWE-400 | A04:2021 | | Give every gRPC client call a deadline | 🟢 | | | | | |
162
+
163
+ <!-- AUTO-GENERATED:RULES_TABLE:END -->
164
+ <!-- INTERLACE:STAR_CTA:START -->
165
+
166
+ ## Support
167
+
168
+ Found a false positive? [Open an issue](https://github.com/ofri-peretz/eslint/issues): that is a bug. If the plugin helped, a star on [ofri-peretz/eslint](https://github.com/ofri-peretz/eslint) helps others find it.
169
+
170
+ <!-- INTERLACE:STAR_CTA:END -->
171
+
172
+ <!-- AUTO-GENERATED:ECOSYSTEM_TABLE:START - Do not edit manually -->
173
+
174
+ ## 🔗 Related ESLint Plugins
175
+
176
+ Part of the **Interlace ESLint ecosystem** — AI-native rules with LLM-optimized error messages:
177
+
178
+ **Security**
179
+
180
+ | Plugin | Downloads | Description |
181
+ | :----------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------- |
182
+ | [`eslint-plugin-anthropic-security`](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-anthropic-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | Anthropic SDK security. |
183
+ | [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-browser-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-browser-security) | XSS, DOM security. |
184
+ | [`eslint-plugin-drizzle-security`](https://www.npmjs.com/package/eslint-plugin-drizzle-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-drizzle-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-drizzle-security) | Drizzle security. |
185
+ | [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-express-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-express-security) | Express middleware hardening. |
186
+ | [`eslint-plugin-gemini-security`](https://www.npmjs.com/package/eslint-plugin-gemini-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-gemini-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-gemini-security) | Google Gemini SDK security. |
187
+ | [`eslint-plugin-jwt-security`](https://www.npmjs.com/package/eslint-plugin-jwt-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-jwt-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-jwt-security) | Token security. |
188
+ | [`eslint-plugin-knex-security`](https://www.npmjs.com/package/eslint-plugin-knex-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-knex-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-knex-security) | Knex security. |
189
+ | [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-lambda-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda hardening. |
190
+ | [`eslint-plugin-mcp-sdk-security`](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-mcp-sdk-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | MCP SDK security. |
191
+ | [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-mongodb-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB injection. |
192
+ | [`eslint-plugin-mysql-security`](https://www.npmjs.com/package/eslint-plugin-mysql-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-mysql-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-mysql-security) | MySQL security. |
193
+ | [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-nestjs-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS framework hardening. |
194
+ | [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-node-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-node-security) | Server-side patterns. |
195
+ | [`eslint-plugin-openai-security`](https://www.npmjs.com/package/eslint-plugin-openai-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-openai-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-openai-security) | OpenAI SDK security. |
196
+ | [`eslint-plugin-postgresql-security`](https://www.npmjs.com/package/eslint-plugin-postgresql-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-postgresql-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-postgresql-security) | PostgreSQL security. |
197
+ | [`eslint-plugin-prisma-security`](https://www.npmjs.com/package/eslint-plugin-prisma-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-prisma-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-prisma-security) | Prisma security. |
198
+ | [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-secure-coding.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-secure-coding) | Injection prevention. |
199
+ | [`eslint-plugin-sequelize-security`](https://www.npmjs.com/package/eslint-plugin-sequelize-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-sequelize-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-sequelize-security) | Sequelize ORM security. |
200
+ | [`eslint-plugin-sqlite-security`](https://www.npmjs.com/package/eslint-plugin-sqlite-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-sqlite-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-sqlite-security) | SQLite security. |
201
+ | [`eslint-plugin-supabase-security`](https://www.npmjs.com/package/eslint-plugin-supabase-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-supabase-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-supabase-security) | Supabase security. |
202
+ | [`eslint-plugin-typeorm-security`](https://www.npmjs.com/package/eslint-plugin-typeorm-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-typeorm-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-typeorm-security) | TypeORM security. |
203
+ | [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-vercel-ai-security.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | AI SDK security. |
204
+
205
+ **Code quality**
206
+
207
+ | Plugin | Downloads | Description |
208
+ | :--------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------- |
209
+ | [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-conventions.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
210
+ | [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-import-next.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
211
+ | [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-maintainability.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
212
+ | [`eslint-plugin-modernization`](https://www.npmjs.com/package/eslint-plugin-modernization) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-modernization.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-modernization) | ESNext migration + syntax evolution. |
213
+ | [`eslint-plugin-modularity`](https://www.npmjs.com/package/eslint-plugin-modularity) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-modularity.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-modularity) | Structural integrity and DDD patterns. |
214
+ | [`eslint-plugin-operability`](https://www.npmjs.com/package/eslint-plugin-operability) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-operability.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-operability) | Production readiness and resource health. |
215
+ | [`eslint-plugin-react-a11y`](https://www.npmjs.com/package/eslint-plugin-react-a11y) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-react-a11y.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-react-a11y) | React accessibility / WCAG. |
216
+ | [`eslint-plugin-react-features`](https://www.npmjs.com/package/eslint-plugin-react-features) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-react-features.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-react-features) | React best practices and optimization. |
217
+ | [`eslint-plugin-reliability`](https://www.npmjs.com/package/eslint-plugin-reliability) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-reliability.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-reliability) | Runtime stability and error safety. |
218
+
219
+ <!-- AUTO-GENERATED:ECOSYSTEM_TABLE:END -->
220
+
221
+ ## 📄 License
222
+
223
+ MIT © [Ofri Peretz](https://github.com/ofri-peretz)
224
+
225
+ <p align="center">
226
+ <a href="https://eslint.interlace.tools/docs/security/plugin-grpc-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security"><img src="https://eslint.interlace.tools/images/og-grpc-security.png" alt="ESLint Interlace Plugin" width="100%" /></a>
227
+ </p>
228
+
229
+ <p align="center">
230
+ <a href="https://eslint.interlace.tools/docs/security/plugin-grpc-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="70" /></picture></a>
231
+ </p>
package/package.json CHANGED
@@ -1,6 +1,84 @@
1
1
  {
2
2
  "name": "eslint-plugin-grpc-security",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "ESLint gRPC security rules — catches server reflection registered with no guard, a caller identity read from client-settable metadata, message size limits removed, caught errors sent to the client, plaintext transport that is exposed or carries secrets, credentials written to logs, and calls with no deadline.",
5
+ "type": "commonjs",
6
+ "sideEffects": false,
7
+ "main": "./src/index.js",
8
+ "types": "./src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.d.ts",
12
+ "default": "./src/index.js"
13
+ },
14
+ "./oxlint": {
15
+ "types": "./src/oxlint.d.ts",
16
+ "default": "./src/oxlint.js"
17
+ }
18
+ },
19
+ "author": "Ofri Peretz <ofriperetzdev@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://eslint.interlace.tools/docs/security/plugin-grpc-security?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-grpc-security",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/ofri-peretz/eslint.git",
25
+ "directory": "packages/eslint-plugin-grpc-security"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/ofri-peretz/eslint/issues"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "files": [
34
+ "src/",
35
+ "README.md",
36
+ "LICENSE",
37
+ "AGENTS.md"
38
+ ],
39
+ "keywords": [
40
+ "eslint",
41
+ "eslintplugin",
42
+ "eslint-plugin",
43
+ "static-analysis",
44
+ "linting",
45
+ "code-quality",
46
+ "security",
47
+ "sast",
48
+ "appsec",
49
+ "vulnerability",
50
+ "owasp",
51
+ "cwe",
52
+ "interlace-security",
53
+ "grpc",
54
+ "grpc-js",
55
+ "grpc-security",
56
+ "grpc-reflection",
57
+ "protobuf",
58
+ "typescript"
59
+ ],
60
+ "engines": {
61
+ "node": ">=22.13.0"
62
+ },
63
+ "peerDependencies": {
64
+ "eslint": "^8.40.0 || ^9.0.0 || ^10.0.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "eslint": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "dependencies": {
72
+ "@interlace/eslint-devkit": "^2.5.3"
73
+ },
74
+ "interlace": {
75
+ "surface": {
76
+ "kind": "npm",
77
+ "modules": [
78
+ "@grpc/grpc-js",
79
+ "@grpc/reflection",
80
+ "grpc-server-reflection"
81
+ ]
82
+ }
83
+ }
84
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=exports.requireCallDeadline=exports.noUnguardedReflection=exports.noUnboundedMessageSize=exports.noInsecureServerCredentials=exports.noInsecureChannelCredentials=exports.noIdentityFromMetadata=exports.noErrorDetailLeak=exports.noCredentialMetadataLogging=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");var no_credential_metadata_logging_2=require("./rules/no-credential-metadata-logging");Object.defineProperty(exports,"noCredentialMetadataLogging",{enumerable:true,get:function(){return no_credential_metadata_logging_2.noCredentialMetadataLogging}});var no_error_detail_leak_2=require("./rules/no-error-detail-leak");Object.defineProperty(exports,"noErrorDetailLeak",{enumerable:true,get:function(){return no_error_detail_leak_2.noErrorDetailLeak}});var no_identity_from_metadata_2=require("./rules/no-identity-from-metadata");Object.defineProperty(exports,"noIdentityFromMetadata",{enumerable:true,get:function(){return no_identity_from_metadata_2.noIdentityFromMetadata}});var no_insecure_channel_credentials_2=require("./rules/no-insecure-channel-credentials");Object.defineProperty(exports,"noInsecureChannelCredentials",{enumerable:true,get:function(){return no_insecure_channel_credentials_2.noInsecureChannelCredentials}});var no_insecure_server_credentials_2=require("./rules/no-insecure-server-credentials");Object.defineProperty(exports,"noInsecureServerCredentials",{enumerable:true,get:function(){return no_insecure_server_credentials_2.noInsecureServerCredentials}});var no_unbounded_message_size_2=require("./rules/no-unbounded-message-size");Object.defineProperty(exports,"noUnboundedMessageSize",{enumerable:true,get:function(){return no_unbounded_message_size_2.noUnboundedMessageSize}});var no_unguarded_reflection_2=require("./rules/no-unguarded-reflection");Object.defineProperty(exports,"noUnguardedReflection",{enumerable:true,get:function(){return no_unguarded_reflection_2.noUnguardedReflection}});var require_call_deadline_2=require("./rules/require-call-deadline");Object.defineProperty(exports,"requireCallDeadline",{enumerable:true,get:function(){return require_call_deadline_2.requireCallDeadline}});exports.rules={get"no-credential-metadata-logging"(){return require("./rules/no-credential-metadata-logging").noCredentialMetadataLogging},get"no-error-detail-leak"(){return require("./rules/no-error-detail-leak").noErrorDetailLeak},get"no-identity-from-metadata"(){return require("./rules/no-identity-from-metadata").noIdentityFromMetadata},get"no-insecure-channel-credentials"(){return require("./rules/no-insecure-channel-credentials").noInsecureChannelCredentials},get"no-insecure-server-credentials"(){return require("./rules/no-insecure-server-credentials").noInsecureServerCredentials},get"no-unguarded-reflection"(){return require("./rules/no-unguarded-reflection").noUnguardedReflection},get"no-unbounded-message-size"(){return require("./rules/no-unbounded-message-size").noUnboundedMessageSize},get"require-call-deadline"(){return require("./rules/require-call-deadline").requireCallDeadline}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-grpc-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-grpc-security",version:"0.5.0"},rules:exports.rules};const minimalConfig={plugins:{"grpc-security":exports.plugin},rules:{"grpc-security/no-unguarded-reflection":"error"}};const recommendedConfig={plugins:{"grpc-security":exports.plugin},rules:{"grpc-security/no-unguarded-reflection":"error","grpc-security/no-identity-from-metadata":"error","grpc-security/no-unbounded-message-size":"error","grpc-security/no-error-detail-leak":"error","grpc-security/no-insecure-server-credentials":"error","grpc-security/no-insecure-channel-credentials":"error","grpc-security/no-credential-metadata-logging":"error"}};const strictConfig={plugins:{"grpc-security":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`grpc-security/${ruleName}`,"error"]))};exports.configs={minimal:minimalConfig,recommended:recommendedConfig,strict:strictConfig};exports.default={...exports.plugin,configs:exports.configs};
@@ -0,0 +1,17 @@
1
+ // Minimal declaration written by scripts/build-package.ts.
2
+ //
3
+ // tsc's generated entry declaration inlined every inferred rule-option type
4
+ // (up to 166 kB per plugin) for an API no consumer calls directly. This types
5
+ // what a flat config actually touches. Per-rule option types remain available
6
+ // from the "./types" subpath export where a plugin provides one.
7
+ import type { Linter, Rule } from 'eslint';
8
+
9
+ export declare const rules: Record<string, Rule.RuleModule>;
10
+ export declare const configs: Record<string, Linter.Config>;
11
+ export declare const plugin: {
12
+ meta: { name: string; version: string };
13
+ rules: Record<string, Rule.RuleModule>;
14
+ };
15
+
16
+ declare const _default: typeof plugin;
17
+ export default _default;
package/src/oxlint.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";const index_1=require("./index");module.exports=index_1.plugin;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCredentialMetadataLogging=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_credentials_1=require("../../utils/grpc-credentials");const grpc_flow_1=require("../../utils/grpc-flow");const LOGGING_LIBRARIES=new Set(["pino","winston","bunyan","log4js","loglevel","consola","signale"]);const DUMPS=new Set(["getMap","toJSON","toHttp2Headers"]);function fromLoggingLibrary(node,sourceCode){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node,sourceCode.getScope(node));return binding!==void 0&&LOGGING_LIBRARIES.has(binding.module)}function isLogger(node,sourceCode){if(node.type!=="Identifier")return false;if(node.name==="console"&&(0,eslint_devkit_1.isGlobalReference)(node,sourceCode)){return true}if(fromLoggingLibrary(node,sourceCode))return true;const init=(0,grpc_credentials_1.followConst)(node,sourceCode);return init.type==="CallExpression"&&fromLoggingLibrary(init.callee,sourceCode)}function isMetadata(node,sourceCode){return(0,grpc_flow_1.isCallMetadata)(node,sourceCode,grpc_flow_1.MAX_HOPS)||(0,grpc_credentials_1.isNewMetadata)((0,grpc_credentials_1.followConst)(node,sourceCode),sourceCode)}function isDump(node,sourceCode){const call=(0,grpc_credentials_1.followConst)(node,sourceCode);return call.type==="CallExpression"&&call.callee.type==="MemberExpression"&&DUMPS.has((0,eslint_devkit_1.propertyName)(call.callee)??"")&&isMetadata(call.callee.object,sourceCode)}function isCredentialName(node,sourceCode){if(node===void 0)return false;const{text,complete}=(0,grpc_credentials_1.staticPrefix)(node,sourceCode);return complete&&grpc_credentials_1.CREDENTIAL_HEADERS.has(text.toLowerCase())}function isCredentialGet(node,sourceCode){const call=(0,grpc_credentials_1.followConst)(node,sourceCode);return call.type==="CallExpression"&&call.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(call.callee)==="get"&&isMetadata(call.callee.object,sourceCode)&&isCredentialName(call.arguments[0],sourceCode)}function leaks(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){if(hops<=0)return false;const any=children=>children.some(child=>child!==null&&leaks(child,sourceCode,hops-1));if(isMetadata(node,sourceCode)||isDump(node,sourceCode))return true;if(isCredentialGet(node,sourceCode))return true;switch(node.type){case"Identifier":{const init=(0,grpc_credentials_1.followConst)(node,sourceCode);return init!==node&&any([init])}case"MemberExpression":{if(isDump(node.object,sourceCode)){return grpc_credentials_1.CREDENTIAL_HEADERS.has(((0,eslint_devkit_1.propertyName)(node)??"").toLowerCase())}return node.computed&&node.property.type==="Literal"&&typeof node.property.value==="number"&&isCredentialGet(node.object,sourceCode)}case"CallExpression":{const{callee}=node;const wraps=callee.type==="Identifier"&&callee.name==="String"&&(0,eslint_devkit_1.isGlobalReference)(callee,sourceCode)||callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&callee.object.name==="JSON"&&(0,eslint_devkit_1.isGlobalReference)(callee.object,sourceCode)&&(0,eslint_devkit_1.propertyName)(callee)==="stringify";return wraps&&any(node.arguments)}case"ObjectExpression":return any(node.properties.map(p=>p.type==="Property"?p.value:p.argument));case"ArrayExpression":return any(node.elements);case"TemplateLiteral":return any(node.expressions);case"SpreadElement":return any([node.argument]);case"ConditionalExpression":return any([node.consequent,node.alternate]);case"LogicalExpression":return any([node.left,node.right]);case"BinaryExpression":return node.operator==="+"&&any([node.left,node.right]);default:return false}}exports.noCredentialMetadataLogging=(0,eslint_devkit_1.createRule)({name:"no-credential-metadata-logging",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-credential-metadata-logging.md",description:"Do not log gRPC metadata that carries credentials",cwe:"CWE-532",cvss:6.5},messages:{credentialLogged:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"gRPC Credentials Written to Logs",cwe:"CWE-532",owasp:"A09:2021",cvss:6.5,description:"A log call receives gRPC metadata (the whole object, a dump of it, or a credential header), which writes the caller\u2019s token, cookie or API key into the logs",severity:"MEDIUM",compliance:["SOC2","PCI-DSS","ISO27001"],fix:"Log only the headers you need, by name, and never authorization, cookie or API-key values. If the logger takes whole objects, configure its redaction (pino `redact`, winston format) for those keys.",documentationLink:"https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/"})},schema:[]},defaultOptions:[],createOnce(context){return{CallExpression(node){const{callee}=node;const{sourceCode}=context;if(callee.type!=="MemberExpression")return;if(!isLogger(callee.object,sourceCode))return;for(const arg of node.arguments){if(leaks(arg,sourceCode)){context.report({node:arg,messageId:"credentialLogged"})}}}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noErrorDetailLeak=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_flow_1=require("../../utils/grpc-flow");const ERROR_TEXT=new Set(["stack","message"]);function isCaughtError(id,sourceCode){const def=(0,grpc_flow_1.definitionOf)(id,sourceCode);if(def?.type==="CatchClause")return true;if(def?.type!=="Parameter")return false;const fn=def.node;const call=fn.parent;return fn.params[0]===def.name&&call.type==="CallExpression"&&call.arguments[0]===fn&&call.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(call.callee)==="catch"}function carriesCaughtError(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){if(hops<=0)return false;const carries=child=>carriesCaughtError(child,sourceCode,hops-1);switch(node.type){case"Identifier":{if(isCaughtError(node,sourceCode))return true;const def=(0,grpc_flow_1.definitionOf)(node,sourceCode);const init=def?.type==="Variable"?def.node.init:null;return init!==null&&carries(init)}case"MemberExpression":{const key=(0,eslint_devkit_1.propertyName)(node);return key!==null&&ERROR_TEXT.has(key)&&carries(node.object)}case"CallExpression":{const{callee}=node;if(callee.type==="MemberExpression"){return(0,eslint_devkit_1.propertyName)(callee)==="toString"&&carries(callee.object)}return callee.type==="Identifier"&&callee.name==="String"&&(0,eslint_devkit_1.isGlobalReference)(callee,sourceCode)&&node.arguments.some(carries)}case"TemplateLiteral":return node.expressions.some(carries);case"BinaryExpression":return node.operator==="+"&&(carries(node.left)||carries(node.right));case"LogicalExpression":return carries(node.left)||carries(node.right);case"ConditionalExpression":return carries(node.consequent)||carries(node.alternate);default:return false}}function isHandlerParam(id,index,sourceCode){if(id.type!=="Identifier")return false;const def=(0,grpc_flow_1.definitionOf)(id,sourceCode);if(def?.type!=="Parameter")return false;const fn=def.node;return(0,grpc_flow_1.isFunction)(fn)&&fn.params[index]===def.name&&(0,grpc_flow_1.isHandler)(fn,sourceCode)}function sentStatus(call,sourceCode){const{callee}=call;if(isHandlerParam(callee,1,sourceCode))return call.arguments[0];if(callee.type!=="MemberExpression"||!isHandlerParam(callee.object,0,sourceCode)){return void 0}const method=(0,eslint_devkit_1.propertyName)(callee);if(method==="destroy")return call.arguments[0];const[event,status]=call.arguments;return method==="emit"&&event?.type==="Literal"&&event.value==="error"?status:void 0}exports.noErrorDetailLeak=(0,eslint_devkit_1.createRule)({name:"no-error-detail-leak",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-error-detail-leak.md",description:"Do not send a caught error's stack or message to the gRPC client",cwe:"CWE-209",cvss:5.3},messages:{errorDetailLeak:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Caught Error Sent to the gRPC Client",cwe:"CWE-209",owasp:"A05:2021",cvss:5.3,description:"A gRPC status sent to the client is built from a caught error's stack or message, which can carry file paths, queries and internal hosts",severity:"MEDIUM",compliance:["SOC2","ISO27001"],fix:"Log the caught error server-side and send a fixed message: `cb({ code: grpc.status.INTERNAL, details: 'internal error' })`. Map the errors you expect to their own status codes and messages.",documentationLink:"https://grpc.io/docs/guides/error/"})},schema:[]},defaultOptions:[],createOnce(context){return{CallExpression(node){const{sourceCode}=context;const status=sentStatus(node,sourceCode);if(status===void 0)return;const object=(0,eslint_devkit_1.resolveObjectLiteral)(status,sourceCode);if(object===void 0)return;for(const key of["details","message"]){const read=(0,eslint_devkit_1.readObjectProperty)(object,key,sourceCode);if(read.kind!=="value")continue;if(!carriesCaughtError(read.node,sourceCode))continue;context.report({node:read.node,messageId:"errorDetailLeak"})}}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noIdentityFromMetadata=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_flow_1=require("../../utils/grpc-flow");const EQUALITY=new Set(["===","!==","==","!="]);function metadataOrigins(node,sourceCode,hops,seen){if(hops<=0||seen.has(node))return[];seen.add(node);const next=child=>metadataOrigins(child,sourceCode,hops-1,seen);switch(node.type){case"Identifier":{const def=(0,grpc_flow_1.definitionOf)(node,sourceCode);if(def?.type==="Parameter"){const fn=def.node;const index=fn.params.indexOf(def.name);return(0,grpc_flow_1.callSitesOf)(fn,sourceCode).flatMap(call=>call.arguments[index]?next(call.arguments[index]):[])}if(def?.type!=="Variable")return[];const{init}=def.node;return init?next(init):[]}case"MemberExpression":return next(node.object);case"ChainExpression":case"TSAsExpression":case"TSNonNullExpression":return next(node.expression);case"AwaitExpression":return next(node.argument);case"TemplateLiteral":return node.expressions.flatMap(next);case"LogicalExpression":return[...next(node.left),...next(node.right)];case"ConditionalExpression":return[...next(node.consequent),...next(node.alternate)];case"CallExpression":{const{callee}=node;if(callee.type==="MemberExpression"){if((0,eslint_devkit_1.propertyName)(callee)==="get"&&(0,grpc_flow_1.isCallMetadata)(callee.object,sourceCode,grpc_flow_1.MAX_HOPS)){return[node]}return next(callee.object)}if((0,grpc_flow_1.isFunction)(callee))return(0,grpc_flow_1.returnsOf)(callee).flatMap(next);if(callee.type!=="Identifier")return[];if(callee.name==="String"&&(0,eslint_devkit_1.isGlobalReference)(callee,sourceCode)){return node.arguments.flatMap(next)}const fn=(0,grpc_flow_1.functionOf)(callee,sourceCode);return fn?(0,grpc_flow_1.returnsOf)(fn).flatMap(next):[]}default:return[]}}function rootOf(node){let current=node;while(current.type==="MemberExpression")current=current.object;return current}function isRecordField(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){if(hops<=0)return false;if(node.type==="Identifier"){const def=(0,grpc_flow_1.definitionOf)(node,sourceCode);const init=def?.type==="Variable"?def.node.init:null;return init!==null&&isRecordField(init,sourceCode,hops-1)}if(node.type!=="MemberExpression")return false;const root=rootOf(node);if(root.type==="AwaitExpression"||root.type==="CallExpression"){return true}if(root.type!=="Identifier")return false;const variable=(0,eslint_devkit_1.variableOf)(root,sourceCode);if(variable===void 0||variable.defs.length===0){return root.name!=="process"}return variable.scope.type!=="module"&&variable.scope.type!=="global"}function decidesABranch(node){let child=node;let parent=node.parent;while(parent!=null&&!(0,grpc_flow_1.isFunction)(parent)&&!parent.type.endsWith("Statement")){if(parent.type==="ConditionalExpression"&&parent.test===child){return true}child=parent;parent=parent.parent}return parent?.type==="IfStatement"&&parent.test===child}exports.noIdentityFromMetadata=(0,eslint_devkit_1.createRule)({name:"no-identity-from-metadata",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-identity-from-metadata.md",description:"Do not authorize a gRPC caller by an identity read from metadata",cwe:"CWE-290",cvss:8.1},messages:{identityFromMetadata:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"gRPC Caller Identity Taken From Client-Set Metadata",cwe:"CWE-290",owasp:"A07:2021",cvss:8.1,description:"A value read from call metadata reaches an authorization check as the caller\u2019s identity, and any client can set any metadata header",severity:"HIGH",compliance:["SOC2","ISO27001"],fix:"Authenticate every call in the backend: resolve the caller from a credential you verify (a signed token, an mTLS peer certificate), never from a header a gateway is supposed to set. If a gateway hop must carry identity, authenticate the hop (mTLS) or sign the header.",documentationLink:"https://grpc.io/docs/guides/auth/"})},schema:[]},defaultOptions:[],createOnce(context){let reported=new Set;return{before(){reported=new Set;return true},BinaryExpression(node){if(!EQUALITY.has(node.operator))return;if(!decidesABranch(node))return;const{sourceCode}=context;const sides=[[node.left,node.right],[node.right,node.left]];for(const[identity,other]of sides){if(!isRecordField(other,sourceCode))continue;for(const read of metadataOrigins(identity,sourceCode,grpc_flow_1.MAX_HOPS,new Set)){if(reported.has(read))continue;reported.add(read);context.report({node:read,messageId:"identityFromMetadata"})}}}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInsecureChannelCredentials=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_credentials_1=require("../../utils/grpc-credentials");const grpc_flow_1=require("../../utils/grpc-flow");const HEADER_SETTERS=new Set(["add","set"]);function stableReferences(declarator,sourceCode){if(declarator.type!=="VariableDeclarator"||declarator.id.type!=="Identifier"){return[]}const refs=(0,grpc_flow_1.referencesOf)(declarator.id,declarator,sourceCode);if(refs.some(ref=>ref.isWrite()&&!ref.init))return[];return refs.map(ref=>ref.identifier)}function carriesCredential(arg,sourceCode){const created=(0,grpc_credentials_1.followConst)(arg,sourceCode);if(arg.type!=="Identifier"||!(0,grpc_credentials_1.isNewMetadata)(created,sourceCode)){return false}return stableReferences(created.parent,sourceCode).some(id=>{const member=id.parent;const call=member?.parent;return member?.type==="MemberExpression"&&member.object===id&&HEADER_SETTERS.has((0,eslint_devkit_1.propertyName)(member)??"")&&call?.type==="CallExpression"&&call.callee===member&&(0,grpc_credentials_1.isCredentialHeader)(call.arguments[0],call.arguments[1],sourceCode)})}exports.noInsecureChannelCredentials=(0,eslint_devkit_1.createRule)({name:"no-insecure-channel-credentials",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-insecure-channel-credentials.md",description:"Do not send credentials over a plaintext gRPC channel",cwe:"CWE-319",cvss:7.4},messages:{insecureChannel:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Credentials Sent Over a Plaintext gRPC Channel",cwe:"CWE-319",owasp:"A02:2021",cvss:7.4,description:"A client built with credentials.createInsecure() sends metadata carrying a credential, so the secret crosses the network in cleartext",severity:"HIGH",compliance:["SOC2","PCI-DSS","ISO27001"],fix:"Build the channel with credentials.createSsl() (or combineChannelCredentials(createSsl(), callCredentials)) whenever a call carries a token, cookie or API key.",documentationLink:"https://grpc.io/docs/guides/auth/"})},schema:[]},defaultOptions:[],createOnce(context){return{NewExpression(node){const{sourceCode}=context;const credentials=node.arguments[1];if(credentials===void 0||!(0,grpc_credentials_1.isInsecureCredentials)(credentials,"credentials",sourceCode)){return}const sendsSecret=stableReferences(node.parent,sourceCode).some(client=>{const member=client.parent;const call=member?.parent;return member?.type==="MemberExpression"&&member.object===client&&call?.type==="CallExpression"&&call.callee===member&&call.arguments.some(arg=>carriesCredential(arg,sourceCode))});if(sendsSecret){context.report({node:credentials,messageId:"insecureChannel"})}}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInsecureServerCredentials=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_credentials_1=require("../../utils/grpc-credentials");const BIND_METHODS=new Set(["bindAsync","bind"]);const WILDCARD_HOSTS=new Set(["","0.0.0.0","::"]);function isWildcardAddress(node,sourceCode){const{text,complete}=(0,grpc_credentials_1.staticPrefix)(node,sourceCode);let host;if(text.startsWith("[")){const end=text.indexOf("]");host=end<0?void 0:text.slice(1,end)}else if(text.includes(":")){host=text.slice(0,text.indexOf(":"))}else if(complete&&/^\d+$/.test(text)){host=""}return host!==void 0&&WILDCARD_HOSTS.has(host)}exports.noInsecureServerCredentials=(0,eslint_devkit_1.createRule)({name:"no-insecure-server-credentials",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-insecure-server-credentials.md",description:"Do not serve plaintext gRPC on every interface",cwe:"CWE-319",cvss:7.4},messages:{insecureServer:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Plaintext gRPC Server on Every Interface",cwe:"CWE-319",owasp:"A02:2021",cvss:7.4,description:"A gRPC server with ServerCredentials.createInsecure() is bound to a wildcard address, so every network the host is on can read and alter its traffic",severity:"HIGH",compliance:["SOC2","PCI-DSS","ISO27001"],fix:"Serve TLS with ServerCredentials.createSsl(rootCerts, keyCertPairs), or bind the plaintext server to loopback or a unix socket and put a TLS-terminating proxy in front of it.",documentationLink:"https://grpc.io/docs/guides/auth/"})},schema:[]},defaultOptions:[],createOnce(context){return{CallExpression(node){const{callee}=node;if(callee.type!=="MemberExpression")return;const method=(0,eslint_devkit_1.propertyName)(callee);if(method===null||!BIND_METHODS.has(method))return;const[address,credentials]=node.arguments;if(address===void 0||credentials===void 0)return;const{sourceCode}=context;if(!(0,grpc_credentials_1.isInsecureCredentials)(credentials,"ServerCredentials",sourceCode)){return}if(!isWildcardAddress(address,sourceCode))return;context.report({node:address,messageId:"insecureServer"})}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnboundedMessageSize=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_flow_1=require("../../utils/grpc-flow");const SIZE_KEYS=new Set(["grpc.max_receive_message_length","grpc.max_send_message_length"]);const MAX_REASONABLE_BYTES=100*1024*1024;const NUMBER_CONSTANTS={MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,MAX_VALUE:Number.MAX_VALUE,POSITIVE_INFINITY:Number.POSITIVE_INFINITY};function evaluate(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){if(hops<=0)return void 0;const value=child=>evaluate(child,sourceCode,hops-1);switch(node.type){case"Literal":return typeof node.value==="number"?node.value:void 0;case"UnaryExpression":{const operand=value(node.argument);if(operand===void 0)return void 0;return node.operator==="-"?-operand:node.operator==="+"?operand:void 0}case"BinaryExpression":{const left=value(node.left);const right=value(node.right);if(left===void 0||right===void 0)return void 0;switch(node.operator){case"*":return left*right;case"+":return left+right;case"-":return left-right;case"/":return left/right;case"**":return left**right;case"<<":return left*2**right;default:return void 0}}case"TSAsExpression":return value(node.expression);case"Identifier":{if(node.name==="Infinity"&&(0,eslint_devkit_1.isGlobalReference)(node,sourceCode)){return Infinity}const def=(0,grpc_flow_1.definitionOf)(node,sourceCode);const init=def?.type==="Variable"?def.node.init:null;return init?value(init):void 0}case"MemberExpression":{const key=(0,eslint_devkit_1.propertyName)(node);return node.object.type==="Identifier"&&node.object.name==="Number"&&(0,eslint_devkit_1.isGlobalReference)(node.object,sourceCode)&&key!==null?NUMBER_CONSTANTS[key]:void 0}default:return void 0}}function isUnbounded(node,sourceCode){const size=evaluate(node,sourceCode);if(size===void 0||Number.isNaN(size))return false;return size<0||size>MAX_REASONABLE_BYTES}exports.noUnboundedMessageSize=(0,eslint_devkit_1.createRule)({name:"no-unbounded-message-size",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-unbounded-message-size.md",description:"Keep gRPC message size limits bounded",cwe:"CWE-770",cvss:7.5},messages:{unboundedMessageSize:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"gRPC Message Size Limit Removed",cwe:"CWE-770",owasp:"A04:2021",cvss:7.5,description:"A gRPC message size limit is set to -1 (no limit) or above 100 MiB, so one message can make the process allocate that much memory",severity:"HIGH",compliance:["SOC2","ISO27001"],fix:"Set the limit to the largest message the service actually needs (gRPC defaults receive to 4 MiB). Stream large payloads in chunks instead of raising the cap.",documentationLink:"https://grpc.github.io/grpc/core/group__grpc__arg__keys.html"})},schema:[]},defaultOptions:[],createOnce(context){return{Property(node){const key=(0,eslint_devkit_1.objectKeyName)(node);if(key===null||!SIZE_KEYS.has(key))return;if(!isUnbounded(node.value,context.sourceCode))return;context.report({node:node.value,messageId:"unboundedMessageSize"})},AssignmentExpression(node){if(node.left.type!=="MemberExpression")return;const key=(0,eslint_devkit_1.propertyName)(node.left);if(key===null||!SIZE_KEYS.has(key))return;if(!isUnbounded(node.right,context.sourceCode))return;context.report({node:node.right,messageId:"unboundedMessageSize"})}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnguardedReflection=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_evidence_1=require("../../utils/grpc-evidence");function isReflectionRegistration(call,sourceCode){const{callee}=call;if((0,eslint_devkit_1.isModuleBinding)(callee,sourceCode.getScope(call),grpc_evidence_1.GRPC_SERVER_REFLECTION,["addReflection"])){return true}if(callee.type!=="MemberExpression"||(0,eslint_devkit_1.propertyName)(callee)!=="addToServer"){return false}const service=(0,eslint_devkit_1.followConst)(callee.object,sourceCode);return service.type==="NewExpression"&&(0,eslint_devkit_1.isModuleBinding)(service.callee,sourceCode.getScope(service),grpc_evidence_1.GRPC_REFLECTION,["ReflectionService"])}function exits(statement){switch(statement.type){case"ReturnStatement":case"ThrowStatement":case"BreakStatement":case"ContinueStatement":return true;case"BlockStatement":{const last=statement.body.at(-1);return last!==void 0&&exits(last)}default:return false}}function followsEarlyExit(body,child){return body.slice(0,body.indexOf(child)).some(statement=>statement.type==="IfStatement"&&exits(statement.consequent))}function bindingOf(fn){if(fn.type==="FunctionDeclaration")return fn.id??void 0;const{parent}=fn;return parent.type==="VariableDeclarator"&&parent.init===fn&&parent.id.type==="Identifier"?parent.id:void 0}function isConditional(node,sourceCode,visiting){let child=node;for(let parent=node.parent;parent!=null;child=parent,parent=parent.parent){switch(parent.type){case"IfStatement":case"ConditionalExpression":if(child!==parent.test)return true;break;case"LogicalExpression":if(child===parent.right)return true;break;case"SwitchCase":return true;case"BlockStatement":case"Program":if(followsEarlyExit(parent.body,child))return true;break;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{const invoker=parent.parent;const runsWithCaller=(invoker.type==="CallExpression"||invoker.type==="NewExpression")&&(invoker.callee===parent||invoker.arguments.includes(parent));if(runsWithCaller)break;return isOnlyCalledConditionally(parent,sourceCode,visiting)}default:break}}return false}function isOnlyCalledConditionally(fn,sourceCode,visiting){if(visiting.has(fn))return true;const binding=bindingOf(fn);const variable=binding&&(0,eslint_devkit_1.variableOf)(binding,sourceCode);if(variable===void 0)return true;visiting.add(fn);const unconditional=variable.references.some(({identifier})=>{const call=identifier.parent;return call?.type==="CallExpression"&&call.callee===identifier&&!isConditional(call,sourceCode,visiting)});visiting.delete(fn);return!unconditional}exports.noUnguardedReflection=(0,eslint_devkit_1.createRule)({name:"no-unguarded-reflection",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/no-unguarded-reflection.md",description:"Register gRPC server reflection only behind a guard",cwe:"CWE-306",cvss:5.3},messages:{unguardedReflection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"gRPC Server Reflection Registered Unconditionally",cwe:"CWE-306",owasp:"A05:2021",cvss:5.3,description:"Server reflection is registered with nothing in the file between it and production, so any client can list every service and method on this listener, internal ones included",severity:"MEDIUM",compliance:["SOC2","ISO27001"],fix:"Register reflection only where it is meant to run: `if (process.env.NODE_ENV !== 'production') new ReflectionService(def).addToServer(server);`. Serve internal services from a separate server bound to a private interface.",documentationLink:"https://github.com/grpc/grpc/blob/master/doc/server-reflection.md"})},schema:[]},defaultOptions:[],createOnce(context){return{before(){return(0,grpc_evidence_1.fileUsesGrpcReflection)(context.sourceCode.ast)},CallExpression(node){const{sourceCode}=context;if(!isReflectionRegistration(node,sourceCode))return;if(isConditional(node,sourceCode,new Set))return;context.report({node,messageId:"unguardedReflection"})}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireCallDeadline=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_credentials_1=require("../../utils/grpc-credentials");const grpc_flow_1=require("../../utils/grpc-flow");const CLIENT_LIFECYCLE=new Set(["close","getChannel","waitForReady"]);function isChannelCredentials(node,sourceCode){const call=(0,grpc_credentials_1.followConst)(node,sourceCode);if(call.type!=="CallExpression"||call.callee.type!=="MemberExpression"){return false}const owner=call.callee.object;return owner.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(owner)==="credentials"||owner.type==="Identifier"&&owner.name==="credentials"}function setsNoDeadline(node){return node.type==="Identifier"&&node.name==="undefined"||node.type==="Literal"&&node.value===null||node.type==="UnaryExpression"&&node.operator==="void"}function classify(arg,sourceCode){const value=(0,grpc_credentials_1.followConst)(arg,sourceCode);if((0,grpc_flow_1.isFunction)(value))return"callback";if((0,grpc_credentials_1.isNewMetadata)(value,sourceCode))return"metadata";if(value.type==="ObjectExpression"){const read=(0,eslint_devkit_1.readObjectProperty)(value,"deadline",sourceCode);if(read.kind==="value"){return setsNoDeadline(read.node)?"value":"deadline"}return value.properties.some(p=>p.type==="SpreadElement")?"unknown":"value"}if(value.type==="Literal"||value.type==="ArrayExpression"){return"value"}return"unknown"}function lacksDeadline(args,sourceCode){const kinds=args.map(arg=>classify(arg,sourceCode));if(kinds.includes("deadline"))return false;const hasCallback=kinds.includes("callback");if(!hasCallback&&kinds.length===1&&kinds[0]==="unknown"){return false}return kinds.every((kind,i)=>kind!=="unknown"||i===0)}exports.requireCallDeadline=(0,eslint_devkit_1.createRule)({name:"require-call-deadline",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-grpc-security/docs/rules/require-call-deadline.md",description:"Give every gRPC client call a deadline",cwe:"CWE-400",cvss:5.3},messages:{missingDeadline:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"gRPC Call Without a Deadline",cwe:"CWE-400",owasp:"A04:2021",cvss:5.3,description:"A gRPC client call sets no deadline, so a slow or stalled server holds it, and everything waiting on it, indefinitely",severity:"MEDIUM",compliance:["SOC2"],fix:"Pass call options with a deadline: `client.Get(req, { deadline: Date.now() + 5000 }, callback)`. Pick the deadline from the caller\u2019s own time budget.",documentationLink:"https://grpc.io/docs/guides/deadlines/"})},schema:[]},defaultOptions:[],createOnce(context){return{NewExpression(node){const{sourceCode}=context;const credentials=node.arguments[1];if(credentials===void 0||!isChannelCredentials(credentials,sourceCode)){return}const declarator=node.parent;if(declarator.type!=="VariableDeclarator"||declarator.id.type!=="Identifier"){return}const refs=(0,grpc_flow_1.referencesOf)(declarator.id,declarator,sourceCode);if(refs.some(ref=>ref.isWrite()&&!ref.init))return;for(const{identifier}of refs){const member=identifier.parent;const call=member?.parent;if(member?.type!=="MemberExpression"||member.object!==identifier||call?.type!=="CallExpression"||call.callee!==member){continue}const method=(0,eslint_devkit_1.propertyName)(member);if(method===null||CLIENT_LIFECYCLE.has(method))continue;if(lacksDeadline(call.arguments,sourceCode)){context.report({node:call,messageId:"missingDeadline"})}}}}}});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.CREDENTIAL_HEADERS=void 0;exports.followConst=followConst;exports.isInsecureCredentials=isInsecureCredentials;exports.isNewMetadata=isNewMetadata;exports.staticPrefix=staticPrefix;exports.isCredentialHeader=isCredentialHeader;const eslint_devkit_1=require("@interlace/eslint-devkit");const grpc_flow_1=require("./grpc-flow");exports.CREDENTIAL_HEADERS=new Set(["authorization","proxy-authorization","cookie","x-api-key"]);const BEARER=/^bearer\s/i;function followConst(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){if(hops<=0||node.type!=="Identifier")return node;const def=(0,grpc_flow_1.definitionOf)(node,sourceCode);const declarator=def?.type==="Variable"?def.node:void 0;return declarator?.init&&declarator.id===def?.name?followConst(declarator.init,sourceCode,hops-1):node}function namesExport(node,owner,sourceCode){if(node.type==="MemberExpression")return(0,eslint_devkit_1.propertyName)(node)===owner;if(node.type!=="Identifier")return false;const binding=(0,eslint_devkit_1.resolveModuleBinding)(node,sourceCode.getScope(node));return binding?.path.at(-1)===owner}function isInsecureCredentials(node,owner,sourceCode){const call=followConst(node,sourceCode);return call.type==="CallExpression"&&call.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(call.callee)==="createInsecure"&&namesExport(call.callee.object,owner,sourceCode)}function isNewMetadata(node,sourceCode){return node.type==="NewExpression"&&namesExport(node.callee,"Metadata",sourceCode)}function staticPrefix(node,sourceCode,hops=grpc_flow_1.MAX_HOPS){const unknown={text:"",complete:false};if(hops<=0)return unknown;const read=child=>staticPrefix(child,sourceCode,hops-1);switch(node.type){case"Literal":return typeof node.value==="string"||typeof node.value==="number"?{text:String(node.value),complete:true}:unknown;case"TemplateLiteral":{let text="";for(const[i,quasi]of node.quasis.entries()){text+=quasi.value.raw;const expression=node.expressions[i];if(expression===void 0)break;const part=read(expression);text+=part.text;if(!part.complete)return{text,complete:false}}return{text,complete:true}}case"BinaryExpression":{if(node.operator!=="+")return unknown;const left=read(node.left);if(!left.complete)return left;const right=read(node.right);return{text:left.text+right.text,complete:right.complete}}case"Identifier":{const followed=followConst(node,sourceCode,1);return followed===node?unknown:read(followed)}default:return unknown}}function isCredentialHeader(name,value,sourceCode){const key=name?staticPrefix(name,sourceCode):void 0;if(key?.complete&&exports.CREDENTIAL_HEADERS.has(key.text.toLowerCase())){return true}return value!==void 0&&BEARER.test(staticPrefix(value,sourceCode).text)}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fileUsesGrpcReflection=exports.GRPC_SERVER_REFLECTION=exports.GRPC_REFLECTION=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.GRPC_REFLECTION="@grpc/reflection";exports.GRPC_SERVER_REFLECTION="grpc-server-reflection";exports.fileUsesGrpcReflection=(0,eslint_devkit_1.createModuleEvidence)({packages:[exports.GRPC_REFLECTION,exports.GRPC_SERVER_REFLECTION]});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MAX_HOPS=void 0;exports.isFunction=isFunction;exports.definitionOf=definitionOf;exports.functionOf=functionOf;exports.referencesOf=referencesOf;exports.callSitesOf=callSitesOf;exports.returnsOf=returnsOf;exports.isServiceImplementation=isServiceImplementation;exports.isHandler=isHandler;exports.isCallMetadata=isCallMetadata;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.MAX_HOPS=12;function isFunction(node){return node.type==="FunctionDeclaration"||node.type==="FunctionExpression"||node.type==="ArrowFunctionExpression"}function definitionOf(id,sourceCode){const variable=(0,eslint_devkit_1.variableOf)(id,sourceCode);if(variable===void 0||variable.defs.length!==1)return void 0;const writes=variable.references.filter(ref=>ref.isWrite()&&!ref.init);return writes.length===0?variable.defs[0]:void 0}function functionOf(id,sourceCode){const def=definitionOf(id,sourceCode);if(def?.type==="FunctionName")return def.node;if(def?.type!=="Variable")return void 0;const init=def.node.init;return init!==null&&isFunction(init)?init:void 0}function referencesOf(binding,declaration,sourceCode){const refs=[];for(const variable of sourceCode.getDeclaredVariables(declaration)){if(variable.identifiers.some(id=>id===binding))refs.push(...variable.references)}return refs}function callSitesOf(fn,sourceCode){const{parent}=fn;if(parent.type==="CallExpression"&&parent.callee===fn)return[parent];const[binding,declaration]=fn.type==="FunctionDeclaration"?[fn.id,fn]:parent.type==="VariableDeclarator"?[parent.id,parent]:[null,fn];if(binding===null)return[];return referencesOf(binding,declaration,sourceCode).flatMap(({identifier})=>{const call=identifier.parent;return call?.type==="CallExpression"&&call.callee===identifier?[call]:[]})}function returnsOf(fn){if(fn.body.type!=="BlockStatement")return[fn.body];const found=[];const visit=node=>{if(node.type==="ReturnStatement"){if(node.argument)found.push(node.argument);return}if(isFunction(node))return;for(const[key,value]of Object.entries(node)){if(key==="parent")continue;for(const child of Array.isArray(value)?value:[value]){if(child&&typeof child==="object"&&"type"in child){visit(child)}}}};visit(fn.body);return found}function isServiceImplementation(object,sourceCode){const registers=(call,arg)=>call?.type==="CallExpression"&&call.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(call.callee)==="addService"&&call.arguments[1]===arg;if(registers(object.parent,object))return true;const declarator=object.parent;if(declarator.type!=="VariableDeclarator"||declarator.init!==object||declarator.id.type!=="Identifier"){return false}return referencesOf(declarator.id,declarator,sourceCode).some(({identifier})=>registers(identifier.parent,identifier))}function isHandler(fn,sourceCode){const property=fn.parent;return property.type==="Property"&&property.value===fn&&property.parent.type==="ObjectExpression"&&isServiceImplementation(property.parent,sourceCode)}function isCallMetadata(node,sourceCode,hops){if(hops<=0)return false;if(node.type==="MemberExpression"){if((0,eslint_devkit_1.propertyName)(node)!=="metadata")return false;if(node.object.type!=="Identifier")return false;const def2=definitionOf(node.object,sourceCode);return def2?.type==="Parameter"&&isFunction(def2.node)&&def2.node.params[0]===def2.name&&isHandler(def2.node,sourceCode)}if(node.type!=="Identifier")return false;const def=definitionOf(node,sourceCode);if(def?.type==="Variable"){const init=def.node.init;return init!==null&&isCallMetadata(init,sourceCode,hops-1)}if(def?.type!=="Parameter")return false;const fn=def.node;const[first]=fn.params;if(first?.type==="ObjectPattern"&&def.name.parent?.type==="Property"){const property=def.name.parent;return property.parent===first&&property.value===def.name&&(0,eslint_devkit_1.propertyName)({type:"MemberExpression",computed:property.computed,property:property.key})==="metadata"&&isHandler(fn,sourceCode)}const index=fn.params.indexOf(def.name);return callSitesOf(fn,sourceCode).some(call=>{const arg=call.arguments[index];return arg!==void 0&&isCallMetadata(arg,sourceCode,hops-1)})}