eslint-plugin-postgresql-security 1.5.0 → 1.5.2

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.
Files changed (113) hide show
  1. package/README.md +5 -5
  2. package/package.json +9 -23
  3. package/src/constants.js +1 -0
  4. package/src/index.d.ts +17 -0
  5. package/src/index.js +1 -0
  6. package/src/oxlint.d.ts +17 -0
  7. package/src/oxlint.js +1 -0
  8. package/src/rules/check-query-params/index.js +1 -0
  9. package/src/rules/no-batch-insert-loop/index.js +1 -0
  10. package/src/rules/no-floating-query/index.js +1 -0
  11. package/src/rules/no-hardcoded-credentials/index.js +1 -0
  12. package/src/rules/no-insecure-ssl/index.js +1 -0
  13. package/src/rules/no-missing-client-release/index.js +1 -0
  14. package/src/rules/no-select-all/index.js +1 -0
  15. package/src/rules/no-transaction-on-pool/index.js +1 -0
  16. package/src/rules/no-unsafe-copy-from/index.js +1 -0
  17. package/src/rules/no-unsafe-query/index.js +1 -0
  18. package/src/rules/no-unsafe-search-path/index.js +1 -0
  19. package/src/rules/prefer-pool-query/index.js +1 -0
  20. package/src/rules/prevent-double-release/index.js +1 -0
  21. package/src/types/index.js +1 -0
  22. package/CHANGELOG.md +0 -150
  23. package/dist/AGENTS.md +0 -118
  24. package/dist/CHANGELOG.md +0 -150
  25. package/dist/LICENSE +0 -23
  26. package/dist/README.md +0 -169
  27. package/dist/package.json +0 -99
  28. package/dist/src/constants.d.ts +0 -6
  29. package/dist/src/constants.js +0 -13
  30. package/dist/src/index.d.ts +0 -26
  31. package/dist/src/index.js +0 -116
  32. package/dist/src/oxlint.d.ts +0 -20
  33. package/dist/src/oxlint.js +0 -21
  34. package/dist/src/rules/check-query-params/index.d.ts +0 -8
  35. package/dist/src/rules/check-query-params/index.js +0 -90
  36. package/dist/src/rules/no-batch-insert-loop/index.d.ts +0 -8
  37. package/dist/src/rules/no-batch-insert-loop/index.js +0 -90
  38. package/dist/src/rules/no-floating-query/index.d.ts +0 -8
  39. package/dist/src/rules/no-floating-query/index.js +0 -74
  40. package/dist/src/rules/no-hardcoded-credentials/index.d.ts +0 -8
  41. package/dist/src/rules/no-hardcoded-credentials/index.js +0 -86
  42. package/dist/src/rules/no-insecure-ssl/index.d.ts +0 -8
  43. package/dist/src/rules/no-insecure-ssl/index.js +0 -66
  44. package/dist/src/rules/no-missing-client-release/index.d.ts +0 -8
  45. package/dist/src/rules/no-missing-client-release/index.js +0 -85
  46. package/dist/src/rules/no-select-all/index.d.ts +0 -8
  47. package/dist/src/rules/no-select-all/index.js +0 -79
  48. package/dist/src/rules/no-transaction-on-pool/index.d.ts +0 -8
  49. package/dist/src/rules/no-transaction-on-pool/index.js +0 -71
  50. package/dist/src/rules/no-unsafe-copy-from/index.d.ts +0 -10
  51. package/dist/src/rules/no-unsafe-copy-from/index.js +0 -205
  52. package/dist/src/rules/no-unsafe-query/index.d.ts +0 -8
  53. package/dist/src/rules/no-unsafe-query/index.js +0 -132
  54. package/dist/src/rules/no-unsafe-search-path/index.d.ts +0 -8
  55. package/dist/src/rules/no-unsafe-search-path/index.js +0 -144
  56. package/dist/src/rules/prefer-pool-query/index.d.ts +0 -8
  57. package/dist/src/rules/prefer-pool-query/index.js +0 -104
  58. package/dist/src/rules/prevent-double-release/index.d.ts +0 -8
  59. package/dist/src/rules/prevent-double-release/index.js +0 -456
  60. package/dist/src/types/index.js +0 -7
  61. package/src/__compatibility__/pg-interface.spec.ts +0 -495
  62. package/src/constants.ts +0 -11
  63. package/src/index.spec.ts +0 -14
  64. package/src/index.test.ts +0 -59
  65. package/src/index.ts +0 -130
  66. package/src/oxlint.spec.ts +0 -70
  67. package/src/oxlint.ts +0 -23
  68. package/src/rules/check-query-params/check-query-params.test.ts +0 -68
  69. package/src/rules/check-query-params/index.spec.ts +0 -117
  70. package/src/rules/check-query-params/index.ts +0 -106
  71. package/src/rules/no-batch-insert-loop/index.spec.ts +0 -105
  72. package/src/rules/no-batch-insert-loop/index.ts +0 -105
  73. package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +0 -68
  74. package/src/rules/no-floating-query/index.spec.ts +0 -112
  75. package/src/rules/no-floating-query/index.ts +0 -81
  76. package/src/rules/no-floating-query/no-floating-query.test.ts +0 -68
  77. package/src/rules/no-hardcoded-credentials/index.spec.ts +0 -38
  78. package/src/rules/no-hardcoded-credentials/index.ts +0 -93
  79. package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +0 -68
  80. package/src/rules/no-insecure-ssl/index.spec.ts +0 -40
  81. package/src/rules/no-insecure-ssl/index.ts +0 -81
  82. package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +0 -68
  83. package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +0 -42
  84. package/src/rules/no-missing-client-release/index.spec.ts +0 -52
  85. package/src/rules/no-missing-client-release/index.ts +0 -100
  86. package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +0 -68
  87. package/src/rules/no-select-all/index.spec.ts +0 -44
  88. package/src/rules/no-select-all/index.ts +0 -92
  89. package/src/rules/no-select-all/no-select-all.test.ts +0 -68
  90. package/src/rules/no-transaction-on-pool/index.spec.ts +0 -36
  91. package/src/rules/no-transaction-on-pool/index.ts +0 -85
  92. package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +0 -68
  93. package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +0 -76
  94. package/src/rules/no-unsafe-copy-from/index.spec.ts +0 -274
  95. package/src/rules/no-unsafe-copy-from/index.ts +0 -226
  96. package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +0 -78
  97. package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +0 -61
  98. package/src/rules/no-unsafe-query/index.spec.ts +0 -103
  99. package/src/rules/no-unsafe-query/index.ts +0 -149
  100. package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +0 -73
  101. package/src/rules/no-unsafe-search-path/index.spec.ts +0 -46
  102. package/src/rules/no-unsafe-search-path/index.ts +0 -164
  103. package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +0 -68
  104. package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +0 -76
  105. package/src/rules/prefer-pool-query/index.spec.ts +0 -97
  106. package/src/rules/prefer-pool-query/index.ts +0 -118
  107. package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +0 -68
  108. package/src/rules/prevent-double-release/coverage-gaps.spec.ts +0 -538
  109. package/src/rules/prevent-double-release/index.spec.ts +0 -824
  110. package/src/rules/prevent-double-release/index.ts +0 -534
  111. package/src/rules/prevent-double-release/prevent-double-release.test.ts +0 -70
  112. package/src/types/index.ts +0 -58
  113. /package/{dist/src → src}/types/index.d.ts +0 -0
