eslint-plugin-lambda-security 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,7 +65,9 @@ npm install oxlint-plugin-lambda-security --save-dev
65
65
  // vite.config.ts
66
66
  import { defineConfig } from 'vite-plus';
67
67
 
68
- export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-lambda-security'] } });
68
+ export default defineConfig({
69
+ lint: { jsPlugins: ['oxlint-plugin-lambda-security'] },
70
+ });
69
71
  ```
70
72
 
71
73
  **ESLint:**
@@ -110,7 +112,7 @@ src/handlers/api.ts
110
112
  By providing this structured context (CWE, OWASP, Fix), we enable AI tools to **reason** about the security flaw rather than hallucinating. This allows Copilot/Cursor to suggest the _exact_ correct fix immediately.
111
113
 
112
114
  ## 💡 What You Get
113
- - **Serverless-focused coverage:** 5 rules targeting Lambda-specific vulnerabilities (credentials, CORS, secrets, logging).
115
+ - **Serverless-focused coverage:** 14 rules targeting Lambda-specific vulnerabilities (credentials, CORS, secrets, logging).
114
116
  - **LLM-optimized & MCP-ready:** Structured 2-line messages with CWE + OWASP + CVSS + concrete fixes so humans _and_ AI auto-fixers stay aligned.
115
117
  - **Standards aligned:** OWASP Serverless Top 10, CWE tagging, CVSS scoring in every finding for compliance mapping.
116
118
  - **Tiered presets:** `recommended`, `strict` for fast policy rollout.
@@ -211,7 +213,6 @@ Part of the **Interlace ESLint ecosystem** — AI-native rules with LLM-optimize
211
213
 
212
214
  | Plugin | Downloads | Description |
213
215
  | :--- | :---: | :--- |
214
- | [`eslint-plugin-cli-floor`](https://www.npmjs.com/package/eslint-plugin-cli-floor) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-cli-floor.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-cli-floor) | CLI floor for commander, yargs and burgee. |
215
216
  | [`eslint-plugin-conventions`](https://www.npmjs.com/package/eslint-plugin-conventions) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-conventions.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-conventions) | Team-specific habits and styles. |
216
217
  | [`eslint-plugin-import-next`](https://www.npmjs.com/package/eslint-plugin-import-next) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-import-next.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-import-next) | Fast cycle + import-graph analysis. |
217
218
  | [`eslint-plugin-maintainability`](https://www.npmjs.com/package/eslint-plugin-maintainability) | [![downloads](https://img.shields.io/npm/dt/eslint-plugin-maintainability.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-maintainability) | Cognitive load and clean-code patterns. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-lambda-security",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "ESLint plugin for AWS Lambda security — detects overly permissive IAM policies and CORS, unvalidated event bodies, secrets in env vars, and leaked error details.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -71,7 +71,7 @@
71
71
  "node": ">=18.0.0"
72
72
  },
73
73
  "dependencies": {
74
- "@interlace/eslint-devkit": "^1.21.0"
74
+ "@interlace/eslint-devkit": "^1.21.2"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "eslint": "^8.40.0 || ^9.0.0 || ^10.0.0",
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-hardcoded-credentials-sdk"(){return require("./rules/no-hardcoded-credentials-sdk").noHardcodedCredentialsSdk},get"no-permissive-cors-response"(){return require("./rules/no-permissive-cors-response").noPermissiveCorsResponse},get"no-permissive-cors-middy"(){return require("./rules/no-permissive-cors-middy").noPermissiveCorsMidly},get"no-secrets-in-env"(){return require("./rules/no-secrets-in-env").noSecretsInEnv},get"no-env-logging"(){return require("./rules/no-env-logging").noEnvLogging},get"no-unvalidated-event-body"(){return require("./rules/no-unvalidated-event-body").noUnvalidatedEventBody},get"no-missing-authorization-check"(){return require("./rules/no-missing-authorization-check").noMissingAuthorizationCheck},get"no-overly-permissive-iam-policy"(){return require("./rules/no-overly-permissive-iam-policy").noOverlyPermissiveIamPolicy},get"no-error-swallowing"(){return require("./rules/no-error-swallowing").noErrorSwallowing},get"require-timeout-handling"(){return require("./rules/require-timeout-handling").requireTimeoutHandling},get"no-unbounded-batch-processing"(){return require("./rules/no-unbounded-batch-processing").noUnboundedBatchProcessing},get"no-user-controlled-requests"(){return require("./rules/no-user-controlled-requests").noUserControlledRequests},get"no-exposed-error-details"(){return require("./rules/no-exposed-error-details").noExposedErrorDetails},get"no-exposed-debug-endpoints"(){return require("./rules/no-exposed-debug-endpoints").noExposedDebugEndpoints}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-lambda-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-lambda-security",version:"2.2.0"},rules:exports.rules};exports.configs={recommended:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-unvalidated-event-body":"warn","lambda-security/no-missing-authorization-check":"warn","lambda-security/no-exposed-error-details":"warn","lambda-security/no-exposed-debug-endpoints":"error","lambda-security/no-env-logging":"warn","lambda-security/no-error-swallowing":"warn","lambda-security/require-timeout-handling":"warn","lambda-security/no-unbounded-batch-processing":"warn"}},strict:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-env-logging":"error","lambda-security/no-unvalidated-event-body":"error","lambda-security/no-missing-authorization-check":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-error-swallowing":"error","lambda-security/require-timeout-handling":"error","lambda-security/no-unbounded-batch-processing":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-exposed-error-details":"error","lambda-security/no-exposed-debug-endpoints":"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-hardcoded-credentials-sdk"(){return require("./rules/no-hardcoded-credentials-sdk").noHardcodedCredentialsSdk},get"no-permissive-cors-response"(){return require("./rules/no-permissive-cors-response").noPermissiveCorsResponse},get"no-permissive-cors-middy"(){return require("./rules/no-permissive-cors-middy").noPermissiveCorsMidly},get"no-secrets-in-env"(){return require("./rules/no-secrets-in-env").noSecretsInEnv},get"no-env-logging"(){return require("./rules/no-env-logging").noEnvLogging},get"no-unvalidated-event-body"(){return require("./rules/no-unvalidated-event-body").noUnvalidatedEventBody},get"no-missing-authorization-check"(){return require("./rules/no-missing-authorization-check").noMissingAuthorizationCheck},get"no-overly-permissive-iam-policy"(){return require("./rules/no-overly-permissive-iam-policy").noOverlyPermissiveIamPolicy},get"no-error-swallowing"(){return require("./rules/no-error-swallowing").noErrorSwallowing},get"require-timeout-handling"(){return require("./rules/require-timeout-handling").requireTimeoutHandling},get"no-unbounded-batch-processing"(){return require("./rules/no-unbounded-batch-processing").noUnboundedBatchProcessing},get"no-user-controlled-requests"(){return require("./rules/no-user-controlled-requests").noUserControlledRequests},get"no-exposed-error-details"(){return require("./rules/no-exposed-error-details").noExposedErrorDetails},get"no-exposed-debug-endpoints"(){return require("./rules/no-exposed-debug-endpoints").noExposedDebugEndpoints}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-lambda-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-lambda-security",version:"2.2.2"},rules:exports.rules};exports.configs={recommended:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-unvalidated-event-body":"warn","lambda-security/no-missing-authorization-check":"warn","lambda-security/no-exposed-error-details":"warn","lambda-security/no-exposed-debug-endpoints":"error","lambda-security/no-env-logging":"warn","lambda-security/no-error-swallowing":"warn","lambda-security/require-timeout-handling":"warn","lambda-security/no-unbounded-batch-processing":"warn"}},strict:{plugins:{"lambda-security":exports.plugin},rules:{"lambda-security/no-hardcoded-credentials-sdk":"error","lambda-security/no-permissive-cors-response":"error","lambda-security/no-permissive-cors-middy":"error","lambda-security/no-secrets-in-env":"error","lambda-security/no-env-logging":"error","lambda-security/no-unvalidated-event-body":"error","lambda-security/no-missing-authorization-check":"error","lambda-security/no-overly-permissive-iam-policy":"error","lambda-security/no-error-swallowing":"error","lambda-security/require-timeout-handling":"error","lambda-security/no-unbounded-batch-processing":"error","lambda-security/no-user-controlled-requests":"error","lambda-security/no-exposed-error-details":"error","lambda-security/no-exposed-debug-endpoints":"error"}}};exports.default=exports.plugin;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noEnvLogging=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const LOGGING_FUNCTIONS=new Set(["log","info","warn","error","debug","trace"]);exports.noEnvLogging=(0,eslint_devkit_1.createRule)({name:"no-env-logging",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-env-logging.md",description:"Detects logging of process.env which may expose secrets",cwe:"CWE-532",cvss:5.3},messages:{envLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Environment Variable Logging",cwe:"CWE-532",description:"Logging process.env may expose secrets (API keys, passwords, tokens)",severity:"HIGH",fix:"Remove process.env from log statements or log specific non-sensitive values",documentationLink:"https://cwe.mitre.org/data/definitions/532.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let sourceCode;function isProcessEnv(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name==="process"&&(0,eslint_devkit_1.propertyName)(node)==="env"){return true}return false}function containsProcessEnv(node){const text=sourceCode.getText(node);return text.includes("process.env")}function isLoggingCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const obj=node.callee.object;const prop=node.callee.property;if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const methodName=prop.name;if(!LOGGING_FUNCTIONS.has(methodName))return false;if(obj.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&obj.name==="console"){return true}if(obj.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/log(ger)?/i.test(obj.name)){return true}}return false}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}sourceCode=context.sourceCode;return true},CallExpression(node){if(!isLoggingCall(node))return;for(const arg of node.arguments){if(isProcessEnv(arg)){context.report({node:arg,messageId:"envLogging"})}else if(containsProcessEnv(arg)){const text=sourceCode.getText(arg);if(/process\.env\s*[,)\]]/.test(text)||/JSON\.stringify\s*\(\s*process\.env\s*\)/.test(text)){context.report({node:arg,messageId:"envLogging"})}}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noEnvLogging=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const SERIALIZERS=new Set(["JSON.stringify","Object.entries","Object.fromEntries","Object.values","Object.assign"]);const LOGGING_FUNCTIONS=new Set(["log","info","warn","error","debug","trace"]);exports.noEnvLogging=(0,eslint_devkit_1.createRule)({name:"no-env-logging",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-env-logging.md",description:"Detects logging of process.env which may expose secrets",cwe:"CWE-532",cvss:5.3},messages:{envLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Environment Variable Logging",cwe:"CWE-532",description:"Logging process.env may expose secrets (API keys, passwords, tokens)",severity:"HIGH",fix:"Remove process.env from log statements or log specific non-sensitive values",documentationLink:"https://cwe.mitre.org/data/definitions/532.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isProcessEnv(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name==="process"&&(0,eslint_devkit_1.propertyName)(node)==="env"}function leaksEnv(node){switch(node.type){case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:return isProcessEnv(node);case eslint_devkit_1.AST_NODE_TYPES.TSAsExpression:case eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression:case eslint_devkit_1.AST_NODE_TYPES.SpreadElement:return leaksEnv(node.type===eslint_devkit_1.AST_NODE_TYPES.SpreadElement?node.argument:node.expression);case eslint_devkit_1.AST_NODE_TYPES.ObjectExpression:return node.properties.some(p=>leaksEnv(p.type===eslint_devkit_1.AST_NODE_TYPES.Property?p.value:p));case eslint_devkit_1.AST_NODE_TYPES.ArrayExpression:return node.elements.some(e=>e!==null&&leaksEnv(e));case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:return leaksEnv(node.consequent)||leaksEnv(node.alternate);case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:return leaksEnv(node.left)||leaksEnv(node.right);case eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression:return node.operator==="="&&leaksEnv(node.right);case eslint_devkit_1.AST_NODE_TYPES.SequenceExpression:return leaksEnv(node.expressions[node.expressions.length-1]);case eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral:return node.expressions.some(leaksWhenCoerced);case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:return node.operator==="+"&&[node.left,node.right].some(leaksWhenCoerced);case eslint_devkit_1.AST_NODE_TYPES.CallExpression:return node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&SERIALIZERS.has(`${node.callee.object.name}.${(0,eslint_devkit_1.propertyName)(node.callee)}`)&&node.arguments.some(leaksEnv);default:return false}}function leaksWhenCoerced(node){return(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral||node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression)&&leaksEnv(node)}function isLoggingCall(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;const obj=node.callee.object;const methodName=(0,eslint_devkit_1.propertyName)(node.callee);if(methodName===null||!LOGGING_FUNCTIONS.has(methodName)){return false}return obj.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(obj.name==="console"||/log(ger)?/i.test(obj.name))}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},CallExpression(node){if(!isLoggingCall(node))return;for(const arg of node.arguments){if(leaksEnv(arg)){context.report({node:arg,messageId:"envLogging"})}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noErrorSwallowing=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noErrorSwallowing=(0,eslint_devkit_1.createRule)({name:"no-error-swallowing",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-error-swallowing.md",description:"Detects empty catch blocks and missing error logging in Lambda handlers",cwe:"CWE-390",cvss:5},hasSuggestions:true,messages:{emptyCatchBlock:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Error Swallowing",cwe:"CWE-390",cvss:5,description:"Catch block swallows error without logging. Security incidents may go undetected.",severity:"MEDIUM",fix:'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',documentationLink:"https://cwe.mitre.org/data/definitions/390.html"}),addErrorLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Error Logging",description:"Log errors with context for security monitoring",severity:"LOW",fix:'console.error("Error:", error); // or use structured logger',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},allowWithComment:{type:"boolean",default:true,description:"Allow an empty catch block that carries an explanatory comment"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,allowWithComment:true}],createOnce(context,currentOptions){let allowInTests;let allowWithComment;const LOGGER_OBJECTS=/^(console|logger|log|winston|pino|bunyan|sentry|Sentry)$/;const LOGGER_METHODS=/^(log|error|warn|info|debug|captureException|captureMessage)$/;const LOGGING_FUNCTIONS=/^(log|report|capture|track|record|notify)\w*$/i;const FORWARDING_CALLBACKS=/^(next|reject|callback|cb|done|fail|emit)$/;const RESPONSE_OBJECTS=/^(res|response|reply|ctx)$/;const RESPONSE_METHODS=/^(status|sendStatus|json|send|end|writeHead|render|redirect)$/;function mentions(nodes,name){const stack=[...nodes];while(stack.length>0){const node=stack.pop();if(!node||typeof node.type!=="string")continue;if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.name===name)return true;for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value))stack.push(...value);else if(value&&typeof value==="object")stack.push(value)}}return false}function rootName(node){let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)current=current.object;return current.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?current.name:void 0}function memberNames(node){const names=[];let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if(current.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){names.unshift(current.property.name)}current=current.object}return names}function classifyCall(call,caughtName){const callee=call.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(FORWARDING_CALLBACKS.test(callee.name)){return caughtName!==void 0&&mentions(call.arguments,caughtName)?"forward":void 0}if(LOGGING_FUNCTIONS.test(callee.name))return"log";return void 0}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return void 0;const names=memberNames(callee);const method=names.at(-1)??"";if(names.length>1&&LOGGER_OBJECTS.test(names.at(-2)??"")&&LOGGER_METHODS.test(method)){return"log"}const root=rootName(callee);if(root===void 0)return void 0;if(LOGGER_OBJECTS.test(root)&&LOGGER_METHODS.test(method))return"log";if(RESPONSE_OBJECTS.test(root)&&names.some(n=>RESPONSE_METHODS.test(n))){return"respond"}return void 0}function analyze(block,caughtName){const result={logs:false,forwards:false,responds:false};const seen=new Set;const visit=node=>{if(!node||typeof node.type!=="string"||seen.has(node))return;seen.add(node);if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const kind=classifyCall(node,caughtName);if(kind==="log")result.logs=true;else if(kind==="forward")result.forwards=true;else if(kind==="respond")result.responds=true}for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const item of value)visit(item)}else if(value&&typeof value==="object"){visit(value)}}};visit(block);return result}function hasIntentionalComment(node){if(!allowWithComment)return false;const sourceCode=context.sourceCode;const comments=sourceCode.getCommentsInside(node.body);return comments.some(comment=>/intentional|expected|ignore|suppress|handled|silent/i.test(comment.value))}function hasThrow(block){return block.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.ThrowStatement)}function returnsFallback(block){return block.body.some(stmt=>{if(stmt.type!==eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return false;const value=stmt.argument;if(value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&value.name==="undefined"){return false}if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===true)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const status=value.properties.find(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/^(statusCode|status|ok|allowed|authorized)$/.test(p.key.name));if(status){const literal=status.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal?status.value.value:void 0;if(literal===true)return false;const code=Number(literal);if(code>=200&&code<300)return false}}return true})}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;({allowInTests=true,allowWithComment=true}=options);const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},CatchClause(node){const body=node.body;if(body.body.length===0){if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock",suggest:[{messageId:"addErrorLogging",fix:fixer=>{const errorParam=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:"error";return fixer.replaceText(body,`{ console.error('Error:', ${errorParam}); }`)}}]})}return}if(hasThrow(body)){return}const caughtName=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:void 0;const{logs,forwards,responds}=analyze(body,caughtName);if(logs||forwards||responds||returnsFallback(body)){return}if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock"})}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noErrorSwallowing=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noErrorSwallowing=(0,eslint_devkit_1.createRule)({name:"no-error-swallowing",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-error-swallowing.md",description:"Detects empty catch blocks and missing error logging in Lambda handlers",cwe:"CWE-390",cvss:5},hasSuggestions:true,messages:{emptyCatchBlock:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Error Swallowing",cwe:"CWE-390",cvss:5,description:"Catch block swallows error without logging. Security incidents may go undetected.",severity:"MEDIUM",fix:'Log the error with context: console.error("Operation failed", { error, awsRequestId: context.awsRequestId })',documentationLink:"https://cwe.mitre.org/data/definitions/390.html"}),addErrorLogging:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Error Logging",description:"Log errors with context for security monitoring",severity:"LOW",fix:'console.error("Error:", error); // or use structured logger',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-logging.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},allowWithComment:{type:"boolean",default:true,description:"Allow an empty catch block that carries an explanatory comment"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,allowWithComment:true}],createOnce(context,currentOptions){let allowInTests;let allowWithComment;const LOGGER_OBJECTS=/^(console|logger|log|winston|pino|bunyan|sentry|Sentry)$/;const LOGGER_METHODS=/^(log|error|warn|info|debug|captureException|captureMessage)$/;const LOGGING_FUNCTIONS=/^(log|report|capture|track|record|notify)\w*$/i;const FORWARDING_CALLBACKS=/^(next|reject|callback|cb|done|fail|emit)$/;const RESPONSE_OBJECTS=/^(res|response|reply|ctx)$/;const RESPONSE_METHODS=/^(status|sendStatus|json|send|end|writeHead|render|redirect)$/;function mentions(nodes,name){const stack=[...nodes];while(stack.length>0){const node=stack.pop();if(!node||typeof node.type!=="string")continue;if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.name===name)return true;for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value))stack.push(...value);else if(value&&typeof value==="object")stack.push(value)}}return false}function rootName(node){let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)current=current.object;return current.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?current.name:void 0}function memberNames(node){const names=[];let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if(current.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){names.unshift(current.property.name)}current=current.object}return names}function classifyCall(call,caughtName){const callee=call.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(FORWARDING_CALLBACKS.test(callee.name)){return caughtName!==void 0&&mentions(call.arguments,caughtName)?"forward":void 0}if(LOGGING_FUNCTIONS.test(callee.name))return"log";return void 0}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return void 0;const names=memberNames(callee);const method=names.at(-1)??"";if(names.length>1&&LOGGER_OBJECTS.test(names.at(-2)??"")&&LOGGER_METHODS.test(method)){return"log"}const root=rootName(callee);if(root===void 0)return void 0;if(LOGGER_OBJECTS.test(root)&&LOGGER_METHODS.test(method))return"log";if(RESPONSE_OBJECTS.test(root)&&names.some(n=>RESPONSE_METHODS.test(n))){return"respond"}return void 0}function analyze(block,caughtName){const result={logs:false,forwards:false,responds:false};const seen=new Set;const visit=node=>{if(!node||typeof node.type!=="string"||seen.has(node))return;seen.add(node);if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const kind=classifyCall(node,caughtName);if(kind==="log")result.logs=true;else if(kind==="forward")result.forwards=true;else if(kind==="respond")result.responds=true}for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const item of value)visit(item)}else if(value&&typeof value==="object"){visit(value)}}};visit(block);return result}function hasIntentionalComment(node){if(!allowWithComment)return false;const sourceCode=context.sourceCode;const comments=sourceCode.getCommentsInside(node.body);return comments.some(comment=>/intentional|expected|ignore|suppress|handled|silent/i.test(comment.value))}function hasThrow(block){return block.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.ThrowStatement)}function returnsFallback(block){return block.body.some(stmt=>{if(stmt.type!==eslint_devkit_1.AST_NODE_TYPES.ReturnStatement)return false;const value=stmt.argument;if(value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===null)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&value.name==="undefined"){return false}if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===true)return false;if(value.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&value.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&FORWARDING_CALLBACKS.test(value.callee.name)){return false}if(value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const status=value.properties.find(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/^(statusCode|status|ok|allowed|authorized)$/.test(p.key.name));if(status){const literal=status.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal?status.value.value:void 0;if(literal===true)return false;const code=Number(literal);if(code>=200&&code<300)return false}}return true})}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;({allowInTests=true,allowWithComment=true}=options);const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},CatchClause(node){const body=node.body;if(body.body.length===0){if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock",suggest:[{messageId:"addErrorLogging",fix:fixer=>{const errorParam=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:"error";return fixer.replaceText(body,`{ console.error('Error:', ${errorParam}); }`)}}]})}return}if(hasThrow(body)){return}const caughtName=node.param?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.param.name:void 0;const{logs,forwards,responds}=analyze(body,caughtName);if(logs||forwards||responds||returnsFallback(body)){return}if(!hasIntentionalComment(node)){context.report({node,messageId:"emptyCatchBlock"})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedDebugEndpoints=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const DEFAULT_DEBUG_PATHS=["/debug","/__debug__","/admin","/_admin","/test","/health"];exports.noExposedDebugEndpoints=(0,eslint_devkit_1.createRule)({name:"no-exposed-debug-endpoints",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-debug-endpoints.md",description:"Detect debug endpoints without auth in AWS Lambda handlers",cwe:"CWE-489",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Debug Endpoint",cwe:"CWE-489",description:"Debug endpoint exposed without authentication",severity:"HIGH",fix:"Remove debug endpoints from production or add authentication",documentationLink:"https://cwe.mitre.org/data/definitions/489.html"})},schema:[{type:"object",properties:{endpoints:{type:"array",items:{type:"string"},description:"Custom list of debug/admin endpoints to flag"},ignoreFiles:{type:"array",items:{type:"string"},description:"List of files or patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{}],createOnce(context){let debugPaths;function report(node){context.report({node,messageId:"violationDetected"})}return{before(){if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const options=context.options[0]||{};debugPaths=options.endpoints||DEFAULT_DEBUG_PATHS;const ignoreFiles=options.ignoreFiles||[];const filename=context.filename;if(ignoreFiles.some(pattern=>filename.includes(pattern))){return false}return true},Property(node){const pathText=(0,eslint_devkit_1.staticString)(node.value);if(node.key.type==="Identifier"&&node.key.name==="path"&&pathText!==null){const path=pathText.toLowerCase();if(debugPaths.some(dp=>path.includes(dp.toLowerCase()))){let parent=node.parent;while(parent){if(parent.type==="Property"&&parent.key.type==="Identifier"&&["http","httpApi"].includes(parent.key.name)){report(node.value);return}parent=parent.parent}}}},BinaryExpression(node){if(node.operator==="==="||node.operator==="=="||node.operator==="!=="||node.operator==="!="){const checkNode=side=>{const staticText=(0,eslint_devkit_1.staticString)(side);if(staticText!==null){const val=staticText.toLowerCase();if(debugPaths.some(dp=>val.includes(dp.toLowerCase()))){const other=side===node.left?node.right:node.left;if(other.type==="MemberExpression"&&other.object.type==="Identifier"&&(other.object.name==="event"||other.object.name==="evt")&&other.property.type==="Identifier"&&["path","rawPath","resource","routeKey"].includes(other.property.name)){report(side)}}}};checkNode(node.left);checkNode(node.right)}},Literal(node){if(typeof node.value==="string"){const path=node.value.toLowerCase();if(debugPaths.some(dp=>path===dp.toLowerCase())){const parent=node.parent;if(parent&&parent.type==="BinaryExpression"&&(parent.left===node||parent.right===node)){const other=parent.left===node?parent.right:parent.left;if(other.type==="MemberExpression"&&other.object.type==="Identifier"&&(other.object.name==="event"||other.object.name==="evt")){return}}if(parent&&parent.type==="Property"&&parent.key.type==="Identifier"&&parent.key.name==="path"){return}report(node)}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedDebugEndpoints=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const DEFAULT_DEBUG_PATHS=["/debug","/__debug__","/admin","/_admin","/test","/health"];const ROUTE_PROPERTIES=new Set(["path","rawPath","resource","routeKey"]);const ROUTE_CHAINS=new Set(["path","rawPath","resource","routeKey","requestContext.path","requestContext.resourcePath","requestContext.http.path"]);const ROUTE_TESTS=new Set(["includes","startsWith","endsWith"]);function routePath(text){const path=text.replace(/^[A-Z]+\s+/,"").toLowerCase();return path.startsWith("/")?path:`/${path}`}exports.noExposedDebugEndpoints=(0,eslint_devkit_1.createRule)({name:"no-exposed-debug-endpoints",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-debug-endpoints.md",description:"Detect debug endpoints without auth in AWS Lambda handlers",cwe:"CWE-489",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Debug Endpoint",cwe:"CWE-489",description:"Debug endpoint exposed without authentication",severity:"HIGH",fix:"Remove debug endpoints from production or add authentication",documentationLink:"https://cwe.mitre.org/data/definitions/489.html"})},schema:[{type:"object",properties:{endpoints:{type:"array",items:{type:"string"},description:"Custom list of debug/admin endpoints to flag"},ignoreFiles:{type:"array",items:{type:"string"},description:"List of files or patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{}],createOnce(context){let debugPaths;const reported=new Set;function report(node){if(reported.has(node))return;reported.add(node);context.report({node,messageId:"violationDetected"})}function isDebugRoute(text){const path=routePath(text);return debugPaths.some(dp=>{const debug=dp.toLowerCase().replace(/\/+$/,"");return path===debug||path.startsWith(`${debug}/`)})}function readsRoute(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const variable=context.sourceCode.getScope(node).references.find(r=>r.identifier===node)?.resolved;return variable?.defs.some(destructuresRoute)??false}const path=(0,eslint_devkit_1.memberPath)(node);return path!==null&&["event","evt"].includes(path[0])&&ROUTE_CHAINS.has(path.slice(1).join("."))}function destructuresRoute(def){const property=def.name.parent;if(property.type!==eslint_devkit_1.AST_NODE_TYPES.Property||!(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(property),ROUTE_PROPERTIES)){return false}if(def.type==="Parameter")return true;const init=def.node.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator?def.node.init:null;return init?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["event","evt"].includes(init.name)}return{before(){if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;reported.clear();const options=context.options[0]||{};debugPaths=options.endpoints||DEFAULT_DEBUG_PATHS;const ignoreFiles=options.ignoreFiles||[];const filename=context.filename;if(ignoreFiles.some(pattern=>filename.includes(pattern))){return false}return true},Property(node){const pathText=(0,eslint_devkit_1.staticString)(node.value);if((0,eslint_devkit_1.objectKeyName)(node)!=="path"||pathText===null||!isDebugRoute(pathText)){return}const event=node.parent.parent;const list=event.parent?.parent;if(event.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(event),["http","httpApi"])&&list?.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression&&list.parent.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.objectKeyName)(list.parent)==="events"){report(node.value)}},BinaryExpression(node){if(!["===","==","!==","!="].includes(node.operator))return;for(const[side,other]of[[node.left,node.right],[node.right,node.left]]){const text=(0,eslint_devkit_1.staticString)(side);if(text!==null&&isDebugRoute(text)&&readsRoute(other)){report(side)}}},CallExpression(node){const callee=node.callee;const text=(0,eslint_devkit_1.staticString)(node.arguments[0]);if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),ROUTE_TESTS)&&text!==null&&isDebugRoute(text)&&readsRoute(callee.object)){report(node.arguments[0])}},SwitchStatement(node){if(!readsRoute(node.discriminant))return;for(const c of node.cases){const test=c.test;if(test===null)continue;const text=(0,eslint_devkit_1.staticString)(test);if(text!==null&&isDebugRoute(text))report(test)}},Literal(node){if(typeof node.value!=="string")return;const path=node.value.toLowerCase();if(!debugPaths.some(dp=>path===dp.toLowerCase()))return;const parent=node.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.Property&&parent.value===node&&(0,eslint_devkit_1.objectKeyName)(parent)==="path"){return}report(node)}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedErrorDetails=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const SENSITIVE_ERROR_PROPERTIES=new Set(["stack","stackTrace","trace","cause","__dirname","__filename","path","hostname","config","env"]);exports.noExposedErrorDetails=(0,eslint_devkit_1.createRule)({name:"no-exposed-error-details",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-error-details.md",description:"Detects Lambda handlers exposing internal error details in responses",cwe:"CWE-209",cvss:4.3},messages:{exposedErrorDetails:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Error Details",cwe:"CWE-209",cvss:4.3,description:"Response exposes {{property}} which may leak internal paths, configs, or stack traces.",severity:"MEDIUM",fix:"Return generic error message. Log detailed errors server-side: console.error(error)",documentationLink:"https://cwe.mitre.org/data/definitions/209.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let insideApiResponse;function isApiResponse(node){return node.properties.some(prop=>prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["statusCode","body","headers"].includes(prop.key.name))}function getSensitiveProperty(node){const field=(0,eslint_devkit_1.propertyName)(node);if(field!==null&&SENSITIVE_ERROR_PROPERTIES.has(field)){return field}return null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}insideApiResponse=false;return true},ReturnStatement(node){if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression&&isApiResponse(node.argument)){insideApiResponse=true}},"ReturnStatement:exit"(){insideApiResponse=false},MemberExpression(node){if(!insideApiResponse)return;const sensitiveProperty=getSensitiveProperty(node);if(sensitiveProperty){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.Property||parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){context.report({node,messageId:"exposedErrorDetails",data:{property:sensitiveProperty}})}}},CallExpression(node){if(!insideApiResponse)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="JSON"&&(0,eslint_devkit_1.propertyName)(node.callee)==="stringify"){const arg=node.arguments[0];if(arg?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(/error|err|e|exception/i.test(arg.name)){context.report({node,messageId:"exposedErrorDetails",data:{property:"error object"}})}}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedErrorDetails=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const response_position_1=require("../../utils/response-position");const eslint_devkit_1=require("@interlace/eslint-devkit");const SENSITIVE_ERROR_PROPERTIES=new Set(["stack","stackTrace","trace","cause","path","hostname","config","env"]);const DEPLOYMENT_PATHS=new Set(["__dirname","__filename"]);const ERROR_NAME=/^(e|ex|err|error|exception|failure)$|Error$/;exports.noExposedErrorDetails=(0,eslint_devkit_1.createRule)({name:"no-exposed-error-details",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-error-details.md",description:"Detects Lambda handlers exposing internal error details in responses",cwe:"CWE-209",cvss:4.3},messages:{exposedErrorDetails:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Error Details",cwe:"CWE-209",cvss:4.3,description:"Response exposes {{property}} which may leak internal paths, configs, or stack traces.",severity:"MEDIUM",fix:"Return generic error message. Log detailed errors server-side: console.error(error)",documentationLink:"https://cwe.mitre.org/data/definitions/209.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isApiResponse(node){return node.properties.some(prop=>prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(prop),["statusCode","body","headers"]))}function resolve(id){for(let scope=context.sourceCode.getScope(id);scope;scope=scope.upper){const variable=scope.set.get(id.name);if(variable)return variable}return void 0}function isError(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const variable=resolve(node);return ERROR_NAME.test(node.name)||(variable?.defs.some(d=>d.type==="CatchClause")??false)}function disclosure(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const field=(0,eslint_devkit_1.propertyName)(node);return field!==null&&SENSITIVE_ERROR_PROPERTIES.has(field)&&isError(node.object)?field:null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return DEPLOYMENT_PATHS.has(node.name)?node.name:null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="JSON"&&(0,eslint_devkit_1.propertyName)(node.callee)==="stringify"&&node.arguments.length>0&&isError(node.arguments[0])){return"error object"}return null}function scan(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression){return}const property=disclosure(node);if(property!==null){context.report({node,messageId:"exposedErrorDetails",data:{property}});return}for(const key of Object.keys(node)){if(key==="parent")continue;if((key==="key"||key==="property")&&!node.computed){continue}const value=node[key];for(const child of Array.isArray(value)?value:[value]){if(child&&typeof child.type==="string"){scan(child)}}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},ObjectExpression(node){if(!isApiResponse(node)||!(0,response_position_1.inResponsePosition)(node))return;for(const prop of node.properties)scan(prop)}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHardcodedCredentialsSdk=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const AWS_ACCESS_KEY_PATTERNS=[/^AKIA[0-9A-Z]{16}$/,/^ASIA[0-9A-Z]{16}$/,/^AIDA[0-9A-Z]{16}$/];const CREDENTIAL_PROPERTY_NAMES=["accessKeyId","secretAccessKey","sessionToken","awsAccessKeyId","awsSecretAccessKey"];const AWS_SDK_V3_CLIENTS=new Set(["S3Client","DynamoDBClient","LambdaClient","SQSClient","SNSClient","SecretsManagerClient","KMSClient","STSClient","IAMClient","EC2Client","ECSClient","CloudWatchClient","CloudWatchLogsClient","APIGatewayClient","CognitoIdentityClient","CognitoIdentityProviderClient","EventBridgeClient","StepFunctionsClient","RDSClient","ElastiCacheClient"]);exports.noHardcodedCredentialsSdk=(0,eslint_devkit_1.createRule)({name:"no-hardcoded-credentials-sdk",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-hardcoded-credentials-sdk.md",description:"Detects hardcoded AWS credentials in SDK client configurations",cwe:"CWE-798",cvss:9.8},messages:{hardcodedCredentials:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Hardcoded AWS Credentials",cwe:"CWE-798",description:"Hardcoded AWS credentials detected in {{clientName}} config: {{property}}",severity:"CRITICAL",fix:"Use credential provider chain: new {{clientName}}({ credentials: fromNodeProviderChain() })",documentationLink:"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow hardcoded credentials in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function looksLikeAwsAccessKey(value){return AWS_ACCESS_KEY_PATTERNS.some(pattern=>pattern.test(value))}function isCredentialProperty(name){return CREDENTIAL_PROPERTY_NAMES.some(credProp=>name.toLowerCase()===credProp.toLowerCase())}function getAwsClientName(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const name=node.callee.name;if(AWS_SDK_V3_CLIENTS.has(name)){return name}if(name.endsWith("Client")&&/^(S3|DynamoDB|Lambda|SQS|SNS|Secrets|KMS|STS|IAM|EC2|ECS|CloudWatch|APIGateway|Cognito|EventBridge|StepFunctions|RDS|ElastiCache|SSM|Athena|Glue|Kinesis|Firehose|Rekognition|Textract|Comprehend|Polly|Lex|Bedrock|My|Custom|AWS)/i.test(name)){return name}}return null}function checkCredentialsObject(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="credentials"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(prop.value,clientName)}if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isCredentialProperty(prop.key.name)){const staticText1=(0,eslint_devkit_1.staticString)(prop.value);if(staticText1!==null){reportHardcodedCredential(prop,clientName,prop.key.name)}}}}function checkCredentialsInner(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isCredentialProperty(prop.key.name)){const staticText2=(0,eslint_devkit_1.staticString)(prop.value);if(staticText2!==null){const value=staticText2;const keyName=prop.key.name.toLowerCase();if(keyName==="accesskeyid"){if(looksLikeAwsAccessKey(value)){reportHardcodedCredential(prop,clientName,prop.key.name)}}else if(keyName==="secretaccesskey"){if(value.length>=20){reportHardcodedCredential(prop,clientName,prop.key.name)}}else if(keyName==="sessiontoken"){if(value.length>=15){reportHardcodedCredential(prop,clientName,prop.key.name)}}}else if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){reportHardcodedCredential(prop,clientName,prop.key.name)}}}}function reportHardcodedCredential(node,clientName,propertyName){context.report({node,messageId:"hardcodedCredentials",data:{clientName,property:propertyName}})}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},NewExpression(node){const clientName=getAwsClientName(node);if(!clientName)return;if(node.arguments.length>0&&node.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsObject(node.arguments[0],clientName)}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.id.name.toLowerCase().includes("credential")&&node.init?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(node.init,"AWSClient")}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHardcodedCredentialsSdk=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const AWS_ACCESS_KEY_PATTERNS=[/^AKIA[0-9A-Z]{16}$/,/^ASIA[0-9A-Z]{16}$/,/^AIDA[0-9A-Z]{16}$/];const CREDENTIAL_PROPERTY_NAMES=["accessKeyId","secretAccessKey","sessionToken","awsAccessKeyId","awsSecretAccessKey"];const AWS_SDK_V3_CLIENTS=new Set(["S3Client","DynamoDBClient","LambdaClient","SQSClient","SNSClient","SecretsManagerClient","KMSClient","STSClient","IAMClient","EC2Client","ECSClient","CloudWatchClient","CloudWatchLogsClient","APIGatewayClient","CognitoIdentityClient","CognitoIdentityProviderClient","EventBridgeClient","StepFunctionsClient","RDSClient","ElastiCacheClient"]);exports.noHardcodedCredentialsSdk=(0,eslint_devkit_1.createRule)({name:"no-hardcoded-credentials-sdk",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-hardcoded-credentials-sdk.md",description:"Detects hardcoded AWS credentials in SDK client configurations",cwe:"CWE-798",cvss:9.8},messages:{hardcodedCredentials:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Hardcoded AWS Credentials",cwe:"CWE-798",description:"Hardcoded AWS credentials detected in {{clientName}} config: {{property}}",severity:"CRITICAL",fix:"Use credential provider chain: new {{clientName}}({ credentials: fromNodeProviderChain() })",documentationLink:"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow hardcoded credentials in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function looksLikeAwsAccessKey(value){return AWS_ACCESS_KEY_PATTERNS.some(pattern=>pattern.test(value))}function isCredentialProperty(name){return CREDENTIAL_PROPERTY_NAMES.some(credProp=>name.toLowerCase()===credProp.toLowerCase())}function resolve(id){for(let scope=context.sourceCode.getScope(id);scope;scope=scope.upper){const variable=scope.set.get(id.name);if(variable)return variable}return void 0}function isFromAwsSdk(id){const def=resolve(id)?.defs[0];let source;if(def?.type==="ImportBinding"){source=def.parent.source}else if(def?.type==="Variable"&&def.node.init?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&def.node.init.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&def.node.init.callee.name==="require"){source=def.node.init.arguments[0]}const specifier=(0,eslint_devkit_1.staticString)(source);return specifier!==null&&/^(aws-sdk|@aws-sdk\/)/.test(specifier)}function rootIdentifier(node){while(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)node=node.object;return node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node:null}function getAwsClientName(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const root=rootIdentifier(node.callee);return root!==null&&isFromAwsSdk(root)?((0,eslint_devkit_1.memberPath)(node.callee)??[root.name]).join("."):null}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const name=node.callee.name;if(AWS_SDK_V3_CLIENTS.has(name)||isFromAwsSdk(node.callee)){return name}if(name.endsWith("Client")&&/^(S3|DynamoDB|Lambda|SQS|SNS|Secrets|KMS|STS|IAM|EC2|ECS|CloudWatch|APIGateway|Cognito|EventBridge|StepFunctions|RDS|ElastiCache|SSM|Athena|Glue|Kinesis|Firehose|Rekognition|Textract|Comprehend|Polly|Lex|Bedrock|My|Custom|AWS)/i.test(name)){return name}}return null}function checkCredentialsObject(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if((0,eslint_devkit_1.objectKeyName)(prop)==="credentials"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(prop.value,clientName)}}checkCredentialsInner(obj,clientName)}function isHardcoded(property,value){switch(property.toLowerCase()){case"accesskeyid":case"awsaccesskeyid":return looksLikeAwsAccessKey(value);case"secretaccesskey":case"awssecretaccesskey":return value.length>=20;default:return value.length>=15}}function checkPositionalCredentials(node,clientName){["accessKeyId","secretAccessKey","sessionToken"].forEach((name,i)=>{const text=(0,eslint_devkit_1.staticString)(node.arguments[i]);if(text!==null&&isHardcoded(name,text)){reportHardcodedCredential(node.arguments[i],clientName,name)}})}function checkCredentialsInner(obj,clientName){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const key=(0,eslint_devkit_1.objectKeyName)(prop);if(key!==null&&isCredentialProperty(key)){const staticText2=(0,eslint_devkit_1.staticString)(prop.value);if(staticText2!==null){if(isHardcoded(key,staticText2)){reportHardcodedCredential(prop,clientName,key)}}else if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){reportHardcodedCredential(prop,clientName,key)}}}}function reportHardcodedCredential(node,clientName,propertyName){context.report({node,messageId:"hardcodedCredentials",data:{clientName,property:propertyName}})}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},NewExpression(node){const clientName=getAwsClientName(node);if(!clientName)return;if(node.arguments.length>0&&node.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsObject(node.arguments[0],clientName)}else if(/(^|\.)Credentials$/.test(clientName)){checkPositionalCredentials(node,clientName)}},CallExpression(node){const path=(0,eslint_devkit_1.memberPath)(node.callee);const root=rootIdentifier(node.callee);if(path?.slice(1).join(".")==="config.update"&&root!==null&&isFromAwsSdk(root)&&node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsObject(node.arguments[0],`${root.name}.config`)}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.id.name.toLowerCase().includes("credential")&&node.init?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCredentialsInner(node.init,"AWSClient")}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingAuthorizationCheck=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const AUTHORIZATION_CHECK_PATTERNS=["requestContext.authorizer","requestContext.identity","Authorization","authorization","claims","principalId","isAdmin","isAuthenticated","userId","sub","scope","permissions"];const SENSITIVE_OPERATIONS=new Set(["query","put","delete","update","insert","remove","create","send","invoke","putObject","deleteObject","getObject","putItem","deleteItem","updateItem","getItem"]);const BUILTIN_NAMESPACES=new Set(["Object","Reflect","JSON","Math","Array","Promise","Atomics"]);const IN_PROCESS_COLLECTIONS=new Set(["Map","Set","WeakMap","WeakSet"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noMissingAuthorizationCheck=(0,eslint_devkit_1.createRule)({name:"no-missing-authorization-check",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-missing-authorization-check.md",description:"Detects Lambda handlers without authorization checks",cwe:"CWE-862",cvss:7.5},messages:{missingAuthCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing Authorization Check",cwe:"CWE-862",cvss:7.5,description:"Lambda handler performs {{operation}} operation without authorization check. Users may access resources without proper permissions.",severity:"HIGH",fix:"Add authorization check: const claims = event.requestContext.authorizer?.claims; if (!claims?.sub) { return { statusCode: 401 } }",documentationLink:"https://cwe.mitre.org/data/definitions/862.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow missing auth in test files"},handlerPatterns:{type:"array",items:{type:"string"},description:"Handler file patterns to check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,handlerPatterns:[]}],createOnce(context,currentOptions){let currentFunctionNode;let hasAuthCheck;let hasEventParameter;let sensitiveOperations;function enterFunction(node){const hasEvent=node.params.some(param=>param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(param.name));if(hasEvent){currentFunctionNode=node;hasAuthCheck=false;hasEventParameter=true;sensitiveOperations.length=0}}function exitFunction(node){if(currentFunctionNode!==node)return;if(hasEventParameter&&!hasAuthCheck){for(const{node:opNode,operation}of sensitiveOperations){context.report({node:opNode,messageId:"missingAuthCheck",data:{operation}})}}currentFunctionNode=null;hasEventParameter=false}function isAuthorizationAccess(node){const sourceCode=context.sourceCode;const text=sourceCode.getText(node);return AUTHORIZATION_CHECK_PATTERNS.some(pattern=>text.includes(pattern)||text.toLowerCase().includes(pattern.toLowerCase()))}function isInProcessReceiver(receiver){if(receiver.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;let scope=context.sourceCode.getScope(receiver);while(scope){const variable=scope.set.get(receiver.name);if(variable&&variable.defs.length>0){const def=variable.defs[0];const init=variable.defs.length===1&&def.node.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator?def.node.init:null;return init?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression&&init.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&IN_PROCESS_COLLECTIONS.has(init.callee.name)}scope=scope.upper}return BUILTIN_NAMESPACES.has(receiver.name)}function getSensitiveOperationName(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!isInProcessReceiver(node.callee.object)){const operation=(0,eslint_devkit_1.propertyName)(node.callee);if(operation!==null&&SENSITIVE_OPERATIONS.has(operation)){return operation}}return null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}currentFunctionNode=null;hasAuthCheck=false;hasEventParameter=false;sensitiveOperations=[];return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentFunctionNode)return;if(isAuthorizationAccess(node)){hasAuthCheck=true}},CallExpression(node){if(!currentFunctionNode)return;const operation=getSensitiveOperationName(node);if(operation){sensitiveOperations.push({node,operation})}},ReturnStatement(node){if(!currentFunctionNode)return;if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.argument.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="statusCode"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&(prop.value.value===401||prop.value.value===403)){hasAuthCheck=true}}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingAuthorizationCheck=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const AUTHORIZATION_SEGMENTS=new Set(["authorizer","authorization"]);const IDENTITY_FIELDS=new Set(["claims","principalId","isAdmin","isAuthenticated","userId","sub","scope","permissions"]);const CLIENT_INPUT=new Set(["body","pathParameters","queryStringParameters","multiValueQueryStringParameters"]);const SENSITIVE_OPERATIONS=new Set(["query","put","delete","update","insert","remove","create","send","invoke","putObject","deleteObject","getObject","putItem","deleteItem","updateItem","getItem"]);const BUILTIN_NAMESPACES=new Set(["Object","Reflect","JSON","Math","Array","Promise","Atomics"]);const IN_PROCESS_COLLECTIONS=new Set(["Map","Set","WeakMap","WeakSet"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noMissingAuthorizationCheck=(0,eslint_devkit_1.createRule)({name:"no-missing-authorization-check",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-missing-authorization-check.md",description:"Detects Lambda handlers without authorization checks",cwe:"CWE-862",cvss:7.5},messages:{missingAuthCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing Authorization Check",cwe:"CWE-862",cvss:7.5,description:"Lambda handler performs {{operation}} operation without authorization check. Users may access resources without proper permissions.",severity:"HIGH",fix:"Add authorization check: const claims = event.requestContext.authorizer?.claims; if (!claims?.sub) { return { statusCode: 401 } }",documentationLink:"https://cwe.mitre.org/data/definitions/862.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow missing auth in test files"},handlerPatterns:{type:"array",items:{type:"string"},description:"Handler file patterns to check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,handlerPatterns:[]}],createOnce(context,currentOptions){let currentFunctionNode;let hasAuthCheck;let hasEventParameter;let sensitiveOperations;function enterFunction(node){const hasEvent=node.params.some(param=>param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&EVENT_PARAM_NAMES.has(param.name));if(hasEvent){currentFunctionNode=node;hasAuthCheck=false;hasEventParameter=true;sensitiveOperations.length=0}}function exitFunction(node){if(currentFunctionNode!==node)return;if(hasEventParameter&&!hasAuthCheck){for(const{node:opNode,operation}of sensitiveOperations){context.report({node:opNode,messageId:"missingAuthCheck",data:{operation}})}}currentFunctionNode=null;hasEventParameter=false}function isAuthorizationAccess(node){const path=(0,eslint_devkit_1.memberPath)(node);if(path===null)return false;const clientInput=isClientInput(node,path);if(path.some(p=>AUTHORIZATION_SEGMENTS.has(p.toLowerCase()))&&!clientInput){return true}if(path.some((p,i)=>p==="requestContext"&&path[i+1]==="identity")){return true}return IDENTITY_FIELDS.has(path[path.length-1])&&!clientInput}function isClientInput(node,path){if(path.some(p=>CLIENT_INPUT.has(p)))return true;let root=node;while(root.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression)root=root.object;const variable=context.sourceCode.getScope(root).references.find(r=>r.identifier===root)?.resolved;const def=variable?.defs[0];let init=def?.node.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator?def.node.init:null;if(init?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&init.arguments.length>0){init=init.arguments[0]}if(init?.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression)init=init.left;const source=init?(0,eslint_devkit_1.memberPath)(init):null;return source!==null&&source.some(p=>CLIENT_INPUT.has(p))}function isInProcessReceiver(receiver){if(receiver.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;let scope=context.sourceCode.getScope(receiver);while(scope){const variable=scope.set.get(receiver.name);if(variable&&variable.defs.length>0){const def=variable.defs[0];const init=variable.defs.length===1&&def.node.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator?def.node.init:null;return init?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression&&init.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&IN_PROCESS_COLLECTIONS.has(init.callee.name)}scope=scope.upper}return BUILTIN_NAMESPACES.has(receiver.name)}function getSensitiveOperationName(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!isInProcessReceiver(node.callee.object)){const operation=(0,eslint_devkit_1.propertyName)(node.callee);if(operation!==null&&SENSITIVE_OPERATIONS.has(operation)){return operation}}return null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true,handlerPatterns=[]}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}if(handlerPatterns.length>0&&!handlerPatterns.some(pattern=>filename.includes(pattern))){return false}currentFunctionNode=null;hasAuthCheck=false;hasEventParameter=false;sensitiveOperations=[];return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentFunctionNode)return;if(isAuthorizationAccess(node)){hasAuthCheck=true}},CallExpression(node){if(!currentFunctionNode)return;const operation=getSensitiveOperationName(node);if(operation){sensitiveOperations.push({node,operation})}},ReturnStatement(node){if(!currentFunctionNode)return;if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of node.argument.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="statusCode"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&(prop.value.value===401||prop.value.value===403)){hasAuthCheck=true}}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noOverlyPermissiveIamPolicy=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const POLICY_PROPERTIES=new Set(["Resource","Action","Principal"]);const DANGEROUS_WILDCARDS=new Set(["*","arn:aws:*","arn:*:*:*:*:*"]);exports.noOverlyPermissiveIamPolicy=(0,eslint_devkit_1.createRule)({name:"no-overly-permissive-iam-policy",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-overly-permissive-iam-policy.md",description:"Detects IAM policies with overly broad permissions (wildcards)",cwe:"CWE-732",cvss:6.5},messages:{permissivePolicy:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Overly Permissive IAM Policy",cwe:"CWE-732",cvss:6.5,description:'IAM policy has wildcard {{property}}: "{{value}}". Violates principle of least privilege.',severity:"HIGH",fix:'Restrict {{property}} to specific resources/actions. Example: "arn:aws:s3:::my-bucket/*" instead of "*"',documentationLink:"https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isDangerousWildcard(value){return DANGEROUS_WILDCARDS.has(value)||value.endsWith("*")&&value.includes(":*:")}function checkPolicyProperty(node,propertyName){const value=node.value;const staticText=(0,eslint_devkit_1.staticString)(value);if(staticText!==null){if(isDangerousWildcard(staticText)){context.report({node,messageId:"permissivePolicy",data:{property:propertyName,value:staticText}})}}if(value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){for(const element of value.elements){if(element?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof element.value==="string"){if(isDangerousWildcard(element.value)){context.report({node:element,messageId:"permissivePolicy",data:{property:propertyName,value:element.value}})}}}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},Property(node){if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const keyName=node.key.name;if(POLICY_PROPERTIES.has(keyName)){checkPolicyProperty(node,keyName)}}if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.key.value==="string"){const keyName=node.key.value;if(POLICY_PROPERTIES.has(keyName)){checkPolicyProperty(node,keyName)}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noOverlyPermissiveIamPolicy=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const POLICY_PROPERTIES=new Set(["Resource","Action","Principal"]);const DANGEROUS_WILDCARDS=new Set(["*","arn:aws:*","arn:*:*:*:*:*"]);exports.noOverlyPermissiveIamPolicy=(0,eslint_devkit_1.createRule)({name:"no-overly-permissive-iam-policy",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-overly-permissive-iam-policy.md",description:"Detects IAM policies with overly broad permissions (wildcards)",cwe:"CWE-732",cvss:6.5},messages:{permissivePolicy:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Overly Permissive IAM Policy",cwe:"CWE-732",cvss:6.5,description:'IAM policy has wildcard {{property}}: "{{value}}". Violates principle of least privilege.',severity:"HIGH",fix:'Restrict {{property}} to specific resources/actions. Example: "arn:aws:s3:::my-bucket/*" instead of "*"',documentationLink:"https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isDangerousWildcard(value){return DANGEROUS_WILDCARDS.has(value)||value.endsWith("*")&&value.includes(":*:")}function checkWildcards(value,report,propertyName){const staticText=(0,eslint_devkit_1.staticString)(value);if(staticText!==null&&isDangerousWildcard(staticText)){context.report({node:report,messageId:"permissivePolicy",data:{property:propertyName,value:staticText}})}if(value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){for(const element of value.elements){if(element)checkWildcards(element,element,propertyName)}}}function inDenyStatement(node){const statement=node.parent;const effects=statement.properties.filter(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.objectKeyName)(p)==="Effect");return(0,eslint_devkit_1.staticString)(effects.at(-1)?.value)==="Deny"}function checkPolicyProperty(node,propertyName){if(inDenyStatement(node))return;checkWildcards(node.value,node,propertyName);if(propertyName==="Principal"&&node.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const p of node.value.properties){if(p.type===eslint_devkit_1.AST_NODE_TYPES.Property){checkWildcards(p.value,p,propertyName)}}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},Property(node){const keyName=(0,eslint_devkit_1.objectKeyName)(node);if(keyName!==null&&POLICY_PROPERTIES.has(keyName)){checkPolicyProperty(node,keyName)}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsMidly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");exports.noPermissiveCorsMidly=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-middy",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-middy.md",description:"Detects @middy/http-cors middleware with permissive origin (*)",cwe:"CWE-942",cvss:7.5},messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Middy",cwe:"CWE-942",description:"Wildcard CORS origin in @middy/http-cors allows any domain",severity:"HIGH",fix:'Use specific origins: httpCors({ origins: ["https://your-domain.com"] })',documentationLink:"https://middy.js.org/docs/middlewares/http-cors"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isCorsMiddlewareCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const name=node.callee.name.toLowerCase();return name==="httpcors"||name==="cors"}return false}function checkCorsOptions(node,optionsObj){for(const prop of optionsObj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const keyName=prop.key.name.toLowerCase();if(keyName==="origin"||keyName==="origins"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value==="*"){context.report({node:prop,messageId:"permissiveCors"})}else if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression){for(const element of prop.value.elements){if(element?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&element.value==="*"){context.report({node:element,messageId:"permissiveCors"})}}}}}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},CallExpression(node){if(!isCorsMiddlewareCall(node))return;if(node.arguments.length===0){context.report({node,messageId:"permissiveCors"});return}if(node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCorsOptions(node,node.arguments[0])}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsMidly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");exports.noPermissiveCorsMidly=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-middy",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-middy.md",description:"Detects @middy/http-cors middleware with permissive origin (*)",cwe:"CWE-942",cvss:7.5},messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Middy",cwe:"CWE-942",description:"Wildcard CORS origin in @middy/http-cors allows any domain",severity:"HIGH",fix:'Use specific origins: httpCors({ origins: ["https://your-domain.com"] })',documentationLink:"https://middy.js.org/docs/middlewares/http-cors"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function moduleOf(id,seen=new Set){for(let scope=context.sourceCode.getScope(id);scope;scope=scope.upper){const variable=scope.set.get(id.name);if(!variable||variable.defs.length===0)continue;const def=variable.defs[0];if(def.type==="ImportBinding"){return(0,eslint_devkit_1.staticString)(def.parent.source)}const init=def.node.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator?def.node.init:null;if(init?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&!seen.has(init.name)){seen.add(id.name);return moduleOf(init,seen)}return init?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&init.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&init.callee.name==="require"?(0,eslint_devkit_1.staticString)(init.arguments[0]):null}return void 0}function isCorsMiddlewareCall(node){if(node.callee.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const source=moduleOf(node.callee);if(source===void 0){const name=node.callee.name.toLowerCase();return name==="httpcors"||name==="cors"}return source==="@middy/http-cors"}function checkCorsOptions(node,optionsObj){for(const prop of optionsObj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const keyName=(0,eslint_devkit_1.objectKeyName)(prop)?.toLowerCase();if(keyName==="origin"||keyName==="origins"){const values=prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression?prop.value.elements:[prop.value];for(const value of values){if((0,eslint_devkit_1.staticString)(value)==="*"){context.report({node:value===prop.value?prop:value,messageId:"permissiveCors"})}}}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},CallExpression(node){if(!isCorsMiddlewareCall(node))return;if(node.arguments.length===0){context.report({node,messageId:"permissiveCors"});return}if(node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkCorsOptions(node,node.arguments[0])}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsResponse=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");exports.noPermissiveCorsResponse=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-response",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-response.md",description:"Detects permissive CORS (Access-Control-Allow-Origin: *) in Lambda response headers",cwe:"CWE-942",cvss:7.5},fixable:"code",messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Lambda Response",cwe:"CWE-942",description:"Wildcard CORS origin (*) allows any domain to access this Lambda function",severity:"HIGH",fix:'Use specific origins: headers: { "Access-Control-Allow-Origin": "https://your-domain.com" }',documentationLink:"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html"}),useSpecificOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Specific Origin",description:"Specify allowed origins instead of wildcard",severity:"LOW",fix:'Replace "*" with specific domain(s)',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow permissive CORS in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isLambdaResponse(obj){const propNames=obj.properties.filter(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property).map(p=>p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?p.key.name:"");return propNames.includes("statusCode")||propNames.includes("body")}function checkHeadersObject(obj){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;let headerName="";if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){headerName=prop.key.name}else{headerName=(0,eslint_devkit_1.staticString)(prop.key)??""}if(headerName.toLowerCase()==="access-control-allow-origin"){if(prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value==="*"){context.report({node:prop,messageId:"permissiveCors",fix:fixer=>{return fixer.replaceText(prop.value,'"https://your-domain.com"')}})}}}}function checkResponseObject(obj){if(!isLambdaResponse(obj))return;for(const prop of obj.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&prop.key.name==="headers"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkHeadersObject(prop.value)}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},ReturnStatement(node){if(node.argument?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.argument)}},ArrowFunctionExpression(node){if(node.body.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.body)}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.id.name.toLowerCase().includes("response")&&node.init?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkResponseObject(node.init)}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCorsResponse=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const response_position_1=require("../../utils/response-position");exports.noPermissiveCorsResponse=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors-response",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-response.md",description:"Detects permissive CORS (Access-Control-Allow-Origin: *) in Lambda response headers",cwe:"CWE-942",cvss:7.5},fixable:"code",messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS in Lambda Response",cwe:"CWE-942",description:"Wildcard CORS origin (*) allows any domain to access this Lambda function",severity:"HIGH",fix:'Use specific origins: headers: { "Access-Control-Allow-Origin": "https://your-domain.com" }',documentationLink:"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html"}),useSpecificOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Specific Origin",description:"Specify allowed origins instead of wildcard",severity:"LOW",fix:'Replace "*" with specific domain(s)',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow permissive CORS in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){function isLambdaResponse(obj){return obj.properties.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(p),["statusCode","body"]))}function checkHeadersObject(obj){for(const prop of obj.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const headerName=(0,eslint_devkit_1.objectKeyName)(prop)?.toLowerCase();if(headerName!=="access-control-allow-origin")continue;const values=prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression?prop.value.elements:[prop.value];for(const value of values){if(value&&(0,eslint_devkit_1.staticString)(value)==="*"){context.report({node:prop,messageId:"permissiveCors",fix:fixer=>fixer.replaceText(value,'"https://your-domain.com"')})}}}}function checkResponseObject(obj){if(!isLambdaResponse(obj))return;for(const prop of obj.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(prop),["headers","multiValueHeaders"])&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkHeadersObject(prop.value)}}}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}return true},ObjectExpression(node){if((0,response_position_1.inResponsePosition)(node))checkResponseObject(node)}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSecretsInEnv=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const SECRET_PATTERNS=[/password/i,/secret/i,/api[_-]?key/i,/api[_-]?token/i,/auth[_-]?token/i,/access[_-]?token/i,/private[_-]?key/i,/encryption[_-]?key/i,/db[_-]?pass/i,/database[_-]?password/i,/jwt[_-]?secret/i,/signing[_-]?key/i,/client[_-]?secret/i,/aws[_-]?secret/i];exports.noSecretsInEnv=(0,eslint_devkit_1.createRule)({name:"no-secrets-in-env",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-secrets-in-env.md",description:"Detects secrets directly assigned to environment variables",cwe:"CWE-798",cvss:9.8},messages:{secretsInEnv:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Secret in Environment Variable",cwe:"CWE-798",description:'Secret "{{varName}}" should not be hardcoded in environment variables',severity:"CRITICAL",fix:'Use AWS Secrets Manager: const secret = await secretsClient.send(new GetSecretValueCommand({ SecretId: "{{varName}}" }))',documentationLink:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},additionalPatterns:{type:"array",items:{type:"string"},default:[],description:"Extra environment-variable name patterns to treat as secrets"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalPatterns:[]}],createOnce(context,currentOptions){let allPatterns;function isSecretName(name){return allPatterns.some(pattern=>pattern.test(name))}function isHardcodedSecretValue(node){const staticText=(0,eslint_devkit_1.staticString)(node);if(staticText!==null){return staticText.length>5}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.some(quasi=>quasi.value.raw.length>5)}return false}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true,additionalPatterns=[]}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}allPatterns=[...SECRET_PATTERNS,...additionalPatterns.map(p=>new RegExp(p,"i"))];return true},AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.object.name==="process"&&(0,eslint_devkit_1.propertyName)(node.left.object)==="env"){let envVarName="";if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){envVarName=node.left.property.name}else{envVarName=(0,eslint_devkit_1.staticString)(node.left.property)??""}if(isSecretName(envVarName)&&isHardcodedSecretValue(node.right)){context.report({node,messageId:"secretsInEnv",data:{varName:envVarName}})}}},Property(node){let propName="";if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){propName=node.key.name}else{propName=(0,eslint_devkit_1.staticString)(node.key)??""}if(isSecretName(propName)&&isHardcodedSecretValue(node.value)){let parent=node.parent;while(parent){if(parent.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){parent=parent.parent;continue}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/env|config|settings/i.test(parent.id.name)){context.report({node,messageId:"secretsInEnv",data:{varName:propName}});break}break}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSecretsInEnv=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const lambda_evidence_1=require("../../utils/lambda-evidence");const SECRET_PATTERNS=[/password/i,/secret/i,/api[_-]?key/i,/api[_-]?token/i,/auth[_-]?token/i,/access[_-]?token/i,/private[_-]?key/i,/encryption[_-]?key/i,/db[_-]?pass/i,/database[_-]?password/i,/jwt[_-]?secret/i,/signing[_-]?key/i,/client[_-]?secret/i,/aws[_-]?secret/i];const ENVIRONMENT_KEYS=["environment","Environment","Variables"];exports.noSecretsInEnv=(0,eslint_devkit_1.createRule)({name:"no-secrets-in-env",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-secrets-in-env.md",description:"Detects secrets directly assigned to environment variables",cwe:"CWE-798",cvss:9.8},messages:{secretsInEnv:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Secret in Environment Variable",cwe:"CWE-798",description:'Secret "{{varName}}" should not be hardcoded in environment variables',severity:"CRITICAL",fix:'Use AWS Secrets Manager: const secret = await secretsClient.send(new GetSecretValueCommand({ SecretId: "{{varName}}" }))',documentationLink:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},additionalPatterns:{type:"array",items:{type:"string"},default:[],description:"Extra environment-variable name patterns to treat as secrets"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalPatterns:[]}],createOnce(context,currentOptions){let allPatterns;function isSecretName(name){return allPatterns.some(pattern=>pattern.test(name))}function isHardcodedSecretValue(node){const staticText=(0,eslint_devkit_1.staticString)(node);if(staticText!==null){return staticText.length>5&&!isReference(staticText)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return!isReference(node.quasis[0].value.raw)&&node.quasis.some(quasi=>quasi.value.raw.length>5)}return false}function isReference(text){return text.startsWith("arn:")||/^\/[\w./-]+$/.test(text)}function inEnvironment(node){const holder=node.parent.parent;if(holder.type===eslint_devkit_1.AST_NODE_TYPES.Property&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(holder),ENVIRONMENT_KEYS)){return true}return holder.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&holder.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&/env|config|settings/i.test(holder.id.name)}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true,additionalPatterns=[]}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}allPatterns=[...SECRET_PATTERNS,...additionalPatterns.map(p=>new RegExp(p,"i"))];return true},AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.object.name==="process"&&(0,eslint_devkit_1.propertyName)(node.left.object)==="env"){let envVarName="";if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){envVarName=node.left.property.name}else{envVarName=(0,eslint_devkit_1.staticString)(node.left.property)??""}if(isSecretName(envVarName)&&isHardcodedSecretValue(node.right)){context.report({node,messageId:"secretsInEnv",data:{varName:envVarName}})}}},Property(node){let propName="";if(node.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){propName=node.key.name}else{propName=(0,eslint_devkit_1.staticString)(node.key)??""}if(isSecretName(propName)&&isHardcodedSecretValue(node.value)&&inEnvironment(node)){context.report({node,messageId:"secretsInEnv",data:{varName:propName}})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnboundedBatchProcessing=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const handler_params_1=require("../../utils/handler-params");const eslint_devkit_1=require("@interlace/eslint-devkit");const BATCH_SOURCE_PROPERTIES=new Set(["Records","records","items","messages"]);exports.noUnboundedBatchProcessing=(0,eslint_devkit_1.createRule)({name:"no-unbounded-batch-processing",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md",description:"Detects processing batch records without size validation",cwe:"CWE-770",cvss:5.5},messages:{unboundedBatch:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unbounded Batch Processing",cwe:"CWE-770",cvss:5.5,description:"Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.",severity:"MEDIUM",fix:'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"})},schema:[{type:"object",properties:{...handler_params_1.HANDLER_PARAM_SCHEMA,allowInTests:{type:"boolean",default:true},maxBatchSize:{type:"number",default:100,description:"Batch size above which processing must be explicitly bounded"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,maxBatchSize:100}],createOnce(context,currentOptions){let eventParamNames;let currentHandlerNode;let hasBatchSizeCheck;let batchAccessNodes;let eventParamName;function enterFunction(node){const hasEvent=node.params.some(p=>{if(p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamNames.has(p.name)){eventParamName.push(p.name);return true}return false});if(hasEvent){currentHandlerNode=node;hasBatchSizeCheck=false;batchAccessNodes.length=0}}function exitFunction(node){if(currentHandlerNode!==node)return;if(!hasBatchSizeCheck){for(const{node:batchNode,source}of batchAccessNodes){context.report({node:batchNode,messageId:"unboundedBatch",data:{source}})}}currentHandlerNode=null;eventParamName.length=0}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;eventParamNames=new Set(options.eventParamNames??handler_params_1.DEFAULT_EVENT_PARAM_NAMES);const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}currentHandlerNode=null;hasBatchSizeCheck=false;batchAccessNodes=[];eventParamName=[];return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;const batchProperty=(0,eslint_devkit_1.propertyName)(node);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamName.includes(node.object.name)&&batchProperty!==null&&BATCH_SOURCE_PROPERTIES.has(batchProperty)){batchAccessNodes.push({node,source:`${node.object.name}.${batchProperty}`})}if((0,eslint_devkit_1.propertyName)(node)==="length"){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.object),BATCH_SOURCE_PROPERTIES)){hasBatchSizeCheck=true}}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.property.name)){hasBatchSizeCheck=true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["slice","splice","take","chunk"].includes(node.callee.name)){hasBatchSizeCheck=true}},BinaryExpression(node){if(!currentHandlerNode)return;if(["<","<=",">",">="].includes(node.operator)){const sourceCode=context.sourceCode;const text=sourceCode.getText(node);if(/\.length|Records|records/.test(text)){hasBatchSizeCheck=true}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnboundedBatchProcessing=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const handler_params_1=require("../../utils/handler-params");const eslint_devkit_1=require("@interlace/eslint-devkit");const BATCH_SOURCE_PROPERTIES=new Set(["Records","records","items","messages"]);exports.noUnboundedBatchProcessing=(0,eslint_devkit_1.createRule)({name:"no-unbounded-batch-processing",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md",description:"Detects processing batch records without size validation",cwe:"CWE-770",cvss:5.5},messages:{unboundedBatch:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unbounded Batch Processing",cwe:"CWE-770",cvss:5.5,description:"Processing {{source}} without size check. Large batches may cause timeout or memory exhaustion.",severity:"MEDIUM",fix:'Validate batch size before processing: if (event.Records.length > MAX_BATCH) throw new Error("Batch too large")',documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html"})},schema:[{type:"object",properties:{...handler_params_1.HANDLER_PARAM_SCHEMA,allowInTests:{type:"boolean",default:true},maxBatchSize:{type:"number",default:100,description:"Batch size above which processing must be explicitly bounded"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,maxBatchSize:100}],createOnce(context,currentOptions){let eventParamNames;let currentHandlerNode;let hasBatchSizeCheck;let batchAccessNodes;let eventParamName;let batchAliases;let maxBatchSize;function isBatch(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const variable=context.sourceCode.getScope(node).references.find(r=>r.identifier===node)?.resolved;return variable!=null&&batchAliases.has(variable)}return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamName.includes(node.object.name)&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node),BATCH_SOURCE_PROPERTIES)}function bounds(limit){return limit!==void 0&&!(limit.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof limit.value==="number"&&limit.value>maxBatchSize)}function enterFunction(node){const hasEvent=node.params.some(p=>{if(p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamNames.has(p.name)){eventParamName.push(p.name);return true}return false});if(hasEvent){currentHandlerNode=node;hasBatchSizeCheck=false;batchAccessNodes.length=0}}function exitFunction(node){if(currentHandlerNode!==node)return;if(!hasBatchSizeCheck){for(const{node:batchNode,source}of batchAccessNodes){context.report({node:batchNode,messageId:"unboundedBatch",data:{source}})}}currentHandlerNode=null;eventParamName.length=0}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;eventParamNames=new Set(options.eventParamNames??handler_params_1.DEFAULT_EVENT_PARAM_NAMES);const{allowInTests=true}=options;({maxBatchSize}={maxBatchSize:100,...options});const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}currentHandlerNode=null;hasBatchSizeCheck=false;batchAccessNodes=[];eventParamName=[];batchAliases=new Set;return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;if(isBatch(node)){batchAccessNodes.push({node,source:`${node.object.name}.${(0,eslint_devkit_1.propertyName)(node)}`})}},VariableDeclarator(node){if(!currentHandlerNode||node.id.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectPattern||node.init?.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!eventParamName.includes(node.init.name)){return}for(const prop of node.id.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.objectKeyName)(prop),BATCH_SOURCE_PROPERTIES)){const local=prop.value.name;for(const variable of context.sourceCode.getDeclaredVariables(node)){if(variable.name===local)batchAliases.add(variable)}batchAccessNodes.push({node:prop,source:`${node.init.name}.${(0,eslint_devkit_1.objectKeyName)(prop)}`})}}},CallExpression(node){if(!currentHandlerNode)return;const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&isBatch(callee.object)){const method=(0,eslint_devkit_1.propertyName)(callee);if(method==="slice"||method==="splice"){hasBatchSizeCheck||=bounds(node.arguments[1])}else if(method==="take"){hasBatchSizeCheck||=bounds(node.arguments[0])}}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["take","chunk"].includes(callee.name)&&node.arguments.length>0&&isBatch(node.arguments[0])){hasBatchSizeCheck||=bounds(node.arguments[1])}},BinaryExpression(node){if(!currentHandlerNode)return;if(!["<","<=",">",">="].includes(node.operator))return;for(const[side,other]of[[node.left,node.right],[node.right,node.left]]){if(side.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(side)==="length"&&isBatch(side.object)){hasBatchSizeCheck||=bounds(other)}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedEventBody=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_EVENT_PROPERTIES=["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","multiValueHeaders","rawPath","rawQueryString"];const DEFAULT_VALIDATION_METHOD_NAMES=["validator","httpJsonBodyParser","@middy/validator","parse","validate","parseAsync","safeParse","safeParseAsync","assert","is"];exports.noUnvalidatedEventBody=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-event-body",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unvalidated-event-body.md",description:"Detects Lambda handlers using event body/params without validation",cwe:"CWE-20",cvss:8},messages:{unvalidatedInput:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Event Input",cwe:"CWE-20",cvss:8,description:"Lambda handler uses {{property}} without validation. This can lead to injection attacks.",severity:"HIGH",fix:"Validate event input using Middy validator, Zod, or Joi before use",documentationLink:"https://owasp.org/www-project-serverless-top-10/"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow unvalidated input in test files"},additionalProperties:{type:"array",items:{type:"string"},default:[],description:"Additional event properties to check"},validationMethodNames:{type:"array",items:{type:"string"},default:[...DEFAULT_VALIDATION_METHOD_NAMES],description:"Method names that count as validating a value. Replaces the default."}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalProperties:[]}],createOnce(context,currentOptions){let validationMethodNames;let dangerousProperties;let validatedVariables;let eventParameters;let hasValidationMiddleware;let fileImportsLambda;function isValidationCall(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const property=node.callee.property;if(property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&validationMethodNames.has(property.name)){return true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(validationMethodNames.has(node.callee.name)){return true}}}return false}function isEventPropertyAccess(node){const property=(0,eslint_devkit_1.propertyName)(node);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParameters.has(node.object.name)&&property!==null&&dangerousProperties.has(property)){return{eventName:node.object.name,property}}return null}function semanticParent(node){let current=node;let parent=current.parent;while(parent&&(parent.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSAsExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression)){current=parent;parent=current.parent}return parent}function isExportedAsHandler(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&node.id?.name==="handler"){return true}const parent=node.parent;if(!parent)return false;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.id.name==="handler"){return true}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression){const left=parent.left;if(left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(left)==="handler"){return true}}return false}function isLambdaSignature(params,node){if(params.length<1)return false;const first=params[0];if(first.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const second=params[1];const hasContextSibling=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(second.name==="context"||second.name==="callback");const looksLikeExpress=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(first.name==="req"&&second.name==="res"||first.name==="request"&&second.name==="response");if(looksLikeExpress)return false;const isEventName=first.name==="event"||first.name==="evt";if(isEventName&&hasContextSibling)return true;if(isEventName&&fileImportsLambda)return true;if(isExportedAsHandler(node)){const allowedHandlerParam=["event","evt","e","request","req"];if(allowedHandlerParam.includes(first.name))return true}return false}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true,additionalProperties=[],validationMethodNames:configuredValidationMethods}=options;validationMethodNames=new Set(configuredValidationMethods??DEFAULT_VALIDATION_METHOD_NAMES);const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}dangerousProperties=new Set([...DANGEROUS_EVENT_PROPERTIES,...additionalProperties]);validatedVariables=new Set;eventParameters=new Set;hasValidationMiddleware=false;const sourceCode=context.sourceCode;fileImportsLambda=sourceCode.ast.body.some(n=>{if(n.type!==eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration)return false;const src=String(n.source.value);return src==="aws-lambda"||src.startsWith("@aws-sdk/")||src.startsWith("@middy/")||src==="@aws-cdk/aws-lambda"});return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){if(!isLambdaSignature(node.params,node))return;const first=node.params[0];eventParameters.add(first.name)},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(node.callee)==="use"){for(const arg of node.arguments){if(arg.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&arg.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["validator","httpJsonBodyParser"].includes(arg.callee.name)){hasValidationMiddleware=true}}}if(isValidationCall(node)){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){validatedVariables.add(parent.id.name)}}},MemberExpression(node){if(hasValidationMiddleware)return;const eventAccess=isEventPropertyAccess(node);if(!eventAccess)return;const parent=semanticParent(node);if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&isValidationCall(parent)){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.UnaryExpression&&parent.operator==="typeof"){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.IfStatement||parent?.type===eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression){return}if(node.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ChainExpression){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.callee.object.name==="console"){return}context.report({node,messageId:"unvalidatedInput",data:{property:`event.${eventAccess.property}`}})}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedEventBody=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_EVENT_PROPERTIES=["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","multiValueHeaders","rawPath","rawQueryString"];const DEFAULT_VALIDATION_METHOD_NAMES=["validator","httpJsonBodyParser","@middy/validator","parse","validate","parseAsync","safeParse","safeParseAsync","assert","is"];exports.noUnvalidatedEventBody=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-event-body",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unvalidated-event-body.md",description:"Detects Lambda handlers using event body/params without validation",cwe:"CWE-20",cvss:8},messages:{unvalidatedInput:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Event Input",cwe:"CWE-20",cvss:8,description:"Lambda handler uses {{property}} without validation. This can lead to injection attacks.",severity:"HIGH",fix:"Validate event input using Middy validator, Zod, or Joi before use",documentationLink:"https://owasp.org/www-project-serverless-top-10/"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow unvalidated input in test files"},additionalProperties:{type:"array",items:{type:"string"},default:[],description:"Additional event properties to check"},validationMethodNames:{type:"array",items:{type:"string"},default:[...DEFAULT_VALIDATION_METHOD_NAMES],description:"Method names that count as validating a value. Replaces the default."}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,additionalProperties:[]}],createOnce(context,currentOptions){let validationMethodNames;let dangerousProperties;let validatedVariables;let eventParameters;let hasValidationMiddleware;let pending;let fileImportsLambda;let validatorMiddleware;function modulesLoadedBy(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration){return[{source:node.source.value,locals:node.specifiers.map(spec=>spec.local.name)}]}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration)return[];return node.declarations.flatMap(d=>{const init=d.init;const source=init?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&init.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&init.callee.name==="require"?(0,eslint_devkit_1.staticString)(init.arguments[0]):null;if(source===null)return[];return[{source,locals:d.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?[d.id.name]:[]}]})}function isValidationCall(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const property=node.callee.property;if(property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&validationMethodNames.has(property.name)){return true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(validationMethodNames.has(node.callee.name)){return true}}}return false}function isEventPropertyAccess(node){const property=(0,eslint_devkit_1.propertyName)(node);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParameters.has(node.object.name)&&property!==null&&dangerousProperties.has(property)){return{eventName:node.object.name,property}}return null}function semanticParent(node){let current=node;let parent=current.parent;while(parent&&(parent.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSAsExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression)){current=parent;parent=current.parent}return parent}function isExportedAsHandler(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&node.id?.name==="handler"){return true}const parent=node.parent;if(!parent)return false;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.id.name==="handler"){return true}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression){const left=parent.left;if(left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(left)==="handler"){return true}}return false}function isLambdaSignature(params,node){if(params.length<1)return false;const first=params[0];if(first.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const second=params[1];const hasContextSibling=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(second.name==="context"||second.name==="callback");const looksLikeExpress=second?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(first.name==="req"&&second.name==="res"||first.name==="request"&&second.name==="response");if(looksLikeExpress)return false;const isEventName=first.name==="event"||first.name==="evt";if(isEventName&&hasContextSibling)return true;if(isEventName&&fileImportsLambda)return true;if(isExportedAsHandler(node)){const allowedHandlerParam=["event","evt","e","request","req"];if(allowedHandlerParam.includes(first.name))return true}return false}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true,additionalProperties=[],validationMethodNames:configuredValidationMethods}=options;validationMethodNames=new Set(configuredValidationMethods??DEFAULT_VALIDATION_METHOD_NAMES);const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}dangerousProperties=new Set([...DANGEROUS_EVENT_PROPERTIES,...additionalProperties]);validatedVariables=new Set;eventParameters=new Set;hasValidationMiddleware=false;pending=[];const sourceCode=context.sourceCode;const loads=sourceCode.ast.body.flatMap(modulesLoadedBy);fileImportsLambda=loads.some(({source:src})=>src==="aws-lambda"||src.startsWith("@aws-sdk/")||src.startsWith("@middy/")||src==="@aws-cdk/aws-lambda");validatorMiddleware=new Set(["validator","httpJsonBodyParser",...loads.filter(({source})=>source==="@middy/validator").flatMap(({locals})=>locals)]);return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){if(!isLambdaSignature(node.params,node))return;const first=node.params[0];eventParameters.add(first.name)},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(node.callee)==="use"){for(const arg of node.arguments){if(arg.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&arg.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&validatorMiddleware.has(arg.callee.name)){hasValidationMiddleware=true}}}if(isValidationCall(node)){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){validatedVariables.add(parent.id.name)}}},MemberExpression(node){const eventAccess=isEventPropertyAccess(node);if(!eventAccess)return;const parent=semanticParent(node);if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&isValidationCall(parent)){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.UnaryExpression&&parent.operator==="typeof"){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.IfStatement||parent?.type===eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression){return}if(node.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.optional){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.ChainExpression){return}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.callee.object.name==="console"){return}pending.push({node,property:eventAccess.property})},"Program:exit"(){if(hasValidationMiddleware)return;for(const{node,property}of pending){context.report({node,messageId:"unvalidatedInput",data:{property:`event.${property}`}})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUserControlledRequests=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_CLIENT_METHODS=new Set(["fetch","request","get","post","put","delete","patch","axios","got","nodeFetch","superagent"]);const HTTP_CLIENT_OBJECTS=new Set(["http","https","axios","got","request"]);const USER_INPUT_PROPERTIES=new Set(["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","rawPath","rawQueryString"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noUserControlledRequests=(0,eslint_devkit_1.createRule)({name:"no-user-controlled-requests",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-user-controlled-requests.md",description:"Detects HTTP requests with user-controlled URLs (SSRF vulnerability)",cwe:"CWE-918",cvss:9.1},messages:{ssrfVulnerability:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Server-Side Request Forgery (SSRF)",cwe:"CWE-918",cvss:9.1,description:"HTTP request URL contains user-controlled input from {{source}}. Attackers can access internal services or exfiltrate data.",severity:"CRITICAL",fix:"Validate URL against allowlist before making request. Never use user input directly in URLs.",documentationLink:"https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow user-controlled URLs in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let eventParameters;let taintedVariables;function isEventParameter(name){return eventParameters.has(name)}function getEventInputSource(node){const field=(0,eslint_devkit_1.propertyName)(node);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.name)&&field!==null&&USER_INPUT_PROPERTIES.has(field)){return`event.${field}`}const outer=(0,eslint_devkit_1.memberPropertyName)(node.object);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.object.name)&&outer!==null&&USER_INPUT_PROPERTIES.has(outer)){return`event.${outer}.${(0,eslint_devkit_1.propertyName)(node)??"[...]"}`}return null}function getTaintSource(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const source=getEventInputSource(node);if(source)return source}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=taintedVariables.get(node.name);if(source)return source}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){for(const expr of node.expressions){const source=getTaintSource(expr);if(source)return source}}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const leftSource=getTaintSource(node.left);if(leftSource)return leftSource;const rightSource=getTaintSource(node.right);if(rightSource)return rightSource}return null}function isHttpClientCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_METHODS.has(node.callee.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_OBJECTS.has(node.callee.object.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),["get","post","put","delete","patch","request"])){return true}return false}function checkUrlArgument(node){if(node.arguments.length===0)return null;const urlArg=node.arguments[0];const source=getTaintSource(urlArg);if(source){return{tainted:true,source}}if(urlArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of urlArg.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["url","uri","href","baseURL"].includes(prop.key.name)){const propSource=getTaintSource(prop.value);if(propSource){return{tainted:true,source:propSource}}}}}return null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}eventParameters=new Set;taintedVariables=new Map;return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){for(const param of node.params){if(param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EVENT_PARAM_NAMES.has(param.name)){eventParameters.add(param.name)}}}},VariableDeclarator(node){if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.init){const source=getTaintSource(node.init);if(source){taintedVariables.set(node.id.name,source)}}},AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=getTaintSource(node.right);if(source){taintedVariables.set(node.left.name,source)}}},CallExpression(node){if(!isHttpClientCall(node))return;const result=checkUrlArgument(node);if(result?.tainted){context.report({node,messageId:"ssrfVulnerability",data:{source:result.source}})}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUserControlledRequests=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_CLIENT_METHODS=new Set(["fetch","request","get","post","put","delete","patch","axios","got","nodeFetch","superagent"]);const HTTP_CLIENT_OBJECTS=new Set(["http","https","axios","got","request"]);const USER_INPUT_PROPERTIES=new Set(["body","queryStringParameters","pathParameters","multiValueQueryStringParameters","headers","rawPath","rawQueryString"]);const EVENT_PARAM_NAMES=new Set(["event","evt","e","request","req"]);exports.noUserControlledRequests=(0,eslint_devkit_1.createRule)({name:"no-user-controlled-requests",meta:{interop:{runtimes:["eslint","oxlint"]},type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-user-controlled-requests.md",description:"Detects HTTP requests with user-controlled URLs (SSRF vulnerability)",cwe:"CWE-918",cvss:9.1},messages:{ssrfVulnerability:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Server-Side Request Forgery (SSRF)",cwe:"CWE-918",cvss:9.1,description:"HTTP request URL contains user-controlled input from {{source}}. Attackers can access internal services or exfiltrate data.",severity:"CRITICAL",fix:"Validate URL against allowlist before making request. Never use user input directly in URLs.",documentationLink:"https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true,description:"Allow user-controlled URLs in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let eventParameters;let taintedVariables;function isEventParameter(name){return eventParameters.has(name)}function getEventInputSource(node){const field=(0,eslint_devkit_1.propertyName)(node);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.name)&&field!==null&&USER_INPUT_PROPERTIES.has(field)){return`event.${field}`}const outer=(0,eslint_devkit_1.memberPropertyName)(node.object);if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isEventParameter(node.object.object.name)&&outer!==null&&USER_INPUT_PROPERTIES.has(outer)){return`event.${outer}.${(0,eslint_devkit_1.propertyName)(node)??"[...]"}`}return null}function getTaintSource(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){return getEventInputSource(node)??getTaintSource(node.object)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&(0,eslint_devkit_1.memberPath)(node.callee)?.join(".")==="JSON.parse"&&node.arguments.length>0){return getTaintSource(node.arguments[0])}if(node.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&node.operator==="||"&&Boolean(node.left.value)){return null}return getTaintSource(node.left)??getTaintSource(node.right)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TSAsExpression||node.type===eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression){return getTaintSource(node.expression)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=taintedVariables.get(node.name);if(source)return source}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){for(const expr of node.expressions){const source=getTaintSource(expr);if(source)return source}}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const leftSource=getTaintSource(node.left);if(leftSource)return leftSource;const rightSource=getTaintSource(node.right);if(rightSource)return rightSource}return null}function isHttpClientCall(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_METHODS.has(node.callee.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENT_OBJECTS.has(node.callee.object.name)){return true}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),["get","post","put","delete","patch","request"])){return true}return false}function checkUrlArgument(node){if(node.arguments.length===0)return null;const urlArg=node.arguments[0];const source=getTaintSource(urlArg);if(source){return{tainted:true,source}}if(urlArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of urlArg.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&["url","uri","href","baseURL"].includes(prop.key.name)){const propSource=getTaintSource(prop.value);if(propSource){return{tainted:true,source:propSource}}}}}return null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}eventParameters=new Set;taintedVariables=new Map;return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){for(const param of node.params){if(param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EVENT_PARAM_NAMES.has(param.name)){eventParameters.add(param.name)}}}},VariableDeclarator(node){const source=node.init?getTaintSource(node.init):null;if(!source)return;if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){taintedVariables.set(node.id.name,source)}if(node.id.type===eslint_devkit_1.AST_NODE_TYPES.ObjectPattern){for(const prop of node.id.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){taintedVariables.set(prop.value.name,source)}}}},AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const source=getTaintSource(node.right);if(source){taintedVariables.set(node.left.name,source)}}},CallExpression(node){if(!isHttpClientCall(node))return;const result=checkUrlArgument(node);if(result?.tainted){context.report({node,messageId:"ssrfVulnerability",data:{source:result.source}})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireTimeoutHandling=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const handler_params_1=require("../../utils/handler-params");const eslint_devkit_1=require("@interlace/eslint-devkit");const EXTERNAL_CALL_PATTERNS=new Set(["fetch","axios","got","request","send","invoke","query","execute","connect","promise","wait"]);exports.requireTimeoutHandling=(0,eslint_devkit_1.createRule)({name:"require-timeout-handling",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/require-timeout-handling.md",description:"Warns when Lambda handlers with external calls lack timeout handling",cwe:"CWE-400",cvss:6},messages:{missingTimeoutHandling:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Missing Timeout Handling",cwe:"CWE-400",cvss:6,description:"Lambda handler makes external calls without timeout handling. Function may timeout without cleanup.",severity:"MEDIUM",fix:"Use context.getRemainingTimeInMillis() to check available time before external calls, or use AbortController",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"})},schema:[{type:"object",properties:{...handler_params_1.HANDLER_PARAM_SCHEMA,contextParamNames:{type:"array",items:{type:"string"},default:[...handler_params_1.DEFAULT_CONTEXT_PARAM_NAMES],description:"Parameter names that identify the Lambda context argument. Replaces the default."},allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let eventParamNames;let contextParamNames;let currentHandlerNode;let hasTimeoutCheck;let hasExternalCalls;let hasContextParam;function enterFunction(node){const params=node.params;const hasEvent=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamNames.has(p.name));const hasContext=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&contextParamNames.has(p.name));if(hasEvent){currentHandlerNode=node;hasTimeoutCheck=false;hasExternalCalls=false;hasContextParam=hasContext}}function exitFunction(node){if(currentHandlerNode!==node)return;if(hasExternalCalls&&!hasTimeoutCheck&&hasContextParam){context.report({node,messageId:"missingTimeoutHandling"})}currentHandlerNode=null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;eventParamNames=new Set(options.eventParamNames??handler_params_1.DEFAULT_EVENT_PARAM_NAMES);contextParamNames=new Set(options.contextParamNames??handler_params_1.DEFAULT_CONTEXT_PARAM_NAMES);const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}currentHandlerNode=null;hasTimeoutCheck=false;hasExternalCalls=false;hasContextParam=false;return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;if((0,eslint_devkit_1.propertyName)(node)==="getRemainingTimeInMillis"){hasTimeoutCheck=true}},NewExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="AbortController"){hasTimeoutCheck=true}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EXTERNAL_CALL_PATTERNS.has(node.callee.name)){hasExternalCalls=true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if((0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),EXTERNAL_CALL_PATTERNS)){hasExternalCalls=true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="Promise"&&(0,eslint_devkit_1.propertyName)(node.callee)==="race"){hasTimeoutCheck=true}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireTimeoutHandling=void 0;const lambda_evidence_1=require("../../utils/lambda-evidence");const handler_params_1=require("../../utils/handler-params");const eslint_devkit_1=require("@interlace/eslint-devkit");const CLIENT_CONFIGURATION=new Set(["create","extend","defaults"]);const HTTP_CLIENTS=new Set(["axios","got","superagent","http","https"]);const EXTERNAL_CALL_PATTERNS=new Set(["fetch","axios","got","request","send","invoke","query","execute","connect","promise","wait"]);exports.requireTimeoutHandling=(0,eslint_devkit_1.createRule)({name:"require-timeout-handling",meta:{interop:{runtimes:["eslint","oxlint"]},type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/require-timeout-handling.md",description:"Warns when Lambda handlers with external calls lack timeout handling",cwe:"CWE-400",cvss:6},messages:{missingTimeoutHandling:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Missing Timeout Handling",cwe:"CWE-400",cvss:6,description:"Lambda handler makes external calls without timeout handling. Function may timeout without cleanup.",severity:"MEDIUM",fix:"Use context.getRemainingTimeInMillis() to check available time before external calls, or use AbortController",documentationLink:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html"})},schema:[{type:"object",properties:{...handler_params_1.HANDLER_PARAM_SCHEMA,contextParamNames:{type:"array",items:{type:"string"},default:[...handler_params_1.DEFAULT_CONTEXT_PARAM_NAMES],description:"Parameter names that identify the Lambda context argument. Replaces the default."},allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],createOnce(context,currentOptions){let eventParamNames;let contextParamNames;let currentHandlerNode;let hasTimeoutCheck;let hasExternalCalls;let hasContextParam;function enterFunction(node){const params=node.params;const hasEvent=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&eventParamNames.has(p.name));const hasContext=params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&contextParamNames.has(p.name));if(hasEvent){currentHandlerNode=node;hasTimeoutCheck=false;hasExternalCalls=false;hasContextParam=hasContext}}function exitFunction(node){if(currentHandlerNode!==node)return;if(hasExternalCalls&&!hasTimeoutCheck&&hasContextParam){context.report({node,messageId:"missingTimeoutHandling"})}currentHandlerNode=null}return{before(){const[options={}]=currentOptions();if(!(0,lambda_evidence_1.fileIsLambda)(context.sourceCode.ast))return false;eventParamNames=new Set(options.eventParamNames??handler_params_1.DEFAULT_EVENT_PARAM_NAMES);contextParamNames=new Set(options.contextParamNames??handler_params_1.DEFAULT_CONTEXT_PARAM_NAMES);const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return false}currentHandlerNode=null;hasTimeoutCheck=false;hasExternalCalls=false;hasContextParam=false;return true},"ArrowFunctionExpression, FunctionExpression, FunctionDeclaration"(node){enterFunction(node)},"ArrowFunctionExpression:exit"(node){exitFunction(node)},"FunctionExpression:exit"(node){exitFunction(node)},"FunctionDeclaration:exit"(node){exitFunction(node)},MemberExpression(node){if(!currentHandlerNode)return;if((0,eslint_devkit_1.propertyName)(node)==="getRemainingTimeInMillis"){hasTimeoutCheck=true}},NewExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="AbortController"){hasTimeoutCheck=true}},CallExpression(node){if(!currentHandlerNode)return;if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(EXTERNAL_CALL_PATTERNS.has(node.callee.name)){hasExternalCalls=true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if((0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),EXTERNAL_CALL_PATTERNS)||node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HTTP_CLIENTS.has(node.callee.object.name)&&!(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),CLIENT_CONFIGURATION)){hasExternalCalls=true}if((0,eslint_devkit_1.memberPath)(node.callee)?.join(".")==="AbortSignal.timeout"){hasTimeoutCheck=true}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="Promise"&&(0,eslint_devkit_1.propertyName)(node.callee)==="race"){hasTimeoutCheck=true}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fileIsLambda=fileIsLambda;const eslint_devkit_1=require("@interlace/eslint-devkit");const AWS_PACKAGES=new Set(["aws-lambda","aws-sdk","aws-xray-sdk","aws-xray-sdk-core","serverless","@aws-lambda-powertools/logger","@aws-lambda-powertools/tracer","@aws-lambda-powertools/metrics"]);const AWS_PREFIXES=["@aws-sdk/","@middy/","serverless-","@aws-lambda-powertools/"];const HANDLER_PARAMS=["event","context","callback"];function normalizeSpecifier(specifier){if(specifier.startsWith("npm:"))return specifier.slice(4);const deno=/^https?:\/\/deno\.land\/x\/([^@/]+)/.exec(specifier);if(deno)return deno[1];return specifier}function isAwsSpecifier(specifier){specifier=normalizeSpecifier(specifier);if(specifier.startsWith(".")||specifier.startsWith("/"))return false;if(AWS_PACKAGES.has(specifier))return true;const parts=specifier.split("/");const root=specifier.startsWith("@")?parts.slice(0,2).join("/"):parts[0];if(AWS_PACKAGES.has(root))return true;return AWS_PREFIXES.some(prefix=>specifier.startsWith(prefix))}function isImportEqualsLoad(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.TSImportEqualsDeclaration&&node.moduleReference.type===eslint_devkit_1.AST_NODE_TYPES.TSExternalModuleReference&&node.moduleReference.expression.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.moduleReference.expression.value==="string"&&isAwsSpecifier(node.moduleReference.expression.value)}function isAwsDynamicLoad(node,requireIsShadowed){const argument=node.type===eslint_devkit_1.AST_NODE_TYPES.ImportExpression?node.source:!requireIsShadowed&&node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="require"?node.arguments[0]:void 0;return argument?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof argument.value==="string"&&isAwsSpecifier(argument.value)}function namesHandler(node){return(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.name:node.value)==="handler"}function isExportsObject(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return node.name==="exports";return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name==="module"&&(0,eslint_devkit_1.propertyName)(node)==="exports"}function declaresHandler(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&isExportsObject(node.left.object)&&(0,eslint_devkit_1.propertyName)(node.left)==="handler"){return true}if(node.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration){if(node.specifiers.some(s=>namesHandler(s.exported)))return true;const decl=node.declaration;if(decl?.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&decl.id){return decl.id.name==="handler"}if(decl?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration){return decl.declarations.some(d=>d.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&d.id.name==="handler")}}return false}function hasHandlerSignature(node){if(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){return false}const params=node.params;if(params.length<2)return false;return HANDLER_PARAMS.slice(0,params.length).every((expected,i)=>params[i].type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&params[i].name===expected)}function bindsRequire(node){if(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){return node.params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&p.name==="require")}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Program||node.type===eslint_devkit_1.AST_NODE_TYPES.BlockStatement){return node.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration&&stmt.declarations.some(d=>d.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&d.id.name==="require"))}return false}const cache=new WeakMap;function fileIsLambda(ast){const cached=cache.get(ast);if(cached!==void 0)return cached;const result=computeIsLambda(ast);cache.set(ast,result);return result}function computeIsLambda(ast){let found=false;const visit=(node,requireIsShadowed)=>{if((node.type===eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.ExportAllDeclaration)&&node.source?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.source.value==="string"&&isAwsSpecifier(node.source.value)){found=true;return}if(isImportEqualsLoad(node)||isAwsDynamicLoad(node,requireIsShadowed)||declaresHandler(node)||hasHandlerSignature(node)){found=true;return}const shadowedHere=requireIsShadowed||bindsRequire(node);for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const child of value){if(child&&typeof child.type==="string"){visit(child,shadowedHere);if(found)return}}}else if(value&&typeof value==="object"&&typeof value.type==="string"){visit(value,shadowedHere);if(found)return}}};visit(ast,false);return found}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.fileIsLambda=fileIsLambda;const eslint_devkit_1=require("@interlace/eslint-devkit");const AWS_PACKAGES=new Set(["aws-lambda","aws-sdk","aws-xray-sdk","aws-xray-sdk-core","serverless","@aws-lambda-powertools/logger","@aws-lambda-powertools/tracer","@aws-lambda-powertools/metrics","aws-cdk-lib"]);const AWS_PREFIXES=["@aws-sdk/","@middy/","serverless-","@serverless/","@aws-cdk/","@aws-lambda-powertools/"];const HANDLER_PARAMS=["event","context","callback"];function normalizeSpecifier(specifier){if(specifier.startsWith("npm:"))return specifier.slice(4);const deno=/^https?:\/\/deno\.land\/x\/([^@/]+)/.exec(specifier);if(deno)return deno[1];return specifier}function isAwsSpecifier(specifier){specifier=normalizeSpecifier(specifier);if(specifier.startsWith(".")||specifier.startsWith("/"))return false;if(AWS_PACKAGES.has(specifier))return true;const parts=specifier.split("/");const root=specifier.startsWith("@")?parts.slice(0,2).join("/"):parts[0];if(AWS_PACKAGES.has(root))return true;return AWS_PREFIXES.some(prefix=>specifier.startsWith(prefix))}function isImportEqualsLoad(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.TSImportEqualsDeclaration&&node.moduleReference.type===eslint_devkit_1.AST_NODE_TYPES.TSExternalModuleReference&&node.moduleReference.expression.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.moduleReference.expression.value==="string"&&isAwsSpecifier(node.moduleReference.expression.value)}function isAwsDynamicLoad(node,requireIsShadowed){const argument=node.type===eslint_devkit_1.AST_NODE_TYPES.ImportExpression?node.source:!requireIsShadowed&&node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="require"?node.arguments[0]:void 0;return argument?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof argument.value==="string"&&isAwsSpecifier(argument.value)}function namesHandler(node){return(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.name:node.value)==="handler"}function isExportsObject(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return node.name==="exports";return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name==="module"&&(0,eslint_devkit_1.propertyName)(node)==="exports"}function declaresHandler(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&isExportsObject(node.left.object)&&(0,eslint_devkit_1.propertyName)(node.left)==="handler"){return true}if(node.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration){if(node.specifiers.some(s=>namesHandler(s.exported)))return true;const decl=node.declaration;if(decl?.type===eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&decl.id){return decl.id.name==="handler"}if(decl?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration){return decl.declarations.some(d=>d.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&d.id.name==="handler")}}return false}function hasHandlerSignature(node){if(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){return false}const params=node.params;if(params.length<2)return false;return HANDLER_PARAMS.slice(0,params.length).every((expected,i)=>params[i].type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&params[i].name===expected)}function bindsRequire(node){if(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){return node.params.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&p.name==="require")}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Program||node.type===eslint_devkit_1.AST_NODE_TYPES.BlockStatement){return node.body.some(stmt=>stmt.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration&&stmt.declarations.some(d=>d.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&d.id.name==="require"))}return false}const cache=new WeakMap;function fileIsLambda(ast){const cached=cache.get(ast);if(cached!==void 0)return cached;const result=computeIsLambda(ast);cache.set(ast,result);return result}function computeIsLambda(ast){let found=false;const visit=(node,requireIsShadowed)=>{if((node.type===eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration||node.type===eslint_devkit_1.AST_NODE_TYPES.ExportAllDeclaration)&&node.source?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.source.value==="string"&&isAwsSpecifier(node.source.value)){found=true;return}if(isImportEqualsLoad(node)||isAwsDynamicLoad(node,requireIsShadowed)||declaresHandler(node)||hasHandlerSignature(node)){found=true;return}const shadowedHere=requireIsShadowed||bindsRequire(node);for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const child of value){if(child&&typeof child.type==="string"){visit(child,shadowedHere);if(found)return}}}else if(value&&typeof value==="object"&&typeof value.type==="string"){visit(value,shadowedHere);if(found)return}}};visit(ast,false);return found}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.inResponsePosition=inResponsePosition;const eslint_devkit_1=require("@interlace/eslint-devkit");const CALLBACK_NAMES=new Set(["callback","cb","done"]);function inResponsePosition(node){const parent=node.parent;switch(parent.type){case eslint_devkit_1.AST_NODE_TYPES.ReturnStatement:case eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression:case eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator:case eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression:return true;case eslint_devkit_1.AST_NODE_TYPES.CallExpression:return parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&CALLBACK_NAMES.has(parent.callee.name);default:return false}}