@interlace/eslint-devkit 1.21.3 → 1.21.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "1.21.3",
3
+ "version": "1.21.4",
4
4
  "description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.classifyPayload=classifyPayload;exports.createMassAssignmentRule=createMassAssignmentRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const request_source_1=require("./request-source");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const value_follow_1=require("./value-follow");function classifyPayload(node,env,isOurs=()=>false){if((0,request_source_1.isRequestPayload)(node,env))return"untrustedPayload";if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const variable=(0,value_follow_1.lookup)(node.name,env.scopeOf(node));const filled=variable?.references.some(reference=>{const call=reference.identifier.parent;if(call===void 0||!isObjectAssign(call))return false;const args=call.arguments;return args[0]===reference.identifier&&!isOurs(reference.identifier)&&args.slice(1).some(source=>(0,request_source_1.isRequestPayload)(source,env))});if(filled===true)return"untrustedPayload"}if(node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;if((0,request_source_1.isRequestPayload)(prop.argument,env))return"untrustedSpread"}}return false}function isObjectAssign(node){return node.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&node.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="Object"&&!node.callee.computed&&node.callee.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="assign"}const WRITE_VERBS=new Set(["insert","update"]);function createMassAssignmentRule(config){const methods=new Set(config.methods);const payloadKeys=new Set(config.payloadKeys??[]);const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{untrustedPayload:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"The request object is written straight to the database, so every column the model exposes is settable by the caller \u2014 including ones this code never mentions.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink}),untrustedSpread:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"Spreading the request into the payload carries every key it happens to hold, not just the ones written beside it.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;const isOurs=node=>originOf((0,value_follow_1.valueAt)(node,env))==="ours";const hasDistinctiveShape=node=>{const callee=node.callee;switch(config.distinctiveShape){case"model-accessor":return callee.object.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;case"table-call":{const chained=(0,unscoped_mutation_rule_1.chainMethodNames)(node);return(0,unscoped_mutation_rule_1.startsWithTable)(callee.object)||["into","table","from"].some(m=>chained.has(m))}case"builder-chain":{const object=callee.object;return object.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&object.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&WRITE_VERBS.has(object.callee.property.name)}default:return false}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;return true},Program(program){ownsFile=usesModule(program)},CallExpression(node){if(isObjectAssign(node)){const[target,...sources]=node.arguments;if(target===void 0||!isOurs(target))return;for(const source of sources){if((0,request_source_1.isRequestPayload)(source,env))context.report({node:source,messageId:"untrustedPayload"})}return}if(node.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||node.callee.property.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||!methods.has(node.callee.property.name)){return}const origin=originOf((0,value_follow_1.valueAt)(node.callee.object,env));if(origin==="foreign")return;if(origin==="unknown"&&!(ownsFile&&hasDistinctiveShape(node))){return}if(config.allowlistOption!==void 0&&node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&arg.properties.some(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&(0,unscoped_mutation_rule_1.propertyKeyName)(p)===config.allowlistOption))){return}for(const arg of node.arguments){if(arg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;const direct=classifyPayload(arg,env,isOurs);if(direct){context.report({node:arg,messageId:direct});continue}if(arg.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)continue;for(const prop of arg.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0||!payloadKeys.has(name))continue;const nested=classifyPayload(prop.value,env,isOurs);if(nested)context.report({node:prop.value,messageId:nested})}}}}}})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.classifyPayload=classifyPayload;exports.createMassAssignmentRule=createMassAssignmentRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const request_source_1=require("./request-source");const spellings_1=require("../ast/spellings");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const value_follow_1=require("./value-follow");function classifyPayload(node,env,isOurs=()=>false){if((0,request_source_1.isRequestPayload)(node,env))return"untrustedPayload";if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const variable=(0,value_follow_1.lookup)(node.name,env.scopeOf(node));const filled=variable?.references.some(reference=>{const call=reference.identifier.parent;if(call===void 0||!isObjectAssign(call))return false;const args=call.arguments;return args[0]===reference.identifier&&!isOurs(reference.identifier)&&args.slice(1).some(source=>(0,request_source_1.isRequestPayload)(source,env))});if(filled===true)return"untrustedPayload"}if(node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;if((0,request_source_1.isRequestPayload)(prop.argument,env))return"untrustedSpread"}}return false}function isObjectAssign(node){return node.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&node.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="Object"&&!node.callee.computed&&node.callee.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="assign"}const WRITE_VERBS=new Set(["insert","update"]);function createMassAssignmentRule(config){const methods=new Set(config.methods);const payloadKeys=new Set(config.payloadKeys??[]);const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{untrustedPayload:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"The request object is written straight to the database, so every column the model exposes is settable by the caller \u2014 including ones this code never mentions.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink}),untrustedSpread:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Mass Assignment",description:"Spreading the request into the payload carries every key it happens to hold, not just the ones written beside it.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A04:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"medium",fix:config.fix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;const isOurs=node=>originOf((0,value_follow_1.valueAt)(node,env))==="ours";const hasDistinctiveShape=node=>{const callee=node.callee;switch(config.distinctiveShape){case"model-accessor":return callee.object.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;case"table-call":{const chained=(0,unscoped_mutation_rule_1.chainMethodNames)(node);return(0,unscoped_mutation_rule_1.startsWithTable)(callee.object)||["into","table","from"].some(m=>chained.has(m))}case"builder-chain":{const object=callee.object;return object.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&object.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&WRITE_VERBS.has((0,spellings_1.propertyName)(object.callee)??"")}default:return false}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;return true},Program(program){ownsFile=usesModule(program)},CallExpression(node){if(isObjectAssign(node)){const[target,...sources]=node.arguments;if(target===void 0||!isOurs(target))return;for(const source of sources){if((0,request_source_1.isRequestPayload)(source,env))context.report({node:source,messageId:"untrustedPayload"})}return}if(node.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||!methods.has((0,spellings_1.propertyName)(node.callee)??"")){return}const origin=originOf((0,value_follow_1.valueAt)(node.callee.object,env));if(origin==="foreign")return;if(origin==="unknown"&&!(ownsFile&&hasDistinctiveShape(node))){return}if(config.allowlistOption!==void 0&&node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&arg.properties.some(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&(0,unscoped_mutation_rule_1.propertyKeyName)(p)===config.allowlistOption))){return}for(const arg of node.arguments){if(arg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;const direct=classifyPayload(arg,env,isOurs);if(direct){context.report({node:arg,messageId:direct});continue}if(arg.type!==ast_node_types_1.AST_NODE_TYPES.ObjectExpression)continue;for(const prop of arg.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0||!payloadKeys.has(name))continue;const nested=classifyPayload(prop.value,env,isOurs);if(nested)context.report({node:prop.value,messageId:nested})}}}}}})}
