eslint-plugin-postgresql-security 1.5.1 → 1.5.3

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/README.md CHANGED
@@ -92,7 +92,7 @@ src/db.ts
92
92
  ## 📦 Compatibility
93
93
  | Package | Version |
94
94
  | :--- | :--- |
95
- | ESLint | `^8.0.0 \|\| ^9.0.0 \|\| ^10.0.0` |
95
+ | ESLint | `^8.40.0 \|\| ^9.0.0 \|\| ^10.0.0` |
96
96
  | Node.js | `>=18.0.0` |
97
97
 
98
98
  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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-postgresql-security",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "ESLint plugin for the pg PostgreSQL driver — detects SQL injection, unreleased clients, floating queries, unsafe search_path, and insecure SSL.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -67,7 +67,7 @@
67
67
  "node": ">=18.0.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
70
+ "eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
71
71
  "pg": "^6.0.0 || ^7.0.0 || ^8.0.0"
72
72
  },
73
73
  "peerDependenciesMeta": {
@@ -76,7 +76,7 @@
76
76
  }
77
77
  },
78
78
  "dependencies": {
79
- "@interlace/eslint-devkit": "^1.8.0"
79
+ "@interlace/eslint-devkit": "^1.11.0"
80
80
  },
81
81
  "funding": {
82
82
  "type": "github",
package/src/constants.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PG_PROTOCOLS = void 0;
4
- exports.PG_PROTOCOLS = ['postgres://', 'postgresql://'];
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.PG_PROTOCOLS=void 0;exports.PG_PROTOCOLS=["postgres://","postgresql://"];
package/src/index.js CHANGED
@@ -1,75 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configs = exports.plugin = exports.rules = void 0;
4
- exports.rules = {
5
- get 'no-unsafe-query'() { return require("./rules/no-unsafe-query").noUnsafeQuery; },
6
- get 'no-insecure-ssl'() { return require("./rules/no-insecure-ssl").noInsecureSsl; },
7
- get 'no-hardcoded-credentials'() { return require("./rules/no-hardcoded-credentials").noHardcodedCredentials; },
8
- get 'check-query-params'() { return require("./rules/check-query-params").checkQueryParams; },
9
- get 'no-missing-client-release'() { return require("./rules/no-missing-client-release").noMissingClientRelease; },
10
- get 'no-transaction-on-pool'() { return require("./rules/no-transaction-on-pool").noTransactionOnPool; },
11
- get 'no-floating-query'() { return require("./rules/no-floating-query").noFloatingQuery; },
12
- get 'no-select-all'() { return require("./rules/no-select-all").noSelectAll; },
13
- get 'prefer-pool-query'() { return require("./rules/prefer-pool-query").preferPoolQuery; },
14
- get 'no-batch-insert-loop'() { return require("./rules/no-batch-insert-loop").noBatchInsertLoop; },
15
- get 'no-unsafe-search-path'() { return require("./rules/no-unsafe-search-path").noUnsafeSearchPath; },
16
- get 'no-unsafe-copy-from'() { return require("./rules/no-unsafe-copy-from").noUnsafeCopyFrom; },
17
- get 'prevent-double-release'() { return require("./rules/prevent-double-release").preventDoubleRelease; },
18
-
19
- };
20
- exports.plugin = {
21
- meta: {
22
- name: 'eslint-plugin-postgresql-security',
23
- version: '1.5.1',
24
- },
25
- rules: exports.rules,
26
- };
27
- exports.configs = {
28
- flagship: {
29
- plugins: { 'pg': exports.plugin },
30
- rules: {
31
- 'pg/no-unsafe-query': 'error',
32
- },
33
- },
34
- recommended: {
35
- plugins: {
36
- 'pg': exports.plugin,
37
- },
38
- rules: {
39
- 'pg/no-unsafe-query': 'error',
40
- 'pg/no-insecure-ssl': 'error',
41
- 'pg/no-hardcoded-credentials': 'error',
42
- 'pg/no-unsafe-search-path': 'error',
43
- 'pg/no-unsafe-copy-from': 'error',
44
- 'pg/no-transaction-on-pool': 'error',
45
- 'pg/no-missing-client-release': 'error',
46
- 'pg/prevent-double-release': 'error',
47
- 'pg/no-floating-query': 'error',
48
- 'pg/check-query-params': 'warn',
49
- 'pg/no-select-all': 'warn',
50
- 'pg/prefer-pool-query': 'warn',
51
- 'pg/no-batch-insert-loop': 'warn',
52
- },
53
- },
54
- strict: {
55
- plugins: {
56
- 'pg': exports.plugin,
57
- },
58
- rules: {
59
- 'pg/no-unsafe-query': 'error',
60
- 'pg/no-insecure-ssl': 'error',
61
- 'pg/no-hardcoded-credentials': 'error',
62
- 'pg/no-unsafe-search-path': 'error',
63
- 'pg/no-unsafe-copy-from': 'error',
64
- 'pg/no-transaction-on-pool': 'error',
65
- 'pg/no-missing-client-release': 'error',
66
- 'pg/prevent-double-release': 'error',
67
- 'pg/no-floating-query': 'error',
68
- 'pg/check-query-params': 'error',
69
- 'pg/no-select-all': 'error',
70
- 'pg/prefer-pool-query': 'error',
71
- 'pg/no-batch-insert-loop': 'error',
72
- },
73
- },
74
- };
75
- exports.default = exports.plugin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;exports.rules={get"no-unsafe-query"(){return require("./rules/no-unsafe-query").noUnsafeQuery},get"no-insecure-ssl"(){return require("./rules/no-insecure-ssl").noInsecureSsl},get"no-hardcoded-credentials"(){return require("./rules/no-hardcoded-credentials").noHardcodedCredentials},get"check-query-params"(){return require("./rules/check-query-params").checkQueryParams},get"no-missing-client-release"(){return require("./rules/no-missing-client-release").noMissingClientRelease},get"no-transaction-on-pool"(){return require("./rules/no-transaction-on-pool").noTransactionOnPool},get"no-floating-query"(){return require("./rules/no-floating-query").noFloatingQuery},get"no-select-all"(){return require("./rules/no-select-all").noSelectAll},get"prefer-pool-query"(){return require("./rules/prefer-pool-query").preferPoolQuery},get"no-batch-insert-loop"(){return require("./rules/no-batch-insert-loop").noBatchInsertLoop},get"no-unsafe-search-path"(){return require("./rules/no-unsafe-search-path").noUnsafeSearchPath},get"no-unsafe-copy-from"(){return require("./rules/no-unsafe-copy-from").noUnsafeCopyFrom},get"prevent-double-release"(){return require("./rules/prevent-double-release").preventDoubleRelease}};exports.plugin={meta:{name:"eslint-plugin-postgresql-security",version:"1.5.3"},rules:exports.rules};exports.configs={flagship:{plugins:{"pg":exports.plugin},rules:{"pg/no-unsafe-query":"error"}},recommended:{plugins:{"pg":exports.plugin},rules:{"pg/no-unsafe-query":"error","pg/no-insecure-ssl":"error","pg/no-hardcoded-credentials":"error","pg/no-unsafe-search-path":"error","pg/no-unsafe-copy-from":"error","pg/no-transaction-on-pool":"error","pg/no-missing-client-release":"error","pg/prevent-double-release":"error","pg/no-floating-query":"error","pg/check-query-params":"warn","pg/no-select-all":"warn","pg/prefer-pool-query":"warn","pg/no-batch-insert-loop":"warn"}},strict:{plugins:{"pg":exports.plugin},rules:{"pg/no-unsafe-query":"error","pg/no-insecure-ssl":"error","pg/no-hardcoded-credentials":"error","pg/no-unsafe-search-path":"error","pg/no-unsafe-copy-from":"error","pg/no-transaction-on-pool":"error","pg/no-missing-client-release":"error","pg/prevent-double-release":"error","pg/no-floating-query":"error","pg/check-query-params":"error","pg/no-select-all":"error","pg/prefer-pool-query":"error","pg/no-batch-insert-loop":"error"}}};exports.default=exports.plugin;
package/src/oxlint.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";
2
- const index_1 = require("./index");
3
- module.exports = index_1.plugin;
1
+ "use strict";const index_1=require("./index");module.exports=index_1.plugin;
@@ -1,79 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkQueryParams = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const SINGLE_QUOTE_REGEX = /'(?:[^']|'')*'/g;
6
- const DOUBLE_QUOTE_REGEX = /"(?:[^"]|"")*"/g;
7
- const LINE_COMMENT_REGEX = /--.*/g;
8
- const BLOCK_COMMENT_REGEX = /\/\*[\s\S]*?\*\//g;
9
- const PARAM_REGEX = /\$\d+/g;
10
- exports.checkQueryParams = {
11
- meta: {
12
- type: 'problem',
13
- docs: {
14
- description: 'Ensure the number of query parameters matches the arguments array.',
15
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/check-query-params.md',
16
- cwe: 'CWE-20',
17
- cvss: 7.5,
18
- },
19
- messages: {
20
- parameterCountMismatch: (0, eslint_devkit_1.formatLLMMessage)({
21
- icon: eslint_devkit_1.MessageIcons.QUALITY,
22
- issueName: 'Parameter Count Mismatch',
23
- description: 'Query parameter count mismatch detected.',
24
- severity: 'HIGH',
25
- cwe: 'CWE-20',
26
- effort: 'low',
27
- fix: 'Ensure the number of arguments matches the number of placeholders ($1, $2, etc.).',
28
- documentationLink: 'https://node-postgres.com/features/queries',
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 < 2)
44
- return;
45
- const queryArg = args[0];
46
- const valuesArg = args[1];
47
- if (queryArg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal || typeof queryArg.value !== 'string') {
48
- return;
49
- }
50
- if (valuesArg.type !== eslint_devkit_1.AST_NODE_TYPES.ArrayExpression) {
51
- return;
52
- }
53
- const queryText = queryArg.value;
54
- const cleanText = queryText
55
- .replace(SINGLE_QUOTE_REGEX, '')
56
- .replace(DOUBLE_QUOTE_REGEX, '')
57
- .replace(LINE_COMMENT_REGEX, '')
58
- .replace(BLOCK_COMMENT_REGEX, '');
59
- const matches = cleanText.match(PARAM_REGEX);
60
- let maxParamIndex = 0;
61
- if (matches) {
62
- const indices = matches.map(m => parseInt(m.substring(1), 10));
63
- maxParamIndex = Math.max(0, ...indices);
64
- }
65
- const providedArgCount = valuesArg.elements.length;
66
- if (providedArgCount < maxParamIndex) {
67
- context.report({
68
- node: valuesArg,
69
- messageId: 'parameterCountMismatch',
70
- data: {
71
- expected: maxParamIndex.toString(),
72
- actual: providedArgCount.toString(),
73
- },
74
- });
75
- }
76
- },
77
- };
78
- },
79
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.checkQueryParams=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SINGLE_QUOTE_REGEX=/'(?:[^']|'')*'/g;const DOUBLE_QUOTE_REGEX=/"(?:[^"]|"")*"/g;const LINE_COMMENT_REGEX=/--.*/g;const BLOCK_COMMENT_REGEX=/\/\*[\s\S]*?\*\//g;const PARAM_REGEX=/\$\d+/g;exports.checkQueryParams={meta:{type:"problem",docs:{description:"Ensure the number of query parameters matches the arguments array.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/check-query-params.md",cwe:"CWE-20",cvss:7.5},messages:{parameterCountMismatch:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.QUALITY,issueName:"Parameter Count Mismatch",description:"Query parameter count mismatch detected.",severity:"HIGH",cwe:"CWE-20",effort:"low",fix:"Ensure the number of arguments matches the number of placeholders ($1, $2, etc.).",documentationLink:"https://node-postgres.com/features/queries"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length<2)return;const queryArg=args[0];const valuesArg=args[1];if(queryArg.type!==eslint_devkit_1.AST_NODE_TYPES.Literal||typeof queryArg.value!=="string"){return}if(valuesArg.type!==eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){return}const queryText=queryArg.value;const cleanText=queryText.replace(SINGLE_QUOTE_REGEX,"").replace(DOUBLE_QUOTE_REGEX,"").replace(LINE_COMMENT_REGEX,"").replace(BLOCK_COMMENT_REGEX,"");const matches=cleanText.match(PARAM_REGEX);let maxParamIndex=0;if(matches){const indices=matches.map(m=>parseInt(m.substring(1),10));maxParamIndex=Math.max(0,...indices)}const providedArgCount=valuesArg.elements.length;if(providedArgCount<maxParamIndex){context.report({node:valuesArg,messageId:"parameterCountMismatch",data:{expected:maxParamIndex.toString(),actual:providedArgCount.toString()}})}}}}};
@@ -1,77 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noBatchInsertLoop = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noBatchInsertLoop = {
6
- meta: {
7
- type: 'problem',
8
- docs: {
9
- description: 'Prevent executing database queries within loops (N+1 problem).',
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-batch-insert-loop.md',
11
- cwe: 'CWE-1049',
12
- cvss: 7.5,
13
- },
14
- messages: {
15
- noBatchInsertLoop: (0, eslint_devkit_1.formatLLMMessage)({
16
- icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
17
- issueName: 'N+1 Query Detection',
18
- description: 'Database query loop detected.',
19
- severity: 'HIGH',
20
- cwe: 'CWE-1049',
21
- effort: 'medium',
22
- fix: 'Batch queries using arrays and "UNNEST" or a single batched INSERT.',
23
- documentationLink: 'https://use-the-index-luke.com/sql/joins/nested-loops-join-n1-problem',
24
- }),
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- return {
31
- CallExpression(node) {
32
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
33
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
34
- node.callee.property.name !== 'query') {
35
- return;
36
- }
37
- const args = node.arguments;
38
- if (args.length > 0 && args[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof args[0].value === 'string') {
39
- const query = args[0].value.toUpperCase();
40
- if (!query.includes('INSERT') && !query.includes('UPDATE')) {
41
- return;
42
- }
43
- }
44
- let ancestor = node.parent;
45
- while (ancestor) {
46
- if (ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForStatement ||
47
- ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForOfStatement ||
48
- ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ForInStatement ||
49
- ancestor.type === eslint_devkit_1.AST_NODE_TYPES.WhileStatement ||
50
- ancestor.type === eslint_devkit_1.AST_NODE_TYPES.DoWhileStatement) {
51
- context.report({
52
- node,
53
- messageId: 'noBatchInsertLoop',
54
- });
55
- break;
56
- }
57
- if ((ancestor.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression || ancestor.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
58
- if (ancestor.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
59
- ancestor.parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
60
- ancestor.parent.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
61
- ['map', 'forEach', 'reduce', 'filter'].includes(ancestor.parent.callee.property.name)) {
62
- context.report({
63
- node,
64
- messageId: 'noBatchInsertLoop',
65
- });
66
- break;
67
- }
68
- if (ancestor.parent?.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
69
- break;
70
- }
71
- }
72
- ancestor = ancestor.parent;
73
- }
74
- },
75
- };
76
- },
77
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noBatchInsertLoop=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noBatchInsertLoop={meta:{type:"problem",docs:{description:"Prevent executing database queries within loops (N+1 problem).",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-batch-insert-loop.md",cwe:"CWE-1049",cvss:7.5},messages:{noBatchInsertLoop:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"N+1 Query Detection",description:"Database query loop detected.",severity:"HIGH",cwe:"CWE-1049",effort:"medium",fix:'Batch queries using arrays and "UNNEST" or a single batched INSERT.',documentationLink:"https://use-the-index-luke.com/sql/joins/nested-loops-join-n1-problem"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const args=node.arguments;if(args.length>0&&args[0].type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof args[0].value==="string"){const query=args[0].value.toUpperCase();if(!query.includes("INSERT")&&!query.includes("UPDATE")){return}}let ancestor=node.parent;while(ancestor){if(ancestor.type===eslint_devkit_1.AST_NODE_TYPES.ForStatement||ancestor.type===eslint_devkit_1.AST_NODE_TYPES.ForOfStatement||ancestor.type===eslint_devkit_1.AST_NODE_TYPES.ForInStatement||ancestor.type===eslint_devkit_1.AST_NODE_TYPES.WhileStatement||ancestor.type===eslint_devkit_1.AST_NODE_TYPES.DoWhileStatement){context.report({node,messageId:"noBatchInsertLoop"});break}if(ancestor.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression||ancestor.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression){if(ancestor.parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&ancestor.parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&ancestor.parent.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["map","forEach","reduce","filter"].includes(ancestor.parent.callee.property.name)){context.report({node,messageId:"noBatchInsertLoop"});break}if(ancestor.parent?.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression){break}}ancestor=ancestor.parent}}}}};
@@ -1,59 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noFloatingQuery = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noFloatingQuery = {
6
- meta: {
7
- type: 'problem',
8
- docs: {
9
- description: 'Ensure all queries are awaited or returned to prevent unhandled promise rejections.',
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-floating-query.md',
11
- cwe: 'CWE-391',
12
- cvss: 5.3,
13
- },
14
- messages: {
15
- noFloatingQuery: (0, eslint_devkit_1.formatLLMMessage)({
16
- icon: eslint_devkit_1.MessageIcons.WARNING,
17
- issueName: 'Floating Query',
18
- description: 'Promise-returning query is neither awaited nor returned.',
19
- severity: 'HIGH',
20
- cwe: 'CWE-391',
21
- effort: 'low',
22
- fix: 'Add "await" or "return" to handle the query promise.',
23
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise',
24
- }),
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- return {
31
- CallExpression(node) {
32
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
33
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
34
- node.callee.property.name !== 'query') {
35
- return;
36
- }
37
- const parent = node.parent;
38
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression)
39
- return;
40
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)
41
- return;
42
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)
43
- return;
44
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)
45
- return;
46
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
47
- return;
48
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression)
49
- return;
50
- if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement) {
51
- context.report({
52
- node,
53
- messageId: 'noFloatingQuery',
54
- });
55
- }
56
- },
57
- };
58
- },
59
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noFloatingQuery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noFloatingQuery={meta:{type:"problem",docs:{description:"Ensure all queries are awaited or returned to prevent unhandled promise rejections.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-floating-query.md",cwe:"CWE-391",cvss:5.3},messages:{noFloatingQuery:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Floating Query",description:"Promise-returning query is neither awaited nor returned.",severity:"HIGH",cwe:"CWE-391",effort:"low",fix:'Add "await" or "return" to handle the query promise.',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="query"){return}const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression)return;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement){context.report({node,messageId:"noFloatingQuery"})}}}}};
@@ -1,77 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noHardcodedCredentials = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const constants_1 = require("../../constants");
6
- exports.noHardcodedCredentials = {
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- description: 'Detect hardcoded credentials in pg Client or Pool initialization.',
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-hardcoded-credentials.md',
12
- cwe: 'CWE-798',
13
- cvss: 9.8,
14
- },
15
- messages: {
16
- noHardcodedCredentials: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Hardcoded Credentials',
19
- description: 'Hardcoded credentials detected in database connection.',
20
- severity: 'CRITICAL',
21
- cwe: 'CWE-798',
22
- owasp: 'A07:2021',
23
- compliance: ['SOC2', 'PCI-DSS', 'ISO27001', 'NIST-CSF'],
24
- effort: 'low',
25
- fix: 'Use environment variables (process.env.DB_PASSWORD) instead of hardcoding secrets.',
26
- documentationLink: 'https://owasp.org/www-community/vulnerabilities/Use_of_hard-coded_password',
27
- }),
28
- },
29
- schema: [],
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- return {
34
- NewExpression(node) {
35
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || !['Client', 'Pool'].includes(node.callee.name)) {
36
- return;
37
- }
38
- if (node.arguments.length === 0)
39
- return;
40
- const configArg = node.arguments[0];
41
- if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof configArg.value === 'string') {
42
- if (constants_1.PG_PROTOCOLS.some(protocol => configArg.value.includes(protocol))) {
43
- context.report({
44
- node: configArg,
45
- messageId: 'noHardcodedCredentials',
46
- });
47
- return;
48
- }
49
- }
50
- if (configArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
51
- for (const prop of configArg.properties) {
52
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property || prop.key.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
53
- continue;
54
- }
55
- if (prop.key.name === 'password') {
56
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
57
- context.report({
58
- node: prop.value,
59
- messageId: 'noHardcodedCredentials',
60
- });
61
- }
62
- continue;
63
- }
64
- if (prop.key.name === 'connectionString') {
65
- if (prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
66
- context.report({
67
- node: prop.value,
68
- messageId: 'noHardcodedCredentials',
69
- });
70
- }
71
- }
72
- }
73
- }
74
- },
75
- };
76
- },
77
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHardcodedCredentials=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const constants_1=require("../../constants");exports.noHardcodedCredentials={meta:{type:"problem",docs:{description:"Detect hardcoded credentials in pg Client or Pool initialization.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-hardcoded-credentials.md",cwe:"CWE-798",cvss:9.8},messages:{noHardcodedCredentials:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Hardcoded Credentials",description:"Hardcoded credentials detected in database connection.",severity:"CRITICAL",cwe:"CWE-798",owasp:"A07:2021",compliance:["SOC2","PCI-DSS","ISO27001","NIST-CSF"],effort:"low",fix:"Use environment variables (process.env.DB_PASSWORD) instead of hardcoding secrets.",documentationLink:"https://owasp.org/www-community/vulnerabilities/Use_of_hard-coded_password"})},schema:[]},defaultOptions:[],create(context){return{NewExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!["Client","Pool"].includes(node.callee.name)){return}if(node.arguments.length===0)return;const configArg=node.arguments[0];if(configArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof configArg.value==="string"){if(constants_1.PG_PROTOCOLS.some(protocol=>configArg.value.includes(protocol))){context.report({node:configArg,messageId:"noHardcodedCredentials"});return}}if(configArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of configArg.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property||prop.key.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){continue}if(prop.key.name==="password"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal){context.report({node:prop.value,messageId:"noHardcodedCredentials"})}continue}if(prop.key.name==="connectionString"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal){context.report({node:prop.value,messageId:"noHardcodedCredentials"})}}}}}}}};
@@ -1,60 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noInsecureSsl = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noInsecureSsl = {
6
- meta: {
7
- type: 'problem',
8
- docs: {
9
- description: 'Prevent the use of insecure SSL configurations (rejectUnauthorized: false).',
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-insecure-ssl.md',
11
- cwe: 'CWE-319',
12
- cvss: 7.5,
13
- },
14
- messages: {
15
- noInsecureSsl: (0, eslint_devkit_1.formatLLMMessage)({
16
- icon: eslint_devkit_1.MessageIcons.SECURITY,
17
- issueName: 'Insecure SSL',
18
- description: 'Insecure SSL configuration detected (rejectUnauthorized: false).',
19
- severity: 'HIGH',
20
- cwe: 'CWE-319',
21
- owasp: 'A05:2021',
22
- compliance: ['SOC2', 'PCI-DSS', 'HIPAA', 'GDPR'],
23
- effort: 'low',
24
- fix: 'Set "rejectUnauthorized: true" or use a valid CA bundle. Do not disable SSL verification in production.',
25
- documentationLink: 'https://node-postgres.com/features/ssl',
26
- }),
27
- },
28
- schema: [],
29
- },
30
- defaultOptions: [],
31
- create(context) {
32
- return {
33
- NewExpression(node) {
34
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || (node.callee.name !== 'Client' && node.callee.name !== 'Pool')) {
35
- return;
36
- }
37
- const configArg = node.arguments[0];
38
- if (!configArg || configArg.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
39
- return;
40
- }
41
- 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');
42
- if (!sslProp)
43
- return;
44
- if (sslProp.value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
45
- const rejectUnauthorized = sslProp.value.properties.find((prop) => prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
46
- prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
47
- prop.key.name === 'rejectUnauthorized');
48
- if (rejectUnauthorized &&
49
- rejectUnauthorized.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
50
- rejectUnauthorized.value.value === false) {
51
- context.report({
52
- node: rejectUnauthorized,
53
- messageId: 'noInsecureSsl',
54
- });
55
- }
56
- }
57
- },
58
- };
59
- },
60
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInsecureSsl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noInsecureSsl={meta:{type:"problem",docs:{description:"Prevent the use of insecure SSL configurations (rejectUnauthorized: false).",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-insecure-ssl.md",cwe:"CWE-319",cvss:7.5},messages:{noInsecureSsl:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure SSL",description:"Insecure SSL configuration detected (rejectUnauthorized: false).",severity:"HIGH",cwe:"CWE-319",owasp:"A05:2021",compliance:["SOC2","PCI-DSS","HIPAA","GDPR"],effort:"low",fix:'Set "rejectUnauthorized: true" or use a valid CA bundle. Do not disable SSL verification in production.',documentationLink:"https://node-postgres.com/features/ssl"})},schema:[]},defaultOptions:[],create(context){return{NewExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.name!=="Client"&&node.callee.name!=="Pool"){return}const configArg=node.arguments[0];if(!configArg||configArg.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){return}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");if(!sslProp)return;if(sslProp.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const rejectUnauthorized=sslProp.value.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==="rejectUnauthorized");if(rejectUnauthorized&&rejectUnauthorized.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&rejectUnauthorized.value.value===false){context.report({node:rejectUnauthorized,messageId:"noInsecureSsl"})}}}}}};
@@ -1,68 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noMissingClientRelease = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noMissingClientRelease = {
6
- meta: {
7
- type: 'problem',
8
- docs: {
9
- description: 'Ensure pg client is released after use to prevent pool exhaustion.',
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-missing-client-release.md',
11
- },
12
- messages: {
13
- missingClientRelease: (0, eslint_devkit_1.formatLLMMessage)({
14
- icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
15
- issueName: 'Missing Client Release',
16
- description: 'PG client acquired but not released.',
17
- severity: 'HIGH',
18
- cwe: 'CWE-404',
19
- owasp: 'A05:2025',
20
- effort: 'low',
21
- fix: 'Ensure "client.release()" is called in a finally block to return the client to the pool.',
22
- documentationLink: 'https://node-postgres.com/features/pooling#checkout-use-and-return',
23
- }),
24
- },
25
- schema: [],
26
- },
27
- defaultOptions: [],
28
- create(context) {
29
- return {
30
- CallExpression(node) {
31
- if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression ||
32
- node.callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
33
- node.callee.property.name !== 'connect') {
34
- return;
35
- }
36
- let currentNode = node;
37
- if (node.parent?.type === eslint_devkit_1.AST_NODE_TYPES.AwaitExpression) {
38
- currentNode = node.parent;
39
- }
40
- if (currentNode.parent?.type !== eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator) {
41
- return;
42
- }
43
- const declarator = currentNode.parent;
44
- if (declarator.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
45
- return;
46
- }
47
- const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
48
- if (!variable)
49
- return;
50
- const references = variable.references;
51
- const hasReleaseCall = references.some(ref => {
52
- const id = ref.identifier;
53
- return (id.parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
54
- id.parent.object === id &&
55
- id.parent.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
56
- id.parent.property.name === 'release' &&
57
- id.parent.parent?.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression);
58
- });
59
- if (!hasReleaseCall) {
60
- context.report({
61
- node: declarator,
62
- messageId: 'missingClientRelease',
63
- });
64
- }
65
- },
66
- };
67
- },
68
- };
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingClientRelease=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noMissingClientRelease={meta:{type:"problem",docs:{description:"Ensure pg client is released after use to prevent pool exhaustion.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/no-missing-client-release.md"},messages:{missingClientRelease:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Missing Client Release",description:"PG client acquired but not released.",severity:"HIGH",cwe:"CWE-404",owasp:"A05:2025",effort:"low",fix:'Ensure "client.release()" is called in a finally block to return the client to the pool.',documentationLink:"https://node-postgres.com/features/pooling#checkout-use-and-return"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.callee.property.name!=="connect"){return}let currentNode=node;if(node.parent?.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression){currentNode=node.parent}if(currentNode.parent?.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator){return}const declarator=currentNode.parent;if(declarator.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){return}const variable=context.sourceCode.getDeclaredVariables(declarator)[0];if(!variable)return;const references=variable.references;const hasReleaseCall=references.some(ref=>{const id=ref.identifier;return id.parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&id.parent.object===id&&id.parent.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&id.parent.property.name==="release"&&id.parent.parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression});if(!hasReleaseCall){context.report({node:declarator,messageId:"missingClientRelease"})}}}}};