Hardening the Data Layer: The node-postgres Static Analysis Standard

Eliminate the #1 database vulnerability. An automated static analysis protocol for preventing SQL injection and connection leaks in production.

2 min read
Hardening the Data Layer: The node-postgres Static Analysis Standard
Share:

Postgres is the backbone of your production infrastructure. For engineering leaders, database security isn't a training problemβ€”it's a governance problem. Here is the automated static analysis standard for node-postgres.

Quick Install

bash
npm install --save-dev eslint-plugin-pg

Flat Config

javascript
// eslint.config.js
import pg from "eslint-plugin-pg";

export default [pg.configs.recommended];

Run ESLint

bash
npx eslint .

You'll see output like:

bash
src/users.ts
  15:3  error  πŸ”’ CWE-89 OWASP:A03 CVSS:9.8 | Unsafe SQL query detected
               Fix: Use parameterized query: client.query('SELECT * FROM users WHERE id = $1', [id])

src/orders.ts
  28:5  error  πŸ”’ CWE-772 | pool.connect() without client.release()
               Fix: Add client.release() in finally block

Rule Overview

RuleCWEWhat it catches
no-unsafe-queryCWE-89SQL injection via string concatenation
no-missing-client-releaseCWE-772Connection pool leaks
prevent-double-releaseCWE-415Double release crashes
no-transaction-on-poolCWE-362Transaction race conditions
prefer-pool-queryCWE-400Unnecessary connect/release
no-unsafe-copy-fromCWE-22Path traversal in COPY FROM
no-unsafe-search-pathCWE-426search_path hijacking
no-batch-insert-loopPerfN+1 query patterns
Plus 5 more...

Quick Wins

Before

javascript
// ❌ SQL Injection
const query = `SELECT * FROM users WHERE id = '${userId}'`;
await pool.query(query);

After

javascript
// βœ… Parameterized Query
const query = "SELECT * FROM users WHERE id = $1";
await pool.query(query, [userId]);

Before

javascript
// ❌ Connection Leak
const client = await pool.connect();
const result = await client.query("SELECT * FROM users");
return result.rows;
// Missing client.release()!

After

javascript
// βœ… Guaranteed Release
const client = await pool.connect();
try {
  const result = await client.query("SELECT * FROM users");
  return result.rows;
} finally {
  client.release();
}

Available Presets

javascript
// Security + best practices
pg.configs.recommended;

// All rules enabled
pg.configs.all;

Customizing Rules

javascript
// eslint.config.js
import pg from "eslint-plugin-pg";

export default [
  pg.configs.recommended,
  {
    rules: {
      // Downgrade to warning
      "pg/prefer-pool-query": "warn",

      // Increase strictness
      "pg/no-unsafe-query": [
        "error",
        {
          allowLiteral: false,
        },
      ],
    },
  },
];

Performance

text
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Benchmark: 1000 files                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ eslint-plugin-pg:          785ms                    β”‚
β”‚ 100% precision (0 false positives in tests)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Combine with Other Plugins

javascript
import pg from "eslint-plugin-pg";
import secureCoding from "eslint-plugin-secure-coding";

export default [pg.configs.recommended, secureCoding.configs.recommended];

Quick Reference

bash
# Install
npm install --save-dev eslint-plugin-pg

# Config (eslint.config.js)
import pg from 'eslint-plugin-pg';
export default [pg.configs.recommended];

# Run
npx eslint .

πŸ“¦ npm: eslint-plugin-pg πŸ“– Full Rule List

πŸš€ Using node-postgres? Drop a star on GitHub!


The Interlace ESLint Ecosystem Interlace is a high-fidelity suite of static code analyzers designed to automate security, performance, and reliability for the modern Node.js stack. With over 330 rules across 18 specialized plugins, it provides 100% coverage for OWASP Top 10, LLM Security, and Database Hardening.

Explore the full Documentation

Β© 2026 Ofri Peretz. All rights reserved.


Build Securely. I'm Ofri Peretz, a Security Engineering Leader and the architect of the Interlace Ecosystem. I build static analysis standards that automate security and performance for Node.js fleets at scale.

ofriperetz.dev | LinkedIn | GitHub

Built with Nuxt UI β€’ Β© 2026 Ofri Peretz