@@ -1,21 +0,0 @@
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
- /**
8
- * oxlint sub-export.
9
- *
10
- * Consumers wire oxlint to this entry via:
11
- * { "jsPlugins": ["eslint-plugin-postgresql-security/oxlint"] }
12
- *
13
- * oxlint's JS plugin loader does `require('eslint-plugin-postgresql-security/oxlint')` and reads
14
- * `.rules` off the result. The compiled output of `export = plugin` is
15
- * `module.exports = plugin`, which gives oxlint the plugin object directly
16
- * (`{ meta, rules }`) — no wrapper, no `.default` indirection.
17
- *
18
- * Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
19
- */
20
- const index_1 = require("./index");
21
- module.exports = index_1.plugin;
@@ -1,8 +0,0 @@
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 { CheckQueryParamsOptions } from '../../types';
8
- export declare const checkQueryParams: TSESLint.RuleModule<'parameterCountMismatch', CheckQueryParamsOptions>;
@@ -1,90 +0,0 @@
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.checkQueryParams = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Pre-compiled regex patterns for performance
11
- const SINGLE_QUOTE_REGEX = /'(?:[^']|'')*'/g;
12
- const DOUBLE_QUOTE_REGEX = /"(?:[^"]|"")*"/g;
13
- const LINE_COMMENT_REGEX = /--.*/g;
14
- const BLOCK_COMMENT_REGEX = /\/\*[\s\S]*?\*\//g;
15
- const PARAM_REGEX = /\$\d+/g;
16
- exports.checkQueryParams = {
17
- meta: {
18
- type: 'problem',
19
- docs: {
20
- description: 'Ensure the number of query parameters matches the arguments array.',
21
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/check-query-params.md',
22
- cwe: 'CWE-20',
23
- cvss: 7.5,
24
- },
25
- messages: {
26
- parameterCountMismatch: (0, eslint_devkit_1.formatLLMMessage)({
27
- icon: eslint_devkit_1.MessageIcons.QUALITY,
28
- issueName: 'Parameter Count Mismatch',
29
- description: 'Query parameter count mismatch detected.',
30
- severity: 'HIGH',
31
- cwe: 'CWE-20',
32
- effort: 'low',
33
- fix: 'Ensure the number of arguments matches the number of placeholders ($1, $2, etc.).',
34
- documentationLink: 'https://node-postgres.com/features/queries',
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 < 2)
50
- return;
51
- const queryArg = args[0];
52
- const valuesArg = args[1];
53
- if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
54
- return; // Can't statically analyze dynamic queries
55
- }
56
- if (valuesArg.type !== eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
57
- return; // Can't statically count dynamic arrays
58
- }
59
- const queryText = queryArg.value;
60
- // Remove strings, quoted identifiers, and comments to avoid false positives
61
- const cleanText = queryText
62
- .replace(SINGLE_QUOTE_REGEX, '')
63
- .replace(DOUBLE_QUOTE_REGEX, '')
64
- .replace(LINE_COMMENT_REGEX, '')
65
- .replace(BLOCK_COMMENT_REGEX, '');
66
- const matches = cleanText.match(PARAM_REGEX);
67
- let maxParamIndex = 0;
68
- if (matches) {
69
- const indices = matches.map(m => parseInt(m.substring(1), 10));
70
- maxParamIndex = Math.max(0, ...indices);
71
- }
72
- // PG allows gaps, but essentially the highest index determines needed array length.
73
- // Actually, strictly speaking, if you use $2, you should provide at least 2 args.
74
- // But commonly, people mean "number of unique placeholders".
75
- // Let's enforce that array length >= max param index.
76
- const providedArgCount = valuesArg.elements.length;
77
- if (providedArgCount < maxParamIndex) {
78
- context.report({
79
- node: valuesArg,
80
- messageId: 'parameterCountMismatch',
81
- data: {
82
- expected: maxParamIndex.toString(),
83
- actual: providedArgCount.toString(),
84
- },
85
- });
86
- }
87
- },
88
- };
89
- },
90
- };
@@ -1,8 +0,0 @@
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 { NoBatchInsertLoopOptions } from '../../types';
8
- export declare const noBatchInsertLoop: TSESLint.RuleModule<'noBatchInsertLoop', NoBatchInsertLoopOptions>;
@@ -1,90 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;
@@ -1,74 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;
@@ -1,86 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;
@@ -1,66 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;
@@ -1,85 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;