@interlace/eslint-devkit 1.20.2 → 1.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.3",
|
|
4
4
|
"description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.urlEmbedsCredentials=urlEmbedsCredentials;exports.staticStringValue=staticStringValue;exports.isLiteralSecret=isLiteralSecret;exports.createHardcodedCredentialsRule=createHardcodedCredentialsRule;exports.urlPrefix=urlPrefix;const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const module_evidence_1=require("./module-evidence");const rule_creator_1=require("./rule-creator");const driver_origin_1=require("./driver-origin");const connection_config_1=require("./connection-config");const value_follow_1=require("./value-follow");const require_tls_rule_1=require("./require-tls-rule");const CREDENTIAL_KEYS=["password","pass","pwd","secret","passwd","auth"];const DEFAULT_CONNECTION_KEYS=["host","hostname","port","database","connectionString","socketPath","uri","url","connection","pool","schema"];function urlEmbedsCredentials(value,schemes){const match=/^([a-z][a-z0-9+.-]*):\/\/([^/@\s:]*:[^/@\s]+)@/i.exec(value);if(match===null)return false;return schemes.some(scheme=>scheme.toLowerCase()===match[1].toLowerCase())}function staticStringValue(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:void 0}if(node.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){const[{value}]=node.quasis;return value.cooked??value.raw}return void 0}function isLiteralSecret(node){const value=staticStringValue(node);return value!==void 0&&value.length>0}function createHardcodedCredentialsRule(config){const connectionKeys=[...DEFAULT_CONNECTION_KEYS,...config.connectionKeys??[]];const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules,extraEvidence:(0,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.urlEmbedsCredentials=urlEmbedsCredentials;exports.staticStringValue=staticStringValue;exports.isLiteralSecret=isLiteralSecret;exports.createHardcodedCredentialsRule=createHardcodedCredentialsRule;exports.urlPrefix=urlPrefix;const ast_node_types_1=require("../ast-node-types");const messaging_1=require("../messaging");const unscoped_mutation_rule_1=require("./unscoped-mutation-rule");const module_evidence_1=require("./module-evidence");const rule_creator_1=require("./rule-creator");const driver_origin_1=require("./driver-origin");const connection_config_1=require("./connection-config");const value_follow_1=require("./value-follow");const require_tls_rule_1=require("./require-tls-rule");const CREDENTIAL_KEYS=["password","pass","pwd","secret","passwd","auth"];const DEFAULT_CONNECTION_KEYS=["host","hostname","port","database","connectionString","socketPath","uri","url","connection","pool","schema"];function urlEmbedsCredentials(value,schemes){const match=/^([a-z][a-z0-9+.-]*):\/\/([^/@\s:]*:[^/@\s]+)@/i.exec(value);if(match===null)return false;return schemes.some(scheme=>scheme.toLowerCase()===match[1].toLowerCase())}function staticStringValue(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:void 0}if(node.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){const[{value}]=node.quasis;return value.cooked??value.raw}return void 0}function isLiteralSecret(node){const value=staticStringValue(node);return value!==void 0&&value.length>0}function createHardcodedCredentialsRule(config){const connectionKeys=[...DEFAULT_CONNECTION_KEYS,...config.connectionKeys??[]];const isConfigShape=(0,connection_config_1.configShapeEvidence)(config.configShapes??[]);const usesModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules,extraEvidence:isConfigShape});const importsModule=(0,module_evidence_1.createModuleEvidence)({packages:config.modules});const withinConfigShape=node=>{for(let at=node;at;at=at.parent){if(at.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression&&isConfigShape?.(at))return true}return false};const originOf=(0,driver_origin_1.createOriginClassifier)(config.modules);return{meta:{type:config.meta.type,docs:{...config.meta.docs},messages:{hardcodedPassword:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Hardcoded Credentials",description:"A database password is written as a literal. It is in git history, every fork, and the built image \u2014 rotating it means rewriting history, so it never gets rotated.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A07:2021",compliance:["SOC2","PCI-DSS","ISO27001","NIST-CSF"],effort:"low",fix:config.fix,documentationLink:config.documentationLink}),credentialsInUrl:(0,messaging_1.formatLLMMessage)({icon:messaging_1.MessageIcons.SECURITY,issueName:"Hardcoded Credentials",description:"A connection URL embeds a password in its userinfo section, so the secret is committed with the string.",severity:"CRITICAL",cwe:config.meta.docs.cwe,owasp:"A07:2021",compliance:["SOC2","PCI-DSS","ISO27001","NIST-CSF"],effort:"low",fix:config.urlFix,documentationLink:config.documentationLink})},schema:[]},defaultOptions:[],create(context){if((0,rule_creator_1.isTestFilePath)(context.filename))return{};const env=(0,value_follow_1.envOf)(context);let ownsFile=false;let ownsShapeOnly=false;const reported=new WeakSet;const scanned=new WeakSet;const report=(node,messageId)=>{if(reported.has(node))return;reported.add(node);context.report({node,messageId})};const reportSecrets=node=>{for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(node,env))){if(!isLiteralSecret(value.node))continue;report(value.env===env&&(0,require_tls_rule_1.within)(value.node,node)?value.node:node,"hardcodedPassword")}};const reportUrl=node=>{for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(node,env))){const url=urlPrefix(value.node);if(url===void 0||!urlEmbedsCredentials(url,config.urlSchemes))continue;report(value.env===env&&(0,require_tls_rule_1.within)(value.node,node)?value.node:node,"credentialsInUrl");return true}return false};const scanConfig=obj=>{if(scanned.has(obj))return;scanned.add(obj);for(const prop of obj.properties){if(prop.type!==ast_node_types_1.AST_NODE_TYPES.Property)continue;const name=(0,unscoped_mutation_rule_1.propertyKeyName)(prop);if(name===void 0)continue;if(CREDENTIAL_KEYS.includes(name.toLowerCase())){reportSecrets(prop.value);continue}if(reportUrl(prop.value))continue;if(connectionKeys.includes(name)){for(const value of(0,connection_config_1.possibleValues)((0,value_follow_1.valueAt)(prop.value,env))){if(value.env===env&&value.node.type===ast_node_types_1.AST_NODE_TYPES.ObjectExpression){scanConfig(value.node)}}}}};return{Program(program){ownsFile=usesModule(program);ownsShapeOnly=ownsFile&&!importsModule(program)},ObjectExpression(node){if(!ownsFile)return;if(ownsShapeOnly&&!withinConfigShape(node))return;if(!(0,require_tls_rule_1.looksLikeConnectionConfig)(node,connectionKeys))return;if((0,connection_config_1.passedToForeign)(node,originOf,env))return;scanConfig(node)},"CallExpression, NewExpression"(node){if(!ownsFile)return;if(originOf((0,value_follow_1.valueAt)(node.callee,env))!=="ours")return;for(const argument of node.arguments){if(argument.type!==ast_node_types_1.AST_NODE_TYPES.SpreadElement)reportUrl(argument)}const index=config.positionalPassword;if(index!==void 0&&node.type===ast_node_types_1.AST_NODE_TYPES.NewExpression&&node.arguments.length>index){reportSecrets(node.arguments[index])}},"Literal, TemplateLiteral"(node){if(!ownsFile)return;const value=urlPrefix(node);if(value===void 0)return;if(!urlEmbedsCredentials(value,config.urlSchemes))return;if(!(0,require_tls_rule_1.inConnectionPosition)(node,connectionKeys,callee=>originOf((0,value_follow_1.valueAt)(callee,env))==="ours")){return}report(node,"credentialsInUrl")}}}}}function urlPrefix(node){const value=staticStringValue(node);if(value!==void 0)return value;if(node.type!==ast_node_types_1.AST_NODE_TYPES.TemplateLiteral)return void 0;const[head]=node.quasis;return head.value.raw}
|