eslint-plugin-postgresql-security 2.3.3 → 2.3.5

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
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="90" /></picture></a>
2
+ <a href="https://eslint.interlace.tools/docs/security/plugin-postgresql-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="90" /></picture></a>
3
3
  &nbsp;&nbsp;
4
4
  <a href="https://www.postgresql.org" target="_blank"><img src="https://eslint.interlace.tools/logos/postgresql.svg" alt="PostgreSQL" height="90" /></a>
5
5
  &nbsp;&nbsp;
@@ -203,5 +203,5 @@ MIT © [Ofri Peretz](https://github.com/ofri-peretz)
203
203
  </p>
204
204
 
205
205
  <p align="center">
206
- <a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="70" /></picture></a>
206
+ <a href="https://eslint.interlace.tools/docs/security/plugin-postgresql-security?utm_source=github&utm_medium=referral&utm_campaign=eslint-plugin-postgresql-security" target="blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://eslint.interlace.tools/logos/interlace-dark.svg"><img src="https://eslint.interlace.tools/logos/interlace-light.svg" alt="Interlace" height="70" /></picture></a>
207
207
  </p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-postgresql-security",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
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",
@@ -76,10 +76,18 @@
76
76
  }
77
77
  },
78
78
  "dependencies": {
79
- "@interlace/eslint-devkit": "^1.19.1"
79
+ "@interlace/eslint-devkit": "^1.19.2"
80
80
  },
81
81
  "funding": {
82
82
  "type": "github",
83
83
  "url": "https://github.com/ofri-peretz/eslint"
84
+ },
85
+ "interlace": {
86
+ "surface": {
87
+ "kind": "npm",
88
+ "modules": [
89
+ "pg"
90
+ ]
91
+ }
84
92
  }
85
93
  }
