eslint-plugin-postgresql-security 1.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/CHANGELOG.md +150 -0
- package/LICENSE +23 -0
- package/README.md +169 -0
- package/dist/AGENTS.md +118 -0
- package/dist/CHANGELOG.md +150 -0
- package/dist/LICENSE +23 -0
- package/dist/README.md +169 -0
- package/dist/package.json +99 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +13 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +116 -0
- package/dist/src/oxlint.d.ts +20 -0
- package/dist/src/oxlint.js +21 -0
- package/dist/src/rules/check-query-params/index.d.ts +8 -0
- package/dist/src/rules/check-query-params/index.js +90 -0
- package/dist/src/rules/no-batch-insert-loop/index.d.ts +8 -0
- package/dist/src/rules/no-batch-insert-loop/index.js +90 -0
- package/dist/src/rules/no-floating-query/index.d.ts +8 -0
- package/dist/src/rules/no-floating-query/index.js +74 -0
- package/dist/src/rules/no-hardcoded-credentials/index.d.ts +8 -0
- package/dist/src/rules/no-hardcoded-credentials/index.js +86 -0
- package/dist/src/rules/no-insecure-ssl/index.d.ts +8 -0
- package/dist/src/rules/no-insecure-ssl/index.js +66 -0
- package/dist/src/rules/no-missing-client-release/index.d.ts +8 -0
- package/dist/src/rules/no-missing-client-release/index.js +85 -0
- package/dist/src/rules/no-select-all/index.d.ts +8 -0
- package/dist/src/rules/no-select-all/index.js +79 -0
- package/dist/src/rules/no-transaction-on-pool/index.d.ts +8 -0
- package/dist/src/rules/no-transaction-on-pool/index.js +71 -0
- package/dist/src/rules/no-unsafe-copy-from/index.d.ts +10 -0
- package/dist/src/rules/no-unsafe-copy-from/index.js +205 -0
- package/dist/src/rules/no-unsafe-query/index.d.ts +8 -0
- package/dist/src/rules/no-unsafe-query/index.js +132 -0
- package/dist/src/rules/no-unsafe-search-path/index.d.ts +8 -0
- package/dist/src/rules/no-unsafe-search-path/index.js +144 -0
- package/dist/src/rules/prefer-pool-query/index.d.ts +8 -0
- package/dist/src/rules/prefer-pool-query/index.js +104 -0
- package/dist/src/rules/prevent-double-release/index.d.ts +8 -0
- package/dist/src/rules/prevent-double-release/index.js +456 -0
- package/dist/src/types/index.d.ts +54 -0
- package/dist/src/types/index.js +7 -0
- package/package.json +99 -0
- package/src/__compatibility__/pg-interface.spec.ts +495 -0
- package/src/constants.ts +11 -0
- package/src/index.spec.ts +14 -0
- package/src/index.test.ts +59 -0
- package/src/index.ts +130 -0
- package/src/oxlint.spec.ts +70 -0
- package/src/oxlint.ts +23 -0
- package/src/rules/check-query-params/check-query-params.test.ts +68 -0
- package/src/rules/check-query-params/index.spec.ts +117 -0
- package/src/rules/check-query-params/index.ts +106 -0
- package/src/rules/no-batch-insert-loop/index.spec.ts +105 -0
- package/src/rules/no-batch-insert-loop/index.ts +105 -0
- package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +68 -0
- package/src/rules/no-floating-query/index.spec.ts +112 -0
- package/src/rules/no-floating-query/index.ts +81 -0
- package/src/rules/no-floating-query/no-floating-query.test.ts +68 -0
- package/src/rules/no-hardcoded-credentials/index.spec.ts +38 -0
- package/src/rules/no-hardcoded-credentials/index.ts +93 -0
- package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +68 -0
- package/src/rules/no-insecure-ssl/index.spec.ts +40 -0
- package/src/rules/no-insecure-ssl/index.ts +81 -0
- package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +68 -0
- package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +42 -0
- package/src/rules/no-missing-client-release/index.spec.ts +52 -0
- package/src/rules/no-missing-client-release/index.ts +100 -0
- package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +68 -0
- package/src/rules/no-select-all/index.spec.ts +44 -0
- package/src/rules/no-select-all/index.ts +92 -0
- package/src/rules/no-select-all/no-select-all.test.ts +68 -0
- package/src/rules/no-transaction-on-pool/index.spec.ts +36 -0
- package/src/rules/no-transaction-on-pool/index.ts +85 -0
- package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +68 -0
- package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +76 -0
- package/src/rules/no-unsafe-copy-from/index.spec.ts +274 -0
- package/src/rules/no-unsafe-copy-from/index.ts +226 -0
- package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +78 -0
- package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +61 -0
- package/src/rules/no-unsafe-query/index.spec.ts +103 -0
- package/src/rules/no-unsafe-query/index.ts +149 -0
- package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +73 -0
- package/src/rules/no-unsafe-search-path/index.spec.ts +46 -0
- package/src/rules/no-unsafe-search-path/index.ts +164 -0
- package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +68 -0
- package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +76 -0
- package/src/rules/prefer-pool-query/index.spec.ts +97 -0
- package/src/rules/prefer-pool-query/index.ts +118 -0
- package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +68 -0
- package/src/rules/prevent-double-release/coverage-gaps.spec.ts +538 -0
- package/src/rules/prevent-double-release/index.spec.ts +824 -0
- package/src/rules/prevent-double-release/index.ts +534 -0
- package/src/rules/prevent-double-release/prevent-double-release.test.ts +70 -0
- package/src/types/index.ts +58 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noBatchInsertLoop = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
exports.noBatchInsertLoop = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Prevent executing database queries within loops (N+1 problem).',
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-batch-insert-loop.md',
|
|
16
|
+
cwe: 'CWE-1049',
|
|
17
|
+
cvss: 7.5,
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
noBatchInsertLoop: (0, eslint_devkit_1.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
|
|
22
|
+
issueName: 'N+1 Query Detection',
|
|
23
|
+
description: 'Database query loop detected.',
|
|
24
|
+
severity: 'HIGH',
|
|
25
|
+
cwe: 'CWE-1049',
|
|
26
|
+
effort: 'medium',
|
|
27
|
+
fix: 'Batch queries using arrays and "UNNEST" or a single batched INSERT.',
|
|
28
|
+
documentationLink: 'https://use-the-index-luke.com/sql/joins/nested-loops-join-n1-problem',
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
return {
|
|
36
|
+
CallExpression(node) {
|
|
37
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
38
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
39
|
+
node.callee.property.name !== 'query') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const args = node.arguments;
|
|
43
|
+
if (args.length > 0 && args[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof args[0].value === 'string') {
|
|
44
|
+
const query = args[0].value.toUpperCase();
|
|
45
|
+
if (!query.includes('INSERT') && !query.includes('UPDATE')) {
|
|
46
|
+
return; // Only care about mutations usually, SELECT N+1 is also bad but maybe 'no-loop-query' is separate
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let ancestor = node.parent;
|
|
50
|
+
while (ancestor) {
|
|
51
|
+
if (ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForStatement ||
|
|
52
|
+
ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForOfStatement ||
|
|
53
|
+
ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForInStatement ||
|
|
54
|
+
ancestor.type === eslint_devkit_1.AST_NODE_TYPES.WhileStatement ||
|
|
55
|
+
ancestor.type === eslint_devkit_1.AST_NODE_TYPES.DoWhileStatement) {
|
|
56
|
+
context.report({
|
|
57
|
+
node,
|
|
58
|
+
messageId: 'noBatchInsertLoop',
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
// Check for function expressions that are callbacks to array methods
|
|
63
|
+
if ((ancestor.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression || ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
|
|
64
|
+
if (ancestor.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
|
|
65
|
+
ancestor.parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
66
|
+
ancestor.parent.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
67
|
+
['map', 'forEach', 'reduce', 'filter'].includes(ancestor.parent.callee.property.name)) {
|
|
68
|
+
context.report({
|
|
69
|
+
node,
|
|
70
|
+
messageId: 'noBatchInsertLoop',
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
// Stop traversal at function boundary unless it's an IIFE?
|
|
75
|
+
// Actually if we are in a function, we stop unless that function IS the loop body callback.
|
|
76
|
+
// If we are in `function foo() { while(...) { query } }` -> we hit WhileStatement first.
|
|
77
|
+
// If we are in `users.map(u => query(u))` -> query -> ArrowFunc -> CallExpression(map).
|
|
78
|
+
// So if we hit a function, we must check if it's the specific loop callback.
|
|
79
|
+
// If not, we stop (don't flag loop outside of function definition, that's weird).
|
|
80
|
+
if (ancestor.parent?.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
81
|
+
// It's a regular function definition, stop going up (don't blame caller's loop).
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
ancestor = ancestor.parent;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoFloatingQueryOptions } from '../../types';
|
|
8
|
+
export declare const noFloatingQuery: TSESLint.RuleModule<'noFloatingQuery', NoFloatingQueryOptions>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noFloatingQuery = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
exports.noFloatingQuery = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Ensure all queries are awaited or returned to prevent unhandled promise rejections.',
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-floating-query.md',
|
|
16
|
+
cwe: 'CWE-391',
|
|
17
|
+
cvss: 5.3,
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
noFloatingQuery: (0, eslint_devkit_1.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
22
|
+
issueName: 'Floating Query',
|
|
23
|
+
description: 'Promise-returning query is neither awaited nor returned.',
|
|
24
|
+
severity: 'HIGH',
|
|
25
|
+
cwe: 'CWE-391',
|
|
26
|
+
effort: 'low',
|
|
27
|
+
fix: 'Add "await" or "return" to handle the query promise.',
|
|
28
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise',
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
return {
|
|
36
|
+
CallExpression(node) {
|
|
37
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
38
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
39
|
+
node.callee.property.name !== 'query') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Check parent node to see if the promise is handled
|
|
43
|
+
const parent = node.parent;
|
|
44
|
+
// Allowed parents:
|
|
45
|
+
// 1. AwaitExpression: await client.query(...)
|
|
46
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression)
|
|
47
|
+
return;
|
|
48
|
+
// 2. ReturnStatement: return client.query(...)
|
|
49
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)
|
|
50
|
+
return;
|
|
51
|
+
// 3. ArrowFunctionExpression (implicit return): () => client.query(...)
|
|
52
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
53
|
+
return;
|
|
54
|
+
// 4. VariableDeclarator: const p = client.query(...) -> Assumed handled if assigned
|
|
55
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)
|
|
56
|
+
return;
|
|
57
|
+
// 5. MemberExpression: client.query(...).then(...) or .catch(...)
|
|
58
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
59
|
+
return; // check chains?
|
|
60
|
+
// 6. AssignmentExpression: p = client.query(...)
|
|
61
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression)
|
|
62
|
+
return;
|
|
63
|
+
// If specific to typical void usage:
|
|
64
|
+
// ExpressionStatement: client.query(...); -> This is bad!
|
|
65
|
+
if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement) {
|
|
66
|
+
context.report({
|
|
67
|
+
node,
|
|
68
|
+
messageId: 'noFloatingQuery',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoHardcodedCredentialsOptions } from '../../types';
|
|
8
|
+
export declare const noHardcodedCredentials: TSESLint.RuleModule<'noHardcodedCredentials', NoHardcodedCredentialsOptions>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noHardcodedCredentials = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const constants_1 = require("../../constants");
|
|
11
|
+
exports.noHardcodedCredentials = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Detect hardcoded credentials in pg Client or Pool initialization.',
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-hardcoded-credentials.md',
|
|
17
|
+
cwe: 'CWE-798',
|
|
18
|
+
cvss: 9.8,
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
noHardcodedCredentials: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
23
|
+
issueName: 'Hardcoded Credentials',
|
|
24
|
+
description: 'Hardcoded credentials detected in database connection.',
|
|
25
|
+
severity: 'CRITICAL',
|
|
26
|
+
cwe: 'CWE-798',
|
|
27
|
+
owasp: 'A07:2021',
|
|
28
|
+
compliance: ['SOC2', 'PCI-DSS', 'ISO27001', 'NIST-CSF'],
|
|
29
|
+
effort: 'low',
|
|
30
|
+
fix: 'Use environment variables (process.env.DB_PASSWORD) instead of hardcoding secrets.',
|
|
31
|
+
documentationLink: 'https://owasp.org/www-community/vulnerabilities/Use_of_hard-coded_password',
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
schema: [],
|
|
35
|
+
},
|
|
36
|
+
defaultOptions: [],
|
|
37
|
+
create(context) {
|
|
38
|
+
return {
|
|
39
|
+
NewExpression(node) {
|
|
40
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || !['Client', 'Pool'].includes(node.callee.name)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (node.arguments.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
const configArg = node.arguments[0];
|
|
46
|
+
// Case 1: Connection string literal 'postgres://user:pass@localhost:5432/db'
|
|
47
|
+
if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof configArg.value === 'string') {
|
|
48
|
+
if (constants_1.PG_PROTOCOLS.some(protocol => configArg.value.includes(protocol))) {
|
|
49
|
+
context.report({
|
|
50
|
+
node: configArg,
|
|
51
|
+
messageId: 'noHardcodedCredentials',
|
|
52
|
+
});
|
|
53
|
+
return; // Return after reporting for Case 1
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Case 2: new Client({ password: 'secret', connectionString: '...' })
|
|
57
|
+
if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
58
|
+
for (const prop of configArg.properties) {
|
|
59
|
+
if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property || prop.key.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// Check for 'password' field
|
|
63
|
+
if (prop.key.name === 'password') {
|
|
64
|
+
if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
65
|
+
context.report({
|
|
66
|
+
node: prop.value,
|
|
67
|
+
messageId: 'noHardcodedCredentials',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Check for 'connectionString' field
|
|
73
|
+
if (prop.key.name === 'connectionString') {
|
|
74
|
+
if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
75
|
+
context.report({
|
|
76
|
+
node: prop.value,
|
|
77
|
+
messageId: 'noHardcodedCredentials',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoInsecureSslOptions } from '../../types';
|
|
8
|
+
export declare const noInsecureSsl: TSESLint.RuleModule<'noInsecureSsl', NoInsecureSslOptions>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noInsecureSsl = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
exports.noInsecureSsl = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Prevent the use of insecure SSL configurations (rejectUnauthorized: false).',
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-insecure-ssl.md',
|
|
16
|
+
cwe: 'CWE-319',
|
|
17
|
+
cvss: 7.5,
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
noInsecureSsl: (0, eslint_devkit_1.formatLLMMessage)({
|
|
21
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
22
|
+
issueName: 'Insecure SSL',
|
|
23
|
+
description: 'Insecure SSL configuration detected (rejectUnauthorized: false).',
|
|
24
|
+
severity: 'HIGH',
|
|
25
|
+
cwe: 'CWE-319',
|
|
26
|
+
owasp: 'A05:2021',
|
|
27
|
+
compliance: ['SOC2', 'PCI-DSS', 'HIPAA', 'GDPR'],
|
|
28
|
+
effort: 'low',
|
|
29
|
+
fix: 'Set "rejectUnauthorized: true" or use a valid CA bundle. Do not disable SSL verification in production.',
|
|
30
|
+
documentationLink: 'https://node-postgres.com/features/ssl',
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
schema: [],
|
|
34
|
+
},
|
|
35
|
+
defaultOptions: [],
|
|
36
|
+
create(context) {
|
|
37
|
+
return {
|
|
38
|
+
NewExpression(node) {
|
|
39
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || (node.callee.name !== 'Client' && node.callee.name !== 'Pool')) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const configArg = node.arguments[0];
|
|
43
|
+
if (!configArg || configArg.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const sslProp = configArg.properties.find((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property && prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && prop.key.name === 'ssl');
|
|
47
|
+
if (!sslProp)
|
|
48
|
+
return;
|
|
49
|
+
// ssl: { rejectUnauthorized: false }
|
|
50
|
+
if (sslProp.value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
51
|
+
const rejectUnauthorized = sslProp.value.properties.find((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
52
|
+
prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
53
|
+
prop.key.name === 'rejectUnauthorized');
|
|
54
|
+
if (rejectUnauthorized &&
|
|
55
|
+
rejectUnauthorized.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
56
|
+
rejectUnauthorized.value.value === false) {
|
|
57
|
+
context.report({
|
|
58
|
+
node: rejectUnauthorized,
|
|
59
|
+
messageId: 'noInsecureSsl',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoMissingClientReleaseOptions } from '../../types';
|
|
8
|
+
export declare const noMissingClientRelease: TSESLint.RuleModule<'missingClientRelease', NoMissingClientReleaseOptions>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noMissingClientRelease = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
exports.noMissingClientRelease = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Ensure pg client is released after use to prevent pool exhaustion.',
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-missing-client-release.md',
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
missingClientRelease: (0, eslint_devkit_1.formatLLMMessage)({
|
|
19
|
+
icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
|
|
20
|
+
issueName: 'Missing Client Release',
|
|
21
|
+
description: 'PG client acquired but not released.',
|
|
22
|
+
severity: 'HIGH',
|
|
23
|
+
cwe: 'CWE-404',
|
|
24
|
+
owasp: 'A05:2025',
|
|
25
|
+
effort: 'low',
|
|
26
|
+
fix: 'Ensure "client.release()" is called in a finally block to return the client to the pool.',
|
|
27
|
+
documentationLink: 'https://node-postgres.com/features/pooling#checkout-use-and-return',
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
schema: [],
|
|
31
|
+
},
|
|
32
|
+
defaultOptions: [],
|
|
33
|
+
create(context) {
|
|
34
|
+
return {
|
|
35
|
+
CallExpression(node) {
|
|
36
|
+
// Detect: const client = await pool.connect() or pool.connect().then(client => ...)
|
|
37
|
+
// For simplicity, we focus on await usage in async functions, which is the modern pattern.
|
|
38
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
39
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
40
|
+
node.callee.property.name !== 'connect') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// We assume valid code would assign the result: const client = await pool.connect()
|
|
44
|
+
// Parent of CallExpression is AwaitExpression (usually)
|
|
45
|
+
// Parent of AwaitExpression is VariableDeclarator
|
|
46
|
+
// Check ancestry up to VariableDeclarator
|
|
47
|
+
let currentNode = node;
|
|
48
|
+
if (node.parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression) {
|
|
49
|
+
currentNode = node.parent;
|
|
50
|
+
}
|
|
51
|
+
if (currentNode.parent?.type !== eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const declarator = currentNode.parent;
|
|
55
|
+
if (declarator.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
56
|
+
// Destructuring not supported for basic check yet
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Variable name is available as declarator.id.name if needed for debugging
|
|
60
|
+
// Find the scope of the variable
|
|
61
|
+
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
62
|
+
if (!variable)
|
|
63
|
+
return;
|
|
64
|
+
// Check references to this variable
|
|
65
|
+
// We look for client.release() call
|
|
66
|
+
const references = variable.references;
|
|
67
|
+
const hasReleaseCall = references.some(ref => {
|
|
68
|
+
const id = ref.identifier;
|
|
69
|
+
// Check if identifier is part of member expression 'client.release()' calls
|
|
70
|
+
return (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
71
|
+
id.parent.object === id &&
|
|
72
|
+
id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
73
|
+
id.parent.property.name === 'release' &&
|
|
74
|
+
id.parent.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression);
|
|
75
|
+
});
|
|
76
|
+
if (!hasReleaseCall) {
|
|
77
|
+
context.report({
|
|
78
|
+
node: declarator,
|
|
79
|
+
messageId: 'missingClientRelease',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoSelectAllOptions } from '../../types';
|
|
8
|
+
export declare const noSelectAll: TSESLint.RuleModule<'noSelectAll', NoSelectAllOptions>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noSelectAll = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
// Pre-compiled regex patterns for performance
|
|
11
|
+
const COUNT_STAR_REGEX = /COUNT\s*\(\s*\*\s*\)/g;
|
|
12
|
+
const SELECT_STAR_REGEX = /\bSELECT\s+\*/;
|
|
13
|
+
const COMMA_STAR_REGEX = /,\s*\*/;
|
|
14
|
+
const SELECT_KEYWORD_REGEX = /\bSELECT\b/;
|
|
15
|
+
const UNNEST_PATTERN_REGEX = /\bSELECT\s+\*\s+FROM\s+UNNEST\s*\(/;
|
|
16
|
+
exports.noSelectAll = {
|
|
17
|
+
meta: {
|
|
18
|
+
type: 'problem',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Prevent using * in SELECT statements (implicit columns).',
|
|
21
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-select-all.md',
|
|
22
|
+
cwe: 'CWE-1049',
|
|
23
|
+
cvss: 5,
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
noSelectAll: (0, eslint_devkit_1.formatLLMMessage)({
|
|
27
|
+
icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
|
|
28
|
+
issueName: 'Select All',
|
|
29
|
+
description: 'Avoid using "SELECT *" which fetches all columns.',
|
|
30
|
+
severity: 'MEDIUM',
|
|
31
|
+
cwe: 'CWE-1049',
|
|
32
|
+
effort: 'low',
|
|
33
|
+
fix: 'Explicitly list the columns you need (e.g., SELECT id, name FROM ...).',
|
|
34
|
+
documentationLink: 'https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_SELECT_.2A',
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
schema: [],
|
|
38
|
+
},
|
|
39
|
+
defaultOptions: [],
|
|
40
|
+
create(context) {
|
|
41
|
+
return {
|
|
42
|
+
CallExpression(node) {
|
|
43
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
44
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
45
|
+
node.callee.property.name !== 'query') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const args = node.arguments;
|
|
49
|
+
if (args.length === 0)
|
|
50
|
+
return;
|
|
51
|
+
const queryArg = args[0];
|
|
52
|
+
if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const queryText = queryArg.value;
|
|
56
|
+
const upperQuery = queryText.toUpperCase();
|
|
57
|
+
// Exclude count(*) from the check by removing it temporarily
|
|
58
|
+
const cleanedQuery = upperQuery.replace(COUNT_STAR_REGEX, 'COUNT_ALL');
|
|
59
|
+
// Check for "SELECT *"
|
|
60
|
+
// 1. SELECT followed immediately by * (with spaces) -> SELECT *
|
|
61
|
+
// 2. Comma followed by * -> SELECT a, *
|
|
62
|
+
// BUT exclude SELECT * FROM UNNEST which is idiomatic for bulk inserts
|
|
63
|
+
if (SELECT_STAR_REGEX.test(cleanedQuery) || COMMA_STAR_REGEX.test(cleanedQuery)) {
|
|
64
|
+
// Ensure it is actually a SELECT query
|
|
65
|
+
if (SELECT_KEYWORD_REGEX.test(cleanedQuery)) {
|
|
66
|
+
// Exclude SELECT * FROM UNNEST (idiomatic bulk insert pattern)
|
|
67
|
+
if (UNNEST_PATTERN_REGEX.test(cleanedQuery)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
context.report({
|
|
71
|
+
node: queryArg,
|
|
72
|
+
messageId: 'noSelectAll',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoTransactionOnPoolOptions } from '../../types';
|
|
8
|
+
export declare const noTransactionOnPool: TSESLint.RuleModule<'noTransactionOnPool', NoTransactionOnPoolOptions>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noTransactionOnPool = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
// Pre-defined set of transaction keywords for fast lookup
|
|
11
|
+
const TRANSACTION_KEYWORDS = new Set(['BEGIN', 'COMMIT', 'ROLLBACK']);
|
|
12
|
+
exports.noTransactionOnPool = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Prevent starting transactions directly on the Pool, which is unsafe due to lack of client affinity.',
|
|
17
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-transaction-on-pool.md',
|
|
18
|
+
cwe: 'CWE-662',
|
|
19
|
+
cweJustification: 'CWE-662 (Improper Synchronization) — running BEGIN/COMMIT on a connection pool can split a logical transaction across different physical clients, breaking ACID atomicity.',
|
|
20
|
+
confidence: 'high',
|
|
21
|
+
},
|
|
22
|
+
messages: {
|
|
23
|
+
noTransactionOnPool: (0, eslint_devkit_1.formatLLMMessage)({
|
|
24
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
25
|
+
issueName: 'Transaction on Pool',
|
|
26
|
+
description: 'Transactions should not be started on the Pool directly.',
|
|
27
|
+
severity: 'HIGH',
|
|
28
|
+
effort: 'low',
|
|
29
|
+
fix: 'Use "await pool.connect()" to get a client, then start the transaction on the client.',
|
|
30
|
+
documentationLink: 'https://node-postgres.com/features/transactions',
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
schema: [],
|
|
34
|
+
},
|
|
35
|
+
defaultOptions: [],
|
|
36
|
+
create(context) {
|
|
37
|
+
return {
|
|
38
|
+
CallExpression(node) {
|
|
39
|
+
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
|
|
40
|
+
node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
41
|
+
node.callee.property.name !== 'query') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const args = node.arguments;
|
|
45
|
+
if (args.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
const queryArg = args[0];
|
|
48
|
+
// Only check literals
|
|
49
|
+
if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const queryText = queryArg.value.toUpperCase().trim();
|
|
53
|
+
// Extract first word (handles "BEGIN", "BEGIN;", "BEGIN TRANSACTION", etc.)
|
|
54
|
+
const firstWord = queryText.split(/[;\s]/)[0];
|
|
55
|
+
if (TRANSACTION_KEYWORDS.has(firstWord)) {
|
|
56
|
+
// Heuristic: If the variable name is 'pool' or ends with 'Pool', stronger signal.
|
|
57
|
+
// However, for safety, if we see pool.query('BEGIN'), it's almost always wrong unless it's a test mock.
|
|
58
|
+
// Let's rely on variable name hint for false positive reduction, or just flag it generally.
|
|
59
|
+
// The most common error is `pool.query('BEGIN')`.
|
|
60
|
+
if (node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
61
|
+
(node.callee.object.name === 'pool' || node.callee.object.name.toLowerCase().includes('pool'))) {
|
|
62
|
+
context.report({
|
|
63
|
+
node: queryArg,
|
|
64
|
+
messageId: 'noTransactionOnPool',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { TSESLint } from '@interlace/eslint-devkit';
|
|
7
|
+
import { NoUnsafeCopyFromOptions } from '../../types';
|
|
8
|
+
type MessageIds = 'dynamicPath' | 'hardcodedPath' | 'unverifiablePath';
|
|
9
|
+
export declare const noUnsafeCopyFrom: TSESLint.RuleModule<MessageIds, NoUnsafeCopyFromOptions>;
|
|
10
|
+
export {};
|