Security rules for PostgreSQL interaction in Node.js (SQL injection prevention).
## Getting Started
- To check out the [guide](https://eslint.interlace.tools/docs/security/plugin-postgresql-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security), visit [eslint.interlace.tools](https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security). ๐
```bash
npm install --save-dev eslint eslint-plugin-postgresql-security
```
```js
// eslint.config.mjs
import { configs } from 'eslint-plugin-postgresql-security';
export default [configs.recommended];
```
`recommended` is the preset to start with. The others are listed under Configuration Presets below.
Using oxlint or Vite+? Install `oxlint-plugin-postgresql-security`: the same rules under the same `postgresql-security/` IDs, without ESLint. Its [page](https://www.npmjs.com/package/oxlint-plugin-postgresql-security) has the setup.
## Description
This plugin provides Security rules for PostgreSQL interaction in Node.js (SQL injection prevention).
## Why pg-specific?
A generic SQL injection linter can flag string concatenation wherever it appears, but it cannot know the parameterization convention for each database client. The `pg` (node-postgres) driver uses `$1, $2, โฆ` positional placeholders with a second-argument array โ a pattern no generic rule encodes. `eslint-plugin-postgresql-security` knows this contract: it only fires on `.query()` calls, it stays silent when a second argument (the values array) is present, and it tracks variable taint across assignment statements so that a split-line pattern like `const sql = "SELECT..." + id; client.query(sql)` is flagged even though the concatenation and the query call are on separate lines. The result is a rule with near-zero false positives on legitimate parameterized queries and reliable detection on the patterns that actually lead to SQL injection.
- **Why** โ a linter nobody reads protects nothing. We would rather miss a finding
than spend your attention on one that was never real.
- **How** โ evidence, not names. A rule fires on what the code *does*, resolved
through the AST and ESLint's own scope analysis.
- **What** โ every finding carries its fix, in prose for a human and as structured
JSON for an agent. Security rules add a CWE mapping and, where assigned, a CVSS score.
That trade costs recall, and we measure it:
[methodology](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-METHODOLOGY.md)
ยท [results](https://github.com/ofri-peretz/eslint/blob/main/BENCHMARK-RESULTS.md)
ยท [a false positive is a bug](https://github.com/ofri-peretz/eslint/issues).
## โ๏ธ Configuration Presets
| Preset | Description |
| :------------ | :------------------------------------------------------- |
| `recommended` | Recommended preset - balanced security for most projects |
| `strict` | Strict preset - all rules as errors |
## ๐ Supported Libraries
| Library | npm | Downloads | Detection |
| -------------------- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------- |
| `pg` (node-postgres) | [](https://www.npmjs.com/package/pg) | [](https://www.npmjs.com/package/pg) | SQL Injection, Connection Leaks |
### Custom Configuration
```javascript
import pg from 'eslint-plugin-postgresql-security';
export default [
{
plugins: { pg },
rules: {
'pg/no-unsafe-query': 'error',
'pg/no-select-all': 'off', // Disable if needed
},
},
];
```
## ๐ก What You Get
- **PostgreSQL-specific rules:** Catches pg driver anti-patterns that generic linters miss
- **LLM-optimized messages:** Structured 2-line errors with CWE + fixes that AI assistants can apply
- **Connection safety:** Prevents leaks, double releases, and transaction race conditions
- **SQL security:** SQL injection, search_path hijacking, file access via COPY
- **Performance patterns:** N+1 queries, SELECT \*, bulk operation suggestions
Every rule produces a **structured error message**:
```bash
src/db.ts
42:15 error ๐ CWE-89 OWASP:A03-Injection CVSS:9.8 | Unsafe query detected | CRITICAL
Fix: Use parameterized query: client.query('SELECT * FROM users WHERE id = $1', [userId])
```
## ๐ฆ Compatibility
| Package | Version |
| :--- | :--- |
| ESLint | `^8.40.0 \|\| ^9.0.0 \|\| ^10.0.0` |
| Node.js | `>=22.13.0` |
See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) โ current ecosystem share data, the 20% gate, and the forward-looking exception that covers v10.
## Rules
**Legend**
| Icon | Description |
| :---: | :--- |
| ๐ผ | **Recommended**: Included in the recommended preset. |
| โ ๏ธ | **Warns**: Set to warn in recommended preset. |
| ๐ง | **Auto-fixable**: Automatically fixable by the `--fix` CLI option. |
| ๐ก | **Suggestions**: Providing code suggestions in IDE. |
| ๐ซ | **Deprecated**: This rule is deprecated. |
| ๐ข | **Type-unaware**: AST-only, runs in oxlint JS-plugin tier. |
| ๐ก | **Type-aware (refining)**: pure-AST primary path; types refine precision. |
| ๐ | **Type-aware (graceful)**: requires TS program; silent without it. |
| Rule | CWE | OWASP | CVSS | Description | ๐ง | ๐ผ | โ ๏ธ | ๐ง | ๐ก | ๐ซ |
| :--- | :---: | :---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
| [check-query-params](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/check-query-params?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-89 | | | Ensures the number of placeholders in SQL queries matches the provided parameters. | ๐ข | | โ ๏ธ | | | |
| [no-batch-insert-loop](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-batch-insert-loop?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-400 | | | Prevents INSERT/UPDATE/DELETE queries inside loops (N+1 query anti-pattern). | ๐ข | | โ ๏ธ | | | |
| [no-floating-query](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-floating-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-252 | | | Ensures query promises are awaited or handled. | ๐ข | | โ ๏ธ | | | |
| [no-hardcoded-credentials](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-hardcoded-credentials?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-798 | | | Prevents hardcoded passwords and connection strings in PostgreSQL client initialization. | ๐ข | ๐ผ | | | | |
| [no-insecure-ssl](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-insecure-ssl?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-295 | | | Prevents disabling SSL certificate validation in PostgreSQL connections. | ๐ข | ๐ผ | | | | |
| [no-missing-client-release](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-missing-client-release?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-772 | | | Ensures acquired pool clients are released back to the pool. | ๐ข | ๐ผ | | | | |
| [no-select-all](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-select-all?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-1049 | | | Discourages SELECT in favor of explicit column lists. | ๐ข | | โ ๏ธ | | | |
| [no-transaction-on-pool](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-transaction-on-pool?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-362 | | | Prevents running transaction commands directly on pool (must use dedicated client). | ๐ข | ๐ผ | | | | |
| [no-unsafe-copy-from](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-unsafe-copy-from?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-73 | A03:2021 | | Prevents COPY FROM with file paths (should use STDIN for safe client-side data loading). | ๐ข | ๐ผ | | | | |
| [no-unsafe-query](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-unsafe-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-89 | | | SQL injection is one of the most critical security vulnerabilities | ๐ข | ๐ผ | | | | |
| [no-unsafe-search-path](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/no-unsafe-search-path?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-426 | | | Prevents dynamic SET searchpath queries that could enable schema hijacking. | ๐ข | ๐ผ | | | | |
| [prefer-pool-query](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/prefer-pool-query?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-400 | | | Suggests using pool.query() for single-shot queries instead of manual connect/release. | ๐ข | | โ ๏ธ | | | |
| [prevent-double-release](https://eslint.interlace.tools/docs/security/plugin-postgresql-security/rules/prevent-double-release?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security) | CWE-415 | | | Prevents calling client.release() multiple times on the same client. | ๐ข | | โ ๏ธ | | | |
## ๐ Related ESLint Plugins
Part of the **Interlace ESLint ecosystem** โ AI-native rules with LLM-optimized error messages:
**Security**
| Plugin | Downloads | Description |
| :--- | :---: | :--- |
| [`eslint-plugin-anthropic-security`](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | [](https://www.npmjs.com/package/eslint-plugin-anthropic-security) | Anthropic SDK security. |
| [`eslint-plugin-browser-security`](https://www.npmjs.com/package/eslint-plugin-browser-security) | [](https://www.npmjs.com/package/eslint-plugin-browser-security) | XSS, DOM security. |
| [`eslint-plugin-drizzle-security`](https://www.npmjs.com/package/eslint-plugin-drizzle-security) | [](https://www.npmjs.com/package/eslint-plugin-drizzle-security) | Drizzle security. |
| [`eslint-plugin-express-security`](https://www.npmjs.com/package/eslint-plugin-express-security) | [](https://www.npmjs.com/package/eslint-plugin-express-security) | Express middleware hardening. |
| [`eslint-plugin-gemini-security`](https://www.npmjs.com/package/eslint-plugin-gemini-security) | [](https://www.npmjs.com/package/eslint-plugin-gemini-security) | Google Gemini SDK security. |
| [`eslint-plugin-jwt-security`](https://www.npmjs.com/package/eslint-plugin-jwt-security) | [](https://www.npmjs.com/package/eslint-plugin-jwt-security) | Token security. |
| [`eslint-plugin-knex-security`](https://www.npmjs.com/package/eslint-plugin-knex-security) | [](https://www.npmjs.com/package/eslint-plugin-knex-security) | Knex security. |
| [`eslint-plugin-lambda-security`](https://www.npmjs.com/package/eslint-plugin-lambda-security) | [](https://www.npmjs.com/package/eslint-plugin-lambda-security) | AWS Lambda hardening. |
| [`eslint-plugin-mcp-sdk-security`](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | [](https://www.npmjs.com/package/eslint-plugin-mcp-sdk-security) | MCP SDK security. |
| [`eslint-plugin-mongodb-security`](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | [](https://www.npmjs.com/package/eslint-plugin-mongodb-security) | MongoDB injection. |
| [`eslint-plugin-mysql-security`](https://www.npmjs.com/package/eslint-plugin-mysql-security) | [](https://www.npmjs.com/package/eslint-plugin-mysql-security) | MySQL security. |
| [`eslint-plugin-nestjs-security`](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | [](https://www.npmjs.com/package/eslint-plugin-nestjs-security) | NestJS framework hardening. |
| [`eslint-plugin-node-security`](https://www.npmjs.com/package/eslint-plugin-node-security) | [](https://www.npmjs.com/package/eslint-plugin-node-security) | Server-side patterns. |
| [`eslint-plugin-openai-security`](https://www.npmjs.com/package/eslint-plugin-openai-security) | [](https://www.npmjs.com/package/eslint-plugin-openai-security) | OpenAI SDK security. |
| [`eslint-plugin-prisma-security`](https://www.npmjs.com/package/eslint-plugin-prisma-security) | [](https://www.npmjs.com/package/eslint-plugin-prisma-security) | Prisma security. |
| [`eslint-plugin-secure-coding`](https://www.npmjs.com/package/eslint-plugin-secure-coding) | [](https://www.npmjs.com/package/eslint-plugin-secure-coding) | Injection prevention. |
| [`eslint-plugin-sequelize-security`](https://www.npmjs.com/package/eslint-plugin-sequelize-security) | [](https://www.npmjs.com/package/eslint-plugin-sequelize-security) | Sequelize ORM security. |
| [`eslint-plugin-sqlite-security`](https://www.npmjs.com/package/eslint-plugin-sqlite-security) | [](https://www.npmjs.com/package/eslint-plugin-sqlite-security) | SQLite security. |
| [`eslint-plugin-supabase-security`](https://www.npmjs.com/package/eslint-plugin-supabase-security) | [](https://www.npmjs.com/package/eslint-plugin-supabase-security) | Supabase security. |
| [`eslint-plugin-typeorm-security`](https://www.npmjs.com/package/eslint-plugin-typeorm-security) | [](https://www.npmjs.com/package/eslint-plugin-typeorm-security) | TypeORM security. |
| [`eslint-plugin-vercel-ai-security`](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | [](https://www.npmjs.com/package/eslint-plugin-vercel-ai-security) | AI SDK security. |
**Code quality**
| Plugin | Downloads | Description |
| :--- | :---: | :--- |
| [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
| [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
| [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
| [`eslint-plugin-modernization`](https://www.npmjs.com/package/eslint-plugin-modernization) | [](https://www.npmjs.com/package/eslint-plugin-modernization) | ESNext migration + syntax evolution. |
| [`eslint-plugin-modularity`](https://www.npmjs.com/package/eslint-plugin-modularity) | [](https://www.npmjs.com/package/eslint-plugin-modularity) | Structural integrity and DDD patterns. |
| [`eslint-plugin-operability`](https://www.npmjs.com/package/eslint-plugin-operability) | [](https://www.npmjs.com/package/eslint-plugin-operability) | Production readiness and resource health. |
| [`eslint-plugin-react-a11y`](https://www.npmjs.com/package/eslint-plugin-react-a11y) | [](https://www.npmjs.com/package/eslint-plugin-react-a11y) | React accessibility / WCAG. |
| [`eslint-plugin-react-features`](https://www.npmjs.com/package/eslint-plugin-react-features) | [](https://www.npmjs.com/package/eslint-plugin-react-features) | React best practices and optimization. |
| [`eslint-plugin-reliability`](https://www.npmjs.com/package/eslint-plugin-reliability) | [](https://www.npmjs.com/package/eslint-plugin-reliability) | Runtime stability and error safety. |
## Support
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.
## ๐ License
MIT ยฉ [Ofri Peretz](https://github.com/ofri-peretz)