package/src/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");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}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-postgresql-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-postgresql-security",version:"2.3.3"},rules:exports.rules};exports.configs={flagship:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error"}},recommended:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error","postgresql-security/no-insecure-ssl":"error","postgresql-security/no-hardcoded-credentials":"error","postgresql-security/no-unsafe-search-path":"error","postgresql-security/no-unsafe-copy-from":"error","postgresql-security/no-transaction-on-pool":"error","postgresql-security/no-missing-client-release":"error","postgresql-security/prevent-double-release":"error","postgresql-security/no-floating-query":"error","postgresql-security/check-query-params":"warn","postgresql-security/no-select-all":"warn","postgresql-security/prefer-pool-query":"warn","postgresql-security/no-batch-insert-loop":"warn"}},strict:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error","postgresql-security/no-insecure-ssl":"error","postgresql-security/no-hardcoded-credentials":"error","postgresql-security/no-unsafe-search-path":"error","postgresql-security/no-unsafe-copy-from":"error","postgresql-security/no-transaction-on-pool":"error","postgresql-security/no-missing-client-release":"error","postgresql-security/prevent-double-release":"error","postgresql-security/no-floating-query":"error","postgresql-security/check-query-params":"error","postgresql-security/no-select-all":"error","postgresql-security/prefer-pool-query":"error","postgresql-security/no-batch-insert-loop":"error"}}};exports.default=exports.plugin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");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}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-postgresql-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-postgresql-security",version:"2.3.5"},rules:exports.rules};exports.configs={flagship:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error"}},recommended:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error","postgresql-security/no-insecure-ssl":"error","postgresql-security/no-hardcoded-credentials":"error","postgresql-security/no-unsafe-search-path":"error","postgresql-security/no-unsafe-copy-from":"error","postgresql-security/no-transaction-on-pool":"error","postgresql-security/no-missing-client-release":"error","postgresql-security/prevent-double-release":"error","postgresql-security/no-floating-query":"error","postgresql-security/check-query-params":"warn","postgresql-security/no-select-all":"warn","postgresql-security/prefer-pool-query":"warn","postgresql-security/no-batch-insert-loop":"warn"}},strict:{plugins:{"postgresql-security":exports.plugin,"pg":exports.plugin},rules:{"postgresql-security/no-unsafe-query":"error","postgresql-security/no-insecure-ssl":"error","postgresql-security/no-hardcoded-credentials":"error","postgresql-security/no-unsafe-search-path":"error","postgresql-security/no-unsafe-copy-from":"error","postgresql-security/no-transaction-on-pool":"error","postgresql-security/no-missing-client-release":"error","postgresql-security/prevent-double-release":"error","postgresql-security/no-floating-query":"error","postgresql-security/check-query-params":"error","postgresql-security/no-select-all":"error","postgresql-security/prefer-pool-query":"error","postgresql-security/no-batch-insert-loop":"error"}}};exports.default=exports.plugin;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingClientRelease=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const PG_MODULE_SET=new Set(utils_1.PG_MODULES);function isPgPoolConstructor(callee,scope){const binding=(0,eslint_devkit_1.resolveModuleBinding)(callee,scope);if(binding===void 0)return false;const parts=binding.module.split("/");const root=binding.module.startsWith("@")?parts.slice(0,2).join("/"):parts[0];if(!PG_MODULE_SET.has(root))return false;const[exported]=binding.path;return exported===void 0||exported==="Pool"}function isPgPool(receiver,scope,poolProperties){if(receiver.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&receiver.object.type===eslint_devkit_1.AST_NODE_TYPES.ThisExpression&&(0,eslint_devkit_1.propertyName)(receiver)!==null){return(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(receiver),poolProperties)}if(receiver.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;for(let current=scope;current;current=current.upper){const variable=current.set.get(receiver.name);if(variable===void 0)continue;if(variable.references.filter(ref=>ref.isWrite()).length!==1)return false;const def=variable.defs.find(d=>d.type==="Variable");const init=def===void 0?null:def.node.init;if(init==null||init.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression)return false;return isPgPoolConstructor(init.callee,scope)}return false}function isReleaseCall(identifier){const member=identifier.parent;if(member?.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||member.object!==identifier||(0,eslint_devkit_1.propertyName)(member)!=="release"){return false}return member.parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&member.parent.callee===member}function isInsideFinally(node){for(let current=node.parent;current;current=current.parent){if(current.parent?.type===eslint_devkit_1.AST_NODE_TYPES.TryStatement&&current.parent.finalizer===current){return true}}return false}function transfersOwnership(identifier){const parent=identifier.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){return parent.arguments.includes(identifier)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.Property)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===identifier){return true}return false}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"}),releaseNotGuaranteed:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Client Release Not Guaranteed",description:"PG client is released on some paths but not all. A throw, an early return or a rejected query skips the release and leaks the connection.",severity:"HIGH",cwe:"CWE-404",owasp:"A05:2025",effort:"low",fix:'Move "client.release()" into a finally block so it runs on every path out of the function.',documentationLink:"https://node-postgres.com/features/pooling#checkout-use-and-return"})},schema:[]},defaultOptions:[],create(context){if(!(0,utils_1.fileUsesPostgres)(context.sourceCode.ast))return{};const poolProperties=new Set;return{AssignmentExpression(node){if(node.operator!=="="||node.left.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.left.object.type!==eslint_devkit_1.AST_NODE_TYPES.ThisExpression||node.left.computed||node.left.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.right.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression){return}if(isPgPoolConstructor(node.right.callee,context.sourceCode.getScope(node))){poolProperties.add(node.left.property.name)}},PropertyDefinition(node){if(node.computed||node.key.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.value==null||node.value.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression){return}if(isPgPoolConstructor(node.value.callee,context.sourceCode.getScope(node))){poolProperties.add(node.key.name)}},"CallExpression:exit"(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||(0,eslint_devkit_1.propertyName)(node.callee)!=="connect"){return}if(!isPgPool(node.callee.object,context.sourceCode.getScope(node),poolProperties)){return}const checkout=node.parent?.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression?node.parent:node;if(checkout.parent?.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)return;const declarator=checkout.parent;if(declarator.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return;const uses=context.sourceCode.getDeclaredVariables(declarator).flatMap(variable=>variable.references.map(ref=>ref.identifier));if(uses.some(id=>transfersOwnership(id)))return;const releases=uses.filter(id=>isReleaseCall(id));if(releases.length===0){context.report({node:declarator,messageId:"missingClientRelease"});return}if(!releases.some(id=>isInsideFinally(id))){context.report({node:declarator,messageId:"releaseNotGuaranteed"})}}}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingClientRelease=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const PG_MODULE_SET=new Set(utils_1.PG_MODULES);function isPgPoolConstructor(callee,scope){const binding=(0,eslint_devkit_1.resolveModuleBinding)(callee,scope);if(binding===void 0)return false;const parts=binding.module.split("/");const root=binding.module.startsWith("@")?parts.slice(0,2).join("/"):parts[0];if(!PG_MODULE_SET.has(root))return false;const[exported]=binding.path;return exported===void 0||exported==="Pool"}function isPgPool(receiver,scope,poolProperties){if(receiver.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&receiver.object.type===eslint_devkit_1.AST_NODE_TYPES.ThisExpression&&(0,eslint_devkit_1.propertyName)(receiver)!==null){return(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(receiver),poolProperties)}if(receiver.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;for(let current=scope;current;current=current.upper){const variable=current.set.get(receiver.name);if(variable===void 0)continue;if(variable.references.filter(ref=>ref.isWrite()).length!==1)return false;const def=variable.defs.find(d=>d.type==="Variable");const init=def===void 0?null:def.node.init;if(init==null||init.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression)return false;return isPgPoolConstructor(init.callee,scope)}return false}function isReleaseCall(identifier){const member=identifier.parent;if(member?.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||member.object!==identifier||(0,eslint_devkit_1.propertyName)(member)!=="release"){return false}return member.parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&member.parent.callee===member}function isInsideFinally(node){for(let current=node.parent;current;current=current.parent){if(current.parent?.type===eslint_devkit_1.AST_NODE_TYPES.TryStatement&&current.parent.finalizer===current){return true}}return false}function transfersOwnership(identifier){const parent=identifier.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){return parent.arguments.includes(identifier)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.Property)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression)return true;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===identifier){return true}return false}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",cwe:"CWE-404"},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"}),releaseNotGuaranteed:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Client Release Not Guaranteed",description:"PG client is released on some paths but not all. A throw, an early return or a rejected query skips the release and leaks the connection.",severity:"HIGH",cwe:"CWE-404",owasp:"A05:2025",effort:"low",fix:'Move "client.release()" into a finally block so it runs on every path out of the function.',documentationLink:"https://node-postgres.com/features/pooling#checkout-use-and-return"})},schema:[]},defaultOptions:[],create(context){if(!(0,utils_1.fileUsesPostgres)(context.sourceCode.ast))return{};const poolProperties=new Set;return{AssignmentExpression(node){if(node.operator!=="="||node.left.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.left.object.type!==eslint_devkit_1.AST_NODE_TYPES.ThisExpression||node.left.computed||node.left.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.right.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression){return}if(isPgPoolConstructor(node.right.callee,context.sourceCode.getScope(node))){poolProperties.add(node.left.property.name)}},PropertyDefinition(node){if(node.computed||node.key.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.value==null||node.value.type!==eslint_devkit_1.AST_NODE_TYPES.NewExpression){return}if(isPgPoolConstructor(node.value.callee,context.sourceCode.getScope(node))){poolProperties.add(node.key.name)}},"CallExpression:exit"(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||(0,eslint_devkit_1.propertyName)(node.callee)!=="connect"){return}if(!isPgPool(node.callee.object,context.sourceCode.getScope(node),poolProperties)){return}const checkout=node.parent?.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression?node.parent:node;if(checkout.parent?.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator)return;const declarator=checkout.parent;if(declarator.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return;const uses=context.sourceCode.getDeclaredVariables(declarator).flatMap(variable=>variable.references.map(ref=>ref.identifier));if(uses.some(id=>transfersOwnership(id)))return;const releases=uses.filter(id=>isReleaseCall(id));if(releases.length===0){context.report({node:declarator,messageId:"missingClientRelease"});return}if(!releases.some(id=>isInsideFinally(id))){context.report({node:declarator,messageId:"releaseNotGuaranteed"})}}}}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.preferPoolQuery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const SESSION_STATEMENTS=[/^begin\b/i,/^start\s+transaction\b/i,/^commit\b/i,/^end\b/i,/^rollback\b/i,/^savepoint\b/i,/^release\s+savepoint\b/i,/^set\b/i,/^reset\b/i,/^discard\b/i,/^listen\b/i,/^unlisten\b/i,/^notify\b/i,/^declare\b/i,/^fetch\b/i,/^move\b/i,/^close\b/i,/^copy\b/i,/^prepare\b/i,/^execute\b/i,/^deallocate\b/i,/^lock\b/i];const SESSION_FUNCTIONS=/\bpg_(?:try_)?advisory_(?:xact_)?(?:un)?lock\w*\s*\(|\bpg_export_snapshot\s*\(/i;function needsSessionAffinity(text){const trimmed=text.trim();return SESSION_STATEMENTS.some(pattern=>pattern.test(trimmed))||SESSION_FUNCTIONS.test(trimmed)}function statementText(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(quasi=>quasi.value.cooked).join(" 1 ")}if(node.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const text=node.properties.find(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&!property.computed&&property.key.name==="text");return text===void 0?null:statementText(text.value)}return null}function isFunctionOrProgram(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.Program}function isLoop(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.ForStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.ForOfStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.ForInStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.WhileStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.DoWhileStatement}function owningScopeNode(node){let current=node;while(!isFunctionOrProgram(current)){current=current.parent}return current}function runsExactlyOnce(call,declarator){const owner=owningScopeNode(declarator);for(let node=call.parent;node&&node!==owner;node=node.parent){if(isLoop(node)||isFunctionOrProgram(node))return false}return true}exports.preferPoolQuery={meta:{type:"suggestion",docs:{description:"Prefer pool.query() over client.query() for single-shot queries.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prefer-pool-query.md"},messages:{preferPoolQuery:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Prefer Pool Query",description:"Single-shot queries should use pool.query() directly.",severity:"MEDIUM",cwe:"CWE-400",effort:"low",fix:"Use pool.query(...) instead of manual client checkout/release for simple queries.",documentationLink:"https://node-postgres.com/features/pooling"})},schema:[]},defaultOptions:[],create(context){if(!(0,utils_1.fileUsesPostgres)(context.sourceCode.ast))return{};return{VariableDeclarator(node){if(!node.init||node.init.type!==eslint_devkit_1.AST_NODE_TYPES.AwaitExpression||node.init.argument.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression||node.init.argument.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.init.argument.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.init.argument.callee.property.name!=="connect"){return}const[variable]=context.sourceCode.getDeclaredVariables(node);if(!variable)return;let queryCallCount=0;let releaseCallCount=0;let otherUsageCount=0;for(const ref of variable.references){if(ref.isWrite())continue;const id=ref.identifier;const access=id.parent;if(access===void 0||access.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||access.object!==id||access.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){otherUsageCount+=1;continue}if(access.property.name==="release"){releaseCallCount+=1;continue}if(access.property.name!=="query"){otherUsageCount+=1;continue}queryCallCount+=1;const call=access.parent;if(call===void 0||call.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression){otherUsageCount+=1;continue}if(!runsExactlyOnce(call,node))return;const[queryArg]=call.arguments;if(queryArg===void 0)return;const text=statementText(queryArg);if(text===null||needsSessionAffinity(text))return}if(queryCallCount===1&&releaseCallCount===1&&otherUsageCount===0){context.report({node,messageId:"preferPoolQuery"})}}}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.preferPoolQuery=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const SESSION_STATEMENTS=[/^begin\b/i,/^start\s+transaction\b/i,/^commit\b/i,/^end\b/i,/^rollback\b/i,/^savepoint\b/i,/^release\s+savepoint\b/i,/^set\b/i,/^reset\b/i,/^discard\b/i,/^listen\b/i,/^unlisten\b/i,/^notify\b/i,/^declare\b/i,/^fetch\b/i,/^move\b/i,/^close\b/i,/^copy\b/i,/^prepare\b/i,/^execute\b/i,/^deallocate\b/i,/^lock\b/i];const SESSION_FUNCTIONS=/\bpg_(?:try_)?advisory_(?:xact_)?(?:un)?lock\w*\s*\(|\bpg_export_snapshot\s*\(/i;function needsSessionAffinity(text){const trimmed=text.trim();return SESSION_STATEMENTS.some(pattern=>pattern.test(trimmed))||SESSION_FUNCTIONS.test(trimmed)}function statementText(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(quasi=>quasi.value.cooked).join(" 1 ")}if(node.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const text=node.properties.find(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&!property.computed&&property.key.name==="text");return text===void 0?null:statementText(text.value)}return null}function isFunctionOrProgram(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.Program}function isLoop(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.ForStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.ForOfStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.ForInStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.WhileStatement||node.type===eslint_devkit_1.AST_NODE_TYPES.DoWhileStatement}function owningScopeNode(node){let current=node;while(!isFunctionOrProgram(current)){current=current.parent}return current}function runsExactlyOnce(call,declarator){const owner=owningScopeNode(declarator);for(let node=call.parent;node&&node!==owner;node=node.parent){if(isLoop(node)||isFunctionOrProgram(node))return false}return true}exports.preferPoolQuery={meta:{type:"suggestion",docs:{description:"Prefer pool.query() over client.query() for single-shot queries.",url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-postgresql-security/docs/rules/prefer-pool-query.md",cwe:"CWE-400"},messages:{preferPoolQuery:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.PERFORMANCE,issueName:"Prefer Pool Query",description:"Single-shot queries should use pool.query() directly.",severity:"MEDIUM",cwe:"CWE-400",effort:"low",fix:"Use pool.query(...) instead of manual client checkout/release for simple queries.",documentationLink:"https://node-postgres.com/features/pooling"})},schema:[]},defaultOptions:[],create(context){if(!(0,utils_1.fileUsesPostgres)(context.sourceCode.ast))return{};return{VariableDeclarator(node){if(!node.init||node.init.type!==eslint_devkit_1.AST_NODE_TYPES.AwaitExpression||node.init.argument.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression||node.init.argument.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||node.init.argument.callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.init.argument.callee.property.name!=="connect"){return}const[variable]=context.sourceCode.getDeclaredVariables(node);if(!variable)return;let queryCallCount=0;let releaseCallCount=0;let otherUsageCount=0;for(const ref of variable.references){if(ref.isWrite())continue;const id=ref.identifier;const access=id.parent;if(access===void 0||access.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||access.object!==id||access.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){otherUsageCount+=1;continue}if(access.property.name==="release"){releaseCallCount+=1;continue}if(access.property.name!=="query"){otherUsageCount+=1;continue}queryCallCount+=1;const call=access.parent;if(call===void 0||call.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression){otherUsageCount+=1;continue}if(!runsExactlyOnce(call,node))return;const[queryArg]=call.arguments;if(queryArg===void 0)return;const text=statementText(queryArg);if(text===null||needsSessionAffinity(text))return}if(queryCallCount===1&&releaseCallCount===1&&otherUsageCount===0){context.report({node,messageId:"preferPoolQuery"})}}}}};