@@ -84,6 +84,12 @@ export declare function looksLikeConnectionConfig(obj: TSESTree.ObjectExpression
84
84
  * driver parses as a connection option, so this is not a finding.
85
85
  */
86
86
  export declare function urlDisablesTls(value: string, schemes: readonly string[]): boolean;
87
+ /**
88
+ * What a connection URL turns off: TLS itself (`sslmode=disable`,
89
+ * `ssl=false`), or only the certificate check (`sslmode=no-verify`, which
90
+ * pg-connection-string maps to `ssl: { rejectUnauthorized: false }`).
91
+ */
92
+ export declare function urlTlsFinding(value: string, schemes: readonly string[]): RequireTlsMessageIds | null;
87
93
  /** Is `inner` inside (or the same node as) `outer`? */
88
94
  export declare function within(inner: TSESTree.Node, outer: TSESTree.Node): boolean;
89
95
  /**
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isLiteralBoolean=isLiteralBoolean;exports.looksLikeConnectionConfig=looksLikeConnectionConfig;exports.urlDisablesTls=urlDisablesTls;exports.within=within;exports.inConnectionPosition=inConnectionPosition;exports.createRequireTlsRule=createRequireTlsRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const connection_config_1=require("./connection-config");const value_follow_1=require("./value-follow");const DEFAULT_CONNECTION_KEYS=["host","hostname","port","user","username","password","database","connectionString","socketPath","uri","url","connection","pool","schema"];const TLS_OFF_KEYS=["ssl","secure","tls","encrypt","useSSL","requireSSL"];const VERIFY_OFF_KEYS=["rejectUnauthorized","verifyServerCertificate","checkServerIdentity","trustServerCertificate"];function isLiteralBoolean(value,expect){if(value.type!==ast_node_types_1.AST_NODE_TYPES.Literal)return false;if(typeof value.value!=="boolean"){return expect===false&&!value.value}return value.value===expect}function looksLikeConnectionConfig(obj,connectionKeys){return obj.properties.some(prop=>{const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);return name!==void 0&&connectionKeys.includes(name)})}function urlDisablesTls(value,schemes){if(!schemes.some(scheme=>value.startsWith(`${scheme}://`)))return false;const query=value.split("#")[0];return/[?&](?:sslmode=disable|ssl=(?:false|0))(?:&|$)/i.test(query)}function within(inner,outer){return outer.range[0]<=inner.range[0]&&inner.range[1]<=outer.range[1]}function inConnectionPosition(node,connectionKeys,isDriverCallee){const parent=node.parent;if(!parent)return false;if(parent.type===ast_node_types_1.AST_NODE_TYPES.Property&&parent.value===node){const name=(0,unscoped_mutation_rule_1.propertyKeyName)(parent);return name!==void 0&&connectionKeys.includes(name)}if(parent.type===ast_node_types_1.AST_NODE_TYPES.CallExpression||parent.type===ast_node_types_1.AST_NODE_TYPES.NewExpression){if(!parent.arguments.includes(node))return false;return isDriverCallee(parent.callee)}return false}function createRequireTlsRule(config){const connectionKeys=[...DEFAULT_CONNECTION_KEYS,...config.connectionKeys??[]];const urlSchemes=config.urlSchemes??[];const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules,extraEvidence:(0,connection_config_1.configShapeEvidence)(config.configShapes??[])});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{tlsDisabled:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Cleartext Database Connection",description:"TLS is explicitly disabled on this database connection. Queries, result rows and the credentials that open the session all cross the network in cleartext.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A02:2021",compliance:["SOC2","PCI-DSS","HIPAA","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),certificateValidationDisabled:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unverified Database TLS Peer",description:"Certificate validation is disabled on this database connection. The traffic is encrypted but the server is never authenticated, so it encrypts just as willingly to whoever answered in its place.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A02:2021",compliance:["SOC2","PCI-DSS","HIPAA","NIST-CSF"],effort:"medium",fix:"Supply the server CA instead of switching verification off \u2014 `ssl: { ca: fs.readFileSync(caPath) }`. If the certificate is self-signed, add that CA to the trust store rather than trusting everything.",documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;let reported;function isDriverCallee(callee){return originOf((0,value_follow_1.valueAt)(callee,env))==="ours"}const report=(node,messageId)=>{if(reported.has(node))return;reported.add(node);context.report({node,messageId})};const judgeProperty=(prop,name,depth)=>{const tlsKey=TLS_OFF_KEYS.includes(name);const verifyKey=VERIFY_OFF_KEYS.includes(name);const inverted=name==="trustServerCertificate";for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(prop.value,env))){const inline=value.env===env&&within(value.node,prop.value);if(tlsKey&&isLiteralBoolean(value.node,false)){report(prop,"tlsDisabled");return}if(verifyKey&&isLiteralBoolean(value.node,inverted)){report(prop,"certificateValidationDisabled");return}if(value.node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&(tlsKey||connectionKeys.includes(name))){if(inline)scanTlsKeys(value.node,depth+1);else if(disablesTls(value.node))report(prop,"certificateValidationDisabled")}}};const disablesTls=obj=>obj.properties.some(prop=>prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&VERIFY_OFF_KEYS.includes((0,unscoped_mutation_rule_1.propertyKeyName)(prop))&&isLiteralBoolean(prop.value,(0,unscoped_mutation_rule_1.propertyKeyName)(prop)==="trustServerCertificate"));const scanTlsKeys=(obj,depth=0)=>{if(depth>4)return;for(const prop of obj.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0)continue;judgeProperty(prop,name,depth)}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;reported=new WeakSet;return true},Program(program){ownsFile=usesModule(program)},ObjectExpression(node){if(!ownsFile)return;if(!looksLikeConnectionConfig(node,connectionKeys))return;if((0,connection_config_1.passedToForeign)(node,originOf,env))return;scanTlsKeys(node)},Literal(node){if(!ownsFile)return;if(typeof node.value!=="string")return;if(!urlDisablesTls(node.value,urlSchemes))return;if(!inConnectionPosition(node,connectionKeys,isDriverCallee))return;context.report({node,messageId:"tlsDisabled"})}}}})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isLiteralBoolean=isLiteralBoolean;exports.looksLikeConnectionConfig=looksLikeConnectionConfig;exports.urlDisablesTls=urlDisablesTls;exports.urlTlsFinding=urlTlsFinding;exports.within=within;exports.inConnectionPosition=inConnectionPosition;exports.createRequireTlsRule=createRequireTlsRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const connection_config_1=require("./connection-config");const value_follow_1=require("./value-follow");const DEFAULT_CONNECTION_KEYS=["host","hostname","port","user","username","password","database","connectionString","socketPath","uri","url","connection","pool","schema"];const TLS_OFF_KEYS=["ssl","secure","tls","encrypt","useSSL","requireSSL"];const VERIFY_OFF_KEYS=["rejectUnauthorized","verifyServerCertificate","checkServerIdentity","trustServerCertificate"];function isLiteralBoolean(value,expect){if(value.type!==ast_node_types_1.AST_NODE_TYPES.Literal)return false;if(typeof value.value!=="boolean"){return expect===false&&!value.value}return value.value===expect}function looksLikeConnectionConfig(obj,connectionKeys){return obj.properties.some(prop=>{const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);return name!==void 0&&connectionKeys.includes(name)})}function urlDisablesTls(value,schemes){return urlTlsFinding(value,schemes)==="tlsDisabled"}function urlTlsFinding(value,schemes){if(!schemes.some(scheme=>value.startsWith(`${scheme}://`)))return null;const query=value.split("#")[0];if(/[?&](?:sslmode=disable|ssl=(?:false|0))(?:&|$)/i.test(query))return"tlsDisabled";if(/[?&]sslmode=no-verify(?:&|$)/i.test(query))return"certificateValidationDisabled";return null}function within(inner,outer){return outer.range[0]<=inner.range[0]&&inner.range[1]<=outer.range[1]}function inConnectionPosition(node,connectionKeys,isDriverCallee){const parent=node.parent;if(!parent)return false;if(parent.type===ast_node_types_1.AST_NODE_TYPES.Property&&parent.value===node){const name=(0,unscoped_mutation_rule_1.propertyKeyName)(parent);return name!==void 0&&connectionKeys.includes(name)}if(parent.type===ast_node_types_1.AST_NODE_TYPES.CallExpression||parent.type===ast_node_types_1.AST_NODE_TYPES.NewExpression){if(!parent.arguments.includes(node))return false;return isDriverCallee(parent.callee)}return false}function createRequireTlsRule(config){const connectionKeys=[...DEFAULT_CONNECTION_KEYS,...config.connectionKeys??[]];const urlSchemes=config.urlSchemes??[];const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules,extraEvidence:(0,connection_config_1.configShapeEvidence)(config.configShapes??[])});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{tlsDisabled:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Cleartext Database Connection",description:"TLS is explicitly disabled on this database connection. Queries, result rows and the credentials that open the session all cross the network in cleartext.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A02:2021",compliance:["SOC2","PCI-DSS","HIPAA","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),certificateValidationDisabled:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unverified Database TLS Peer",description:"Certificate validation is disabled on this database connection. The traffic is encrypted but the server is never authenticated, so it encrypts just as willingly to whoever answered in its place.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A02:2021",compliance:["SOC2","PCI-DSS","HIPAA","NIST-CSF"],effort:"medium",fix:"Supply the server CA instead of switching verification off \u2014 `ssl: { ca: fs.readFileSync(caPath) }`. If the certificate is self-signed, add that CA to the trust store rather than trusting everything.",documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;let reported;function isDriverCallee(callee){return originOf((0,value_follow_1.valueAt)(callee,env))==="ours"}const report=(node,messageId)=>{if(reported.has(node))return;reported.add(node);context.report({node,messageId})};const judgeProperty=(prop,name,depth)=>{const tlsKey=TLS_OFF_KEYS.includes(name);const verifyKey=VERIFY_OFF_KEYS.includes(name);const inverted=name==="trustServerCertificate";for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(prop.value,env))){const inline=value.env===env&&within(value.node,prop.value);if(tlsKey&&isLiteralBoolean(value.node,false)){report(prop,"tlsDisabled");return}if(verifyKey&&isLiteralBoolean(value.node,inverted)){report(prop,"certificateValidationDisabled");return}if(value.node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&(tlsKey||connectionKeys.includes(name))){if(inline)scanTlsKeys(value.node,depth+1);else if(disablesTls(value.node))report(prop,"certificateValidationDisabled")}}};const disablesTls=obj=>obj.properties.some(prop=>prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&VERIFY_OFF_KEYS.includes((0,unscoped_mutation_rule_1.propertyKeyName)(prop))&&isLiteralBoolean(prop.value,(0,unscoped_mutation_rule_1.propertyKeyName)(prop)==="trustServerCertificate"));const scanTlsKeys=(obj,depth=0)=>{if(depth>4)return;for(const prop of obj.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0)continue;judgeProperty(prop,name,depth)}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;reported=new WeakSet;return true},Program(program){ownsFile=usesModule(program)},ObjectExpression(node){if(!ownsFile)return;if(!looksLikeConnectionConfig(node,connectionKeys))return;if((0,connection_config_1.passedToForeign)(node,originOf,env))return;scanTlsKeys(node)},Literal(node){if(!ownsFile)return;if(typeof node.value!=="string")return;const finding=urlTlsFinding(node.value,urlSchemes);if(finding===null)return;if(!inConnectionPosition(node,connectionKeys,isDriverCallee))return;const owner=node.parent.parent;if(owner.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&(0,connection_config_1.passedToForeign)(owner,originOf,env)){return}report(node,finding)},"CallExpression, NewExpression"(node){if(!ownsFile||!isDriverCallee(node.callee))return;for(const argument of node.arguments){if(argument.type===ast_node_types_1.AST_NODE_TYPES.Literal)continue;for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(argument,env))){const literal=value.node;if(literal.type!==ast_node_types_1.AST_NODE_TYPES.Literal||typeof literal.value!=="string"){continue}const finding=urlTlsFinding(literal.value,urlSchemes);if(finding!==null){report(argument,finding);break}}}}}}})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.looksLikeSqlStatement=looksLikeSqlStatement;exports.createSqlInjectionRule=createSqlInjectionRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const type_syntax_1=require("../ast/type-syntax");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const request_source_1=require("./request-source");const sql_safety_1=require("./sql-safety");const sql_position_1=require("./sql-position");const value_follow_1=require("./value-follow");const SQL_STATEMENTS=[/^[\s(]*select\b[\s\S]*\bfrom\b/i,/^[\s(]*select\s/i,/^\s*insert\s+(?:or\s+\w+\s+|ignore\s+)?into\b/i,/^\s*update\b[\s\S]*\bset\b/i,/^\s*delete\s+from\b/i,/^\s*(?:replace|merge)\s+into\b/i,/^\s*with\b[\s\S]*\bas\s*\(/i,/^\s*(?:create|drop|alter|truncate)\s+(?:unique\s+|temp(?:orary)?\s+|or\s+replace\s+)*(?:table|index|view|schema|database|sequence|trigger|function|procedure|user|role)\b/i,/^\s*(?:pragma|attach|detach|vacuum|analyze|reindex|show|describe|explain)\b/i,/^\s*call\s+[\w".`]+\s*\(/i];const PARTITION_SHARED_SINKS=new Set(["query","execute"]);function looksLikeSqlStatement(text){return SQL_STATEMENTS.some(pattern=>pattern.test(text))}function enclosingFunction(node){for(let n=node.parent;n;n=n.parent){if((0,driver_origin_1.isFunctionNode)(n))return n}return void 0}function callableName(fn){if(fn.type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration&&fn.id)return fn.id.name;const parent=fn.parent;if(parent.type===ast_node_types_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return parent.id.name}if((parent.type===ast_node_types_1.AST_NODE_TYPES.MethodDefinition||parent.type===ast_node_types_1.AST_NODE_TYPES.PropertyDefinition||parent.type===ast_node_types_1.AST_NODE_TYPES.Property)&&parent.key.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return parent.key.name}return void 0}function createSqlInjectionRule(config){const statementSinks=new Set(config.methods);const fragmentSinks=new Map;for(const sink of config.fragmentMethods??[]){const spec=typeof sink==="string"?{name:sink}:sink;fragmentSinks.set(spec.name,{name:spec.name,arg:spec.arg??0,requireDriverReceiver:spec.requireDriverReceiver??false})}const fragmentFunctions=new Set(config.fragmentFunctions??[]);const aliasCallbacks=new Set(config.aliasCallbacks??[]);const sqlTextProperties=new Set(config.sqlTextProperties??[]);const statementFactories=new Set(config.statementFactories??[]);const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);const safety=(0,sql_safety_1.createSqlSafety)({origin:originOf,escapers:new Set(config.escapers??[]),fragmentFactories:new Set(config.fragmentFactories??[]),modules:config.modules,escaperModules:config.escaperModules});return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{noUnsafeQuery:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query detected. Variable interpolation found.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"high",fix:config.fix,documentationLink:config.documentationLink}),unsafeTemplateLiteral:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query construction detected (template literal).",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"high",fix:config.fix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let wrappers;let definitions;let wrapperFns;let pending;let ownsFile;const judge=(node,gate,depth=0)=>{const arg=(0,type_syntax_1.unwrapTypeSyntax)(node);if(arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral||arg.type===ast_node_types_1.AST_NODE_TYPES.BinaryExpression&&arg.operator==="+"){if(arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&arg.expressions.length===0){return false}const kind=arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral?"template":"concat";const text=(0,sql_safety_1.sqlStaticText)(arg);if(kind==="concat"&&text.trim()==="")return false;if(gate&&!looksLikeSqlStatement(text))return false;return(0,sql_position_1.sqlHoles)(arg).some(isUnsafeHole)?kind:false}if(depth>2)return false;if(arg.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return judgeBinding(arg,gate,depth)}if(arg.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){const target=(0,value_follow_1.follow)((0,value_follow_1.valueAt)(arg.callee,env));if(target.env!==env||!(0,driver_origin_1.isFunctionNode)(target.node))return false;for(const result of(0,value_follow_1.returnedValues)(target.node)??[]){const kind=judge(result,gate,depth+1);if(kind)return kind}}return false};const isUnsafeHole=({expression,preceding})=>!safety.isSafe((0,value_follow_1.valueAt)(expression,env),(0,sql_position_1.isQuoted)(preceding))&&((0,sql_position_1.isValuePosition)(preceding,config.doubleQuotedStrings)||(0,sql_position_1.isRequestDerived)(expression,env));const judgeBinding=(node,gate,depth)=>{const variable=(0,value_follow_1.lookup)(node.name,env.scopeOf(node));if(variable===null||!variable.defs.some(def=>def.type==="Variable")||variable.defs.some(def=>def.type==="Parameter")){return false}const writes=variable.references.filter(r=>r.isWrite()&&r.writeExpr).map(r=>r.writeExpr);const text=writes.map(sql_safety_1.sqlStaticText).join(" ");if(gate&&!looksLikeSqlStatement(text))return false;for(const write of writes){const kind=judge(write,false,depth+1);if(kind)return kind}return false};const isRequestText=node=>{let cursor=(0,type_syntax_1.unwrapTypeSyntax)(node);while(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&cursor.callee.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&cursor.callee.name==="String"&&cursor.arguments.length===1){cursor=(0,type_syntax_1.unwrapTypeSyntax)(cursor.arguments[0])}for(let link=cursor;;link=link.object){if((0,request_source_1.isRequestPayload)(link,env))return true;if(link.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return false}};const report=(node,kind)=>{context.report({node,messageId:kind==="template"?"unsafeTemplateLiteral":"noUnsafeQuery"})};const isStatementObject=receiver=>{const value=(0,type_syntax_1.unwrapTypeSyntax)((0,value_follow_1.follow)((0,value_follow_1.valueAt)(receiver,env)).node);return value.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&value.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&statementFactories.has((0,spellings_1.propertyName)(value.callee)??"")};const check=(arg,gate)=>{let text=(0,type_syntax_1.unwrapTypeSyntax)(arg);if(text.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&sqlTextProperties.size>0){const property=text.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&sqlTextProperties.has((0,spellings_1.objectKeyName)(p)??""));if(property===void 0)return;text=property.value}const kind=judge(text,gate);if(kind){report(text,kind);return}if(isRequestText(text))report(text,"concat")};const importedName=callee=>{const variable=(0,value_follow_1.lookup)(callee.name,env.scopeOf(callee));const specifier=variable===null?null:(0,value_follow_1.importSpecifierOf)(variable);return specifier!==null&&config.modules.some(m=>specifier.source===m||specifier.source.startsWith(`${m}/`))?specifier.name:null};const checkAliasCallback=node=>{const callback=node.arguments[0];if(!callback||!(0,driver_origin_1.isFunctionNode)(callback))return;const alias=callback.params[0];for(const result of(0,value_follow_1.returnedValues)(callback)??[]){const text=(0,type_syntax_1.unwrapTypeSyntax)(result);if(text.type!==ast_node_types_1.AST_NODE_TYPES.TemplateLiteral)continue;const unsafe=(0,sql_position_1.sqlHoles)(text).some(hole=>!(hole.expression.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&alias?.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&hole.expression.name===alias.name)&&isUnsafeHole(hole));if(unsafe)report(text,"template")}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);wrappers=new Map;definitions=new Map;wrapperFns=new Map;pending=[];ownsFile=false;return true},Program(program){ownsFile=usesModule(program)},"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression"(node){const name=callableName(node);if(name!==void 0)definitions.set(name,(definitions.get(name)??0)+1)},CallExpression(node){const callee=node.callee;const isMember=callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;const calleeName=isMember?(0,spellings_1.propertyName)(callee)??void 0:callee.type===ast_node_types_1.AST_NODE_TYPES.Identifier?callee.name:void 0;if(calleeName===void 0)return;if(!isMember&&ownsFile){const imported=importedName(callee);if(imported!==null&&fragmentFunctions.has(imported)){if(node.arguments[0])check(node.arguments[0],false);return}if(imported!==null&&aliasCallbacks.has(imported)){checkAliasCallback(node);return}}const fragment=isMember?fragmentSinks.get(calleeName):void 0;if(!isMember||!statementSinks.has(calleeName)&&!fragment){for(const[index,arg]of node.arguments.entries()){if(arg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;pending.push({name:calleeName,index,arg})}return}const receiver=originOf((0,value_follow_1.valueAt)(callee.object,env));if(receiver==="foreign")return;if(fragment?.requireDriverReceiver&&receiver!=="ours")return;if(!ownsFile&&!(receiver==="ours"&&!PARTITION_SHARED_SINKS.has(calleeName))){return}const queryArg=node.arguments[fragment?.arg??0];if(!queryArg||queryArg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)return;if(isStatementObject(callee.object))return;if(queryArg.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const fn=enclosingFunction(node);const index=fn?.params.findIndex(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.name===queryArg.name)??-1;const name=fn&&index>=0?callableName(fn):void 0;if(name!==void 0&&fn){wrappers.set(name,index);wrapperFns.set(fn,name)}}const gate=fragment===void 0&&config.requireSqlKeywords&&receiver!=="ours";check(queryArg,gate)},"Program:exit"(){if(!ownsFile)return;const proven=new Map;for(const name of wrapperFns.values())proven.set(name,(proven.get(name)??0)+1);for(const{name,index,arg}of pending){if(wrappers.get(name)!==index)continue;if(definitions.get(name)!==proven.get(name))continue;const kind=judge(arg,true);if(kind)report((0,type_syntax_1.unwrapTypeSyntax)(arg),kind)}}}}})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.looksLikeSqlStatement=looksLikeSqlStatement;exports.createSqlInjectionRule=createSqlInjectionRule;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const type_syntax_1=require("../ast/type-syntax");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const request_source_1=require("./request-source");const sql_safety_1=require("./sql-safety");const sql_position_1=require("./sql-position");const value_follow_1=require("./value-follow");const SQL_STATEMENTS=[/^[\s(]*select\b[\s\S]*\bfrom\b/i,/^[\s(]*select\s/i,/^\s*insert\s+(?:or\s+\w+\s+|ignore\s+)?into\b/i,/^\s*update\b[\s\S]*\bset\b/i,/^\s*delete\s+from\b/i,/^\s*(?:replace|merge)\s+into\b/i,/^\s*with\b[\s\S]*\bas\s*\(/i,/^\s*(?:create|drop|alter|truncate)\s+(?:unique\s+|temp(?:orary)?\s+|or\s+replace\s+)*(?:table|index|view|schema|database|sequence|trigger|function|procedure|user|role)\b/i,/^\s*(?:pragma|attach|detach|vacuum|analyze|reindex|show|describe|explain)\b/i,/^\s*call\s+[\w".`]+\s*\(/i];const PARTITION_SHARED_SINKS=new Set(["query","execute"]);function looksLikeSqlStatement(text){return SQL_STATEMENTS.some(pattern=>pattern.test(text))}function enclosingFunction(node){for(let n=node.parent;n;n=n.parent){if((0,driver_origin_1.isFunctionNode)(n))return n}return void 0}function callableName(fn){if(fn.type===ast_node_types_1.AST_NODE_TYPES.FunctionDeclaration&&fn.id)return fn.id.name;const parent=fn.parent;if(parent.type===ast_node_types_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return parent.id.name}if((parent.type===ast_node_types_1.AST_NODE_TYPES.MethodDefinition||parent.type===ast_node_types_1.AST_NODE_TYPES.PropertyDefinition||parent.type===ast_node_types_1.AST_NODE_TYPES.Property)&&parent.key.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return parent.key.name}return void 0}function createSqlInjectionRule(config){const statementSinks=new Set(config.methods);const fragmentSinks=new Map;for(const sink of config.fragmentMethods??[]){const spec=typeof sink==="string"?{name:sink}:sink;fragmentSinks.set(spec.name,{name:spec.name,arg:spec.arg??0,requireDriverReceiver:spec.requireDriverReceiver??false})}const fragmentFunctions=new Set(config.fragmentFunctions??[]);const aliasCallbacks=new Set(config.aliasCallbacks??[]);const sqlTextProperties=new Set(config.sqlTextProperties??[]);const statementFactories=new Set(config.statementFactories??[]);const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);const safety=(0,sql_safety_1.createSqlSafety)({origin:originOf,escapers:new Set(config.escapers??[]),fragmentFactories:new Set(config.fragmentFactories??[]),modules:config.modules,escaperModules:config.escaperModules});return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{noUnsafeQuery:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query detected. Variable interpolation found.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"high",fix:config.fix,documentationLink:config.documentationLink}),unsafeTemplateLiteral:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"SQL Injection Risk",description:"Unsafe SQL query construction detected (template literal).",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A03:2021",compliance:["SOC2","PCI-DSS","NIST-CSF"],effort:"high",fix:config.fix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let wrappers;let definitions;let wrapperFns;let pending;let ownsFile;const judge=(node,gate,depth=0)=>{const arg=(0,type_syntax_1.unwrapTypeSyntax)(node);if(arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral||arg.type===ast_node_types_1.AST_NODE_TYPES.BinaryExpression&&arg.operator==="+"){if(arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&arg.expressions.length===0){return false}const kind=arg.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral?"template":"concat";const text=(0,sql_safety_1.sqlStaticText)(arg);if(kind==="concat"&&text.trim()==="")return false;if(gate&&!looksLikeSqlStatement(text))return false;return(0,sql_position_1.sqlHoles)(arg).some(isUnsafeHole)?kind:false}if(depth>2)return false;if(arg.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return judgeBinding(arg,gate,depth)}if(arg.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){const target=(0,value_follow_1.follow)((0,value_follow_1.valueAt)(arg.callee,env));if(target.env!==env||!(0,driver_origin_1.isFunctionNode)(target.node))return false;for(const result of(0,value_follow_1.returnedValues)(target.node)??[]){const kind=judge(result,gate,depth+1);if(kind)return kind}}return false};const isUnsafeHole=({expression,preceding})=>!safety.isSafe((0,value_follow_1.valueAt)(expression,env),(0,sql_position_1.isQuoted)(preceding))&&((0,sql_position_1.isValuePosition)(preceding,config.doubleQuotedStrings)||(0,sql_position_1.isRequestDerived)(expression,env));const judgeBinding=(node,gate,depth)=>{const variable=(0,value_follow_1.lookup)(node.name,env.scopeOf(node));if(variable===null||!variable.defs.some(def=>def.type==="Variable")||variable.defs.some(def=>def.type==="Parameter")){return false}const writes=variable.references.filter(r=>r.isWrite()&&r.writeExpr).map(r=>r.writeExpr);const text=writes.map(sql_safety_1.sqlStaticText).join(" ");if(gate&&!looksLikeSqlStatement(text))return false;for(const write of writes){const kind=judge(write,false,depth+1);if(kind)return kind}return false};const isRequestText=node=>{let cursor=(0,type_syntax_1.unwrapTypeSyntax)(node);while(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&cursor.callee.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&cursor.callee.name==="String"&&cursor.arguments.length===1){cursor=(0,type_syntax_1.unwrapTypeSyntax)(cursor.arguments[0])}for(let link=cursor;;link=link.object){if((0,request_source_1.isRequestPayload)(link,env))return true;if(link.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return false}};const report=(node,kind)=>{context.report({node,messageId:kind==="template"?"unsafeTemplateLiteral":"noUnsafeQuery"})};const isStatementObject=receiver=>{const value=(0,type_syntax_1.unwrapTypeSyntax)((0,value_follow_1.follow)((0,value_follow_1.valueAt)(receiver,env)).node);return value.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&value.callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&statementFactories.has((0,spellings_1.propertyName)(value.callee)??"")};const check=(arg,gate)=>{let text=(0,type_syntax_1.unwrapTypeSyntax)(arg);if(text.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&sqlTextProperties.size>0){const property=text.properties.find(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Property&&sqlTextProperties.has((0,spellings_1.objectKeyName)(p)??""));if(property===void 0)return;text=property.value}const kind=judge(text,gate);if(kind){report(text,kind);return}if(isRequestText(text))report(text,"concat")};const importedName=callee=>{const variable=(0,value_follow_1.lookup)(callee.name,env.scopeOf(callee));const specifier=variable===null?null:(0,value_follow_1.importSpecifierOf)(variable);return specifier!==null&&config.modules.some(m=>specifier.source===m||specifier.source.startsWith(`${m}/`))?specifier.name:null};const checkAliasCallback=node=>{const callback=node.arguments[0];if(!callback||!(0,driver_origin_1.isFunctionNode)(callback))return;const alias=callback.params[0];for(const result of(0,value_follow_1.returnedValues)(callback)??[]){const text=(0,type_syntax_1.unwrapTypeSyntax)(result);if(text.type!==ast_node_types_1.AST_NODE_TYPES.TemplateLiteral){if(isRequestText(text))report(text,"concat");continue}const unsafe=(0,sql_position_1.sqlHoles)(text).some(hole=>!(hole.expression.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&alias?.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&hole.expression.name===alias.name)&&isUnsafeHole(hole));if(unsafe)report(text,"template")}};return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);wrappers=new Map;definitions=new Map;wrapperFns=new Map;pending=[];ownsFile=false;return true},Program(program){ownsFile=usesModule(program)},"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression"(node){const name=callableName(node);if(name!==void 0)definitions.set(name,(definitions.get(name)??0)+1)},CallExpression(node){const callee=node.callee;const isMember=callee.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;const calleeName=isMember?(0,spellings_1.propertyName)(callee)??void 0:callee.type===ast_node_types_1.AST_NODE_TYPES.Identifier?callee.name:void 0;if(calleeName===void 0)return;if(!isMember&&ownsFile){const imported=importedName(callee);if(imported!==null&&fragmentFunctions.has(imported)){if(node.arguments[0])check(node.arguments[0],false);return}if(imported!==null&&aliasCallbacks.has(imported)){checkAliasCallback(node);return}}const fragment=isMember?fragmentSinks.get(calleeName):void 0;if(!isMember||!statementSinks.has(calleeName)&&!fragment){for(const[index,arg]of node.arguments.entries()){if(arg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)continue;pending.push({name:calleeName,index,arg})}return}const receiver=originOf((0,value_follow_1.valueAt)(callee.object,env));if(receiver==="foreign")return;if(fragment?.requireDriverReceiver&&receiver!=="ours")return;if(!ownsFile&&!(receiver==="ours"&&!PARTITION_SHARED_SINKS.has(calleeName))){return}const queryArg=node.arguments[fragment?.arg??0];if(!queryArg||queryArg.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)return;if(isStatementObject(callee.object))return;if(queryArg.type===ast_node_types_1.AST_NODE_TYPES.Identifier){const fn=enclosingFunction(node);const index=fn?.params.findIndex(p=>p.type===ast_node_types_1.AST_NODE_TYPES.Identifier&&p.name===queryArg.name)??-1;const name=fn&&index>=0?callableName(fn):void 0;if(name!==void 0&&fn){wrappers.set(name,index);wrapperFns.set(fn,name)}}const gate=fragment===void 0&&config.requireSqlKeywords&&receiver!=="ours";check(queryArg,gate)},"Program:exit"(){if(!ownsFile)return;const proven=new Map;for(const name of wrapperFns.values())proven.set(name,(proven.get(name)??0)+1);for(const{name,index,arg}of pending){if(wrappers.get(name)!==index)continue;if(definitions.get(name)!==proven.get(name))continue;const kind=judge(arg,true);if(kind)report((0,type_syntax_1.unwrapTypeSyntax)(arg),kind)}}}}})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.propertyKeyName=propertyKeyName;exports.hasTruthyKey=hasTruthyKey;exports.hasArgumentScope=hasArgumentScope;exports.chainMethodNames=chainMethodNames;exports.driverBindings=driverBindings;exports.receiverBaseName=receiverBaseName;exports.createUnscopedMutationRule=createUnscopedMutationRule;exports.startsWithTable=startsWithTable;exports.insideAny=insideAny;exports.exportedFunctions=exportedFunctions;exports.scopedElsewhere=scopedElsewhere;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const value_follow_1=require("./value-follow");const DEFAULT_SCOPE_KEYS=["where"];const DEFAULT_SCOPE_METHODS=["where"];function propertyKeyName(prop){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)return void 0;if(prop.computed)return void 0;if(prop.key.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return prop.key.name;if(prop.key.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof prop.key.value==="string"){return prop.key.value}return void 0}function hasTruthyKey(obj,keys){return obj.properties.some(prop=>{if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)return false;const name=propertyKeyName(prop);if(name===void 0||!keys.includes(name))return false;return!(prop.value.type===ast_node_types_1.AST_NODE_TYPES.Literal&&!prop.value.value)})}function hasArgumentScope(args,scopeKeys){return args.some(arg=>{if(arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){return arg.properties.some(prop=>{if(prop.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)return true;const name=propertyKeyName(prop);if(name===void 0)return true;if(!scopeKeys.includes(name))return false;if(prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&prop.value.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&prop.value.properties.length===0){return false}return true})}return arg.type!==ast_node_types_1.AST_NODE_TYPES.Literal})}function chainMethodNames(node){let root=node;for(;;){const parent=root.parent;if(!parent)break;if(parent.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&parent.object===root){root=parent;continue}if(parent.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&parent.callee===root){root=parent;continue}break}const names=new Set;let cursor=root;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){cursor=cursor.callee;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){if(!cursor.computed&&cursor.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier){names.add(cursor.property.name)}cursor=cursor.object;continue}break}return names}function driverBindings(program,modules){const names=new Set;const isDriver=source=>modules.some(m=>source===m||source.startsWith(`${m}/`));for(const stmt of program.body){if(stmt.type===ast_node_types_1.AST_NODE_TYPES.ImportDeclaration){if(typeof stmt.source.value!=="string"||!isDriver(stmt.source.value))continue;for(const spec of stmt.specifiers)names.add(spec.local.name);continue}if(stmt.type!==ast_node_types_1.AST_NODE_TYPES.VariableDeclaration)continue;for(const decl of stmt.declarations){const init=decl.init;if(!init||init.type!==ast_node_types_1.AST_NODE_TYPES.CallExpression||init.callee.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||init.callee.name!=="require"){continue}const arg=init.arguments[0];if(!arg||arg.type!==ast_node_types_1.AST_NODE_TYPES.Literal||typeof arg.value!=="string"||!isDriver(arg.value)){continue}if(decl.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier)names.add(decl.id.name);if(decl.id.type===ast_node_types_1.AST_NODE_TYPES.ObjectPattern){for(const prop of decl.id.properties){if(prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&prop.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier){names.add(prop.value.name)}}}}}return names}function receiverBaseName(node){let cursor=node.object;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){if(cursor.object.type===ast_node_types_1.AST_NODE_TYPES.ThisExpression&&!cursor.computed&&cursor.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return cursor.property.name}cursor=cursor.object;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){cursor=cursor.callee;continue}return cursor.type===ast_node_types_1.AST_NODE_TYPES.Identifier?cursor.name:void 0}}function createUnscopedMutationRule(config){const sinks=new Set(config.methods);const scopeKeys=config.scopeKeys??DEFAULT_SCOPE_KEYS;const scopeMethods=config.scopeMethods??DEFAULT_SCOPE_METHODS;const truncateKeys=config.truncateKeys??[];const argumentRole=config.argumentRole??"options";const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{unscopedMutation:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unscoped Bulk Mutation",description:"Bulk mutation with no filter detected. This rewrites or deletes every row in the table.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A01:2021",compliance:["SOC2","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),explicitTruncate:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unscoped Bulk Mutation",description:"Table truncation detected. This ignores any filter and empties the whole table.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A01:2021",compliance:["SOC2","NIST-CSF"],effort:"low",fix:"Remove the truncate flag and delete by filter, or move the truncation to an explicit maintenance script.",documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;let migrations;function hasDistinctiveShape(node){const callee=node.callee;switch(config.distinctiveShape){case"model-accessor":return callee.object.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;case"table-call":return startsWithTable(callee.object);case"table-argument":{const[table]=node.arguments;return table!==void 0&&table.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement&&originOf((0,value_follow_1.valueAt)(table,env))==="ours"}default:return false}}return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;migrations=new Set;return true},Program(program){ownsFile=usesModule(program);migrations=exportedFunctions(program,config.migrationExports??[],context)},CallExpression(node){if(node.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||node.callee.computed||node.callee.property.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||!sinks.has(node.callee.property.name)){return}const origin=originOf((0,value_follow_1.valueAt)(node.callee.object,env));if(origin==="foreign")return;if(origin==="unknown"&&!(ownsFile&&hasDistinctiveShape(node))){return}if(insideAny(node,migrations))return;if(truncateKeys.length>0){const truncating=node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&hasTruthyKey(arg,truncateKeys));if(truncating){context.report({node,messageId:"explicitTruncate"});return}}if(argumentRole==="options"){if(config.requireOptionsObject===true&&!node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression)){return}if(hasArgumentScope(node.arguments,scopeKeys))return}const chained=chainMethodNames(node);if(scopeMethods.some(name=>chained.has(name)))return;if(scopedElsewhere(node,scopeMethods,env))return;context.report({node,messageId:"unscopedMutation"})}}}})}const TABLE_STARTERS=new Set(["table","from","into","queryBuilder","withSchema"]);function startsWithTable(receiver){let cursor=receiver;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){if(cursor.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return true;if(TABLE_STARTERS.has((0,spellings_1.propertyName)(cursor.callee)??""))return true;cursor=cursor.callee.object;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){cursor=cursor.object;continue}return false}}function insideAny(node,functions){for(let n=node.parent;n;n=n.parent){if(functions.has(n))return true}return false}function exportedFunctions(program,names,context){const found=new Set;const scopeManager=context.sourceCode.scopeManager;if(names.length===0||scopeManager===null)return found;const module={file:context.physicalFilename,ast:program,scopeManager};for(const name of names){const exported=(0,value_follow_1.exportedValue)(module,name,context.languageOptions?.parser);if(exported===null)continue;const target=(0,value_follow_1.follow)(exported);if((0,driver_origin_1.isFunctionNode)(target.node))found.add(target.node)}return found}function scopedElsewhere(node,scopeMethods,env){let root=node.callee;while(root.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression||root.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){root=root.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression?root.object:root.callee}if(root.type!==ast_node_types_1.AST_NODE_TYPES.Identifier)return false;const variable=(0,value_follow_1.lookup)(root.name,env.scopeOf(root));if(variable===null||variable.defs[0]?.type!=="Variable")return false;return variable.references.some(reference=>{const use=reference.identifier.parent;if(use?.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&use.object===reference.identifier){return scopeMethods.includes((0,spellings_1.propertyName)(use)??"")}return(use?.type===ast_node_types_1.AST_NODE_TYPES.CallExpression||use?.type===ast_node_types_1.AST_NODE_TYPES.NewExpression)&&use.arguments.some(argument=>argument===reference.identifier)})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.propertyKeyName=propertyKeyName;exports.hasTruthyKey=hasTruthyKey;exports.hasArgumentScope=hasArgumentScope;exports.chainMethodNames=chainMethodNames;exports.driverBindings=driverBindings;exports.receiverBaseName=receiverBaseName;exports.createUnscopedMutationRule=createUnscopedMutationRule;exports.startsWithTable=startsWithTable;exports.insideAny=insideAny;exports.exportedFunctions=exportedFunctions;exports.scopedElsewhere=scopedElsewhere;const rule_creator_1=require("./rule-creator");const ast_node_types_1=require("../ast-node-types");const spellings_1=require("../ast/spellings");const messaging_1=require("../messaging");const module_evidence_1=require("./module-evidence");const rule_creator_2=require("./rule-creator");const driver_origin_1=require("./driver-origin");const value_follow_1=require("./value-follow");const DEFAULT_SCOPE_KEYS=["where"];const DEFAULT_SCOPE_METHODS=["where"];function propertyKeyName(prop){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)return void 0;if(prop.computed)return void 0;if(prop.key.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return prop.key.name;if(prop.key.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof prop.key.value==="string"){return prop.key.value}return void 0}function hasTruthyKey(obj,keys){return obj.properties.some(prop=>{if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)return false;const name=propertyKeyName(prop);if(name===void 0||!keys.includes(name))return false;return!(prop.value.type===ast_node_types_1.AST_NODE_TYPES.Literal&&!prop.value.value)})}function hasArgumentScope(args,scopeKeys){return args.some(arg=>{if(arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){return arg.properties.some(prop=>{if(prop.type===ast_node_types_1.AST_NODE_TYPES.SpreadElement)return true;const name=propertyKeyName(prop);if(name===void 0)return true;if(!scopeKeys.includes(name))return false;if(prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&prop.value.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&prop.value.properties.length===0){return false}return true})}return arg.type!==ast_node_types_1.AST_NODE_TYPES.Literal})}function chainMethodNames(node){let root=node;for(;;){const parent=root.parent;if(!parent)break;if(parent.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&parent.object===root){root=parent;continue}if(parent.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&parent.callee===root){root=parent;continue}break}const names=new Set;let cursor=root;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){cursor=cursor.callee;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){const name=(0,spellings_1.propertyName)(cursor);if(name!==null)names.add(name);cursor=cursor.object;continue}break}return names}function driverBindings(program,modules){const names=new Set;const isDriver=source=>modules.some(m=>source===m||source.startsWith(`${m}/`));for(const stmt of program.body){if(stmt.type===ast_node_types_1.AST_NODE_TYPES.ImportDeclaration){if(typeof stmt.source.value!=="string"||!isDriver(stmt.source.value))continue;for(const spec of stmt.specifiers)names.add(spec.local.name);continue}if(stmt.type!==ast_node_types_1.AST_NODE_TYPES.VariableDeclaration)continue;for(const decl of stmt.declarations){const init=decl.init;if(!init||init.type!==ast_node_types_1.AST_NODE_TYPES.CallExpression||init.callee.type!==ast_node_types_1.AST_NODE_TYPES.Identifier||init.callee.name!=="require"){continue}const arg=init.arguments[0];if(!arg||arg.type!==ast_node_types_1.AST_NODE_TYPES.Literal||typeof arg.value!=="string"||!isDriver(arg.value)){continue}if(decl.id.type===ast_node_types_1.AST_NODE_TYPES.Identifier)names.add(decl.id.name);if(decl.id.type===ast_node_types_1.AST_NODE_TYPES.ObjectPattern){for(const prop of decl.id.properties){if(prop.type===ast_node_types_1.AST_NODE_TYPES.Property&&prop.value.type===ast_node_types_1.AST_NODE_TYPES.Identifier){names.add(prop.value.name)}}}}}return names}function receiverBaseName(node){let cursor=node.object;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){if(cursor.object.type===ast_node_types_1.AST_NODE_TYPES.ThisExpression&&!cursor.computed&&cursor.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier){return cursor.property.name}cursor=cursor.object;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){cursor=cursor.callee;continue}return cursor.type===ast_node_types_1.AST_NODE_TYPES.Identifier?cursor.name:void 0}}function createUnscopedMutationRule(config){const sinks=new Set(config.methods);const scopeKeys=config.scopeKeys??DEFAULT_SCOPE_KEYS;const scopeMethods=config.scopeMethods??DEFAULT_SCOPE_METHODS;const truncateKeys=config.truncateKeys??[];const argumentRole=config.argumentRole??"options";const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return rule_creator_1.RuleCreator.withoutDocs({meta:{interop:{runtimes:["eslint","oxlint"]},type:config.meta.type,docs:{...config.meta.docs},messages:{unscopedMutation:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unscoped Bulk Mutation",description:"Bulk mutation with no filter detected. This rewrites or deletes every row in the table.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A01:2021",compliance:["SOC2","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),explicitTruncate:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Unscoped Bulk Mutation",description:"Table truncation detected. This ignores any filter and empties the whole table.",severity:"HIGH",cwe:config.meta.docs.cwe,owasp:"A01:2021",compliance:["SOC2","NIST-CSF"],effort:"low",fix:"Remove the truncate flag and delete by filter, or move the truncation to an explicit maintenance script.",documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],createOnce(context){let env;let ownsFile;let migrations;function hasDistinctiveShape(node){const callee=node.callee;switch(config.distinctiveShape){case"model-accessor":return callee.object.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression;case"table-call":return startsWithTable(callee.object);case"table-argument":{const[table]=node.arguments;return table!==void 0&&table.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement&&originOf((0,value_follow_1.valueAt)(table,env))==="ours"}default:return false}}return{before(){if((0,rule_creator_2.isTestFilePath)(context.filename))return false;env=(0,value_follow_1.envOf)(context);ownsFile=false;migrations=new Set;return true},Program(program){ownsFile=usesModule(program);migrations=exportedFunctions(program,config.migrationExports??[],context)},CallExpression(node){if(node.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression||!sinks.has((0,spellings_1.propertyName)(node.callee)??"")){return}const origin=originOf((0,value_follow_1.valueAt)(node.callee.object,env));if(origin==="foreign")return;if(origin==="unknown"&&!(ownsFile&&hasDistinctiveShape(node))){return}if(insideAny(node,migrations))return;if(truncateKeys.length>0){const truncating=node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&hasTruthyKey(arg,truncateKeys));if(truncating){context.report({node,messageId:"explicitTruncate"});return}}if(argumentRole==="options"){if(config.requireOptionsObject===true&&!node.arguments.some(arg=>arg.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression)){return}if(hasArgumentScope(node.arguments,scopeKeys))return}const chained=chainMethodNames(node);if(scopeMethods.some(name=>chained.has(name)))return;if(scopedElsewhere(node,scopeMethods,env))return;context.report({node,messageId:"unscopedMutation"})}}}})}const TABLE_STARTERS=new Set(["table","from","into","queryBuilder","withSchema"]);function startsWithTable(receiver){let cursor=receiver;for(;;){if(cursor.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){if(cursor.callee.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return true;if(TABLE_STARTERS.has((0,spellings_1.propertyName)(cursor.callee)??""))return true;cursor=cursor.callee.object;continue}if(cursor.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){cursor=cursor.object;continue}return false}}function insideAny(node,functions){for(let n=node.parent;n;n=n.parent){if(functions.has(n))return true}return false}function exportedFunctions(program,names,context){const found=new Set;const scopeManager=context.sourceCode.scopeManager;if(names.length===0||scopeManager===null)return found;const module={file:context.physicalFilename,ast:program,scopeManager};for(const name of names){const exported=(0,value_follow_1.exportedValue)(module,name,context.languageOptions?.parser);if(exported===null)continue;const target=(0,value_follow_1.follow)(exported);if((0,driver_origin_1.isFunctionNode)(target.node))found.add(target.node)}return found}function heldThenScoped(node,scopeMethods,env){let top=node;while(top.parent?.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&top.parent.object===top||top.parent?.type===ast_node_types_1.AST_NODE_TYPES.CallExpression&&top.parent.callee===top){top=top.parent}const declarator=top.parent;if(declarator?.type!==ast_node_types_1.AST_NODE_TYPES.VariableDeclarator||declarator.id.type!==ast_node_types_1.AST_NODE_TYPES.Identifier){return false}const variable=(0,value_follow_1.lookup)(declarator.id.name,env.scopeOf(declarator.id));return variable.references.some(reference=>{const use=reference.identifier.parent;if(use.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression)return scopeMethods.includes((0,spellings_1.propertyName)(use));return(use.type===ast_node_types_1.AST_NODE_TYPES.CallExpression||use.type===ast_node_types_1.AST_NODE_TYPES.NewExpression)&&use.arguments.some(argument=>argument===reference.identifier)})}function scopedElsewhere(node,scopeMethods,env){let root=node.callee;while(root.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression||root.type===ast_node_types_1.AST_NODE_TYPES.CallExpression){root=root.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression?root.object:root.callee}if(heldThenScoped(node,scopeMethods,env))return true;if(root.type!==ast_node_types_1.AST_NODE_TYPES.Identifier)return false;const variable=(0,value_follow_1.lookup)(root.name,env.scopeOf(root));if(variable===null||variable.defs[0]?.type!=="Variable")return false;return variable.references.some(reference=>{const use=reference.identifier.parent;if(use?.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression&&use.object===reference.identifier){return scopeMethods.includes((0,spellings_1.propertyName)(use)??"")}return(use?.type===ast_node_types_1.AST_NODE_TYPES.CallExpression||use?.type===ast_node_types_1.AST_NODE_TYPES.NewExpression)&&use.arguments.some(argument=>argument===reference.identifier)})}