eslint-plugin-browser-security 2.1.1 → 2.1.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.
Files changed (35) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -1
  3. package/src/rules/no-clickjacking/index.js +1 -1
  4. package/src/rules/no-client-side-auth-logic/index.js +1 -1
  5. package/src/rules/no-disabled-certificate-validation/index.js +1 -1
  6. package/src/rules/no-dynamic-service-worker-url/index.js +1 -1
  7. package/src/rules/no-filereader-innerhtml/index.js +1 -1
  8. package/src/rules/no-incomplete-url-sanitization/index.js +1 -1
  9. package/src/rules/no-insecure-redirects/index.js +1 -1
  10. package/src/rules/no-missing-cors-check/index.js +1 -1
  11. package/src/rules/no-missing-csrf-protection/index.js +1 -1
  12. package/src/rules/no-missing-security-headers/index.js +1 -1
  13. package/src/rules/no-permissive-cors/index.js +1 -1
  14. package/src/rules/no-postmessage-innerhtml/index.js +1 -1
  15. package/src/rules/no-postmessage-wildcard-origin/index.js +1 -1
  16. package/src/rules/no-unencrypted-transmission/index.js +1 -1
  17. package/src/rules/no-unescaped-url-parameter/index.js +1 -1
  18. package/src/rules/no-unescaped-url-parameter/untrusted-text.js +1 -1
  19. package/src/rules/no-unvalidated-deeplinks/index.js +1 -1
  20. package/src/rules/no-websocket-innerhtml/index.js +1 -1
  21. package/src/rules/no-worker-message-innerhtml/index.js +1 -1
  22. package/src/rules/require-blob-url-revocation/index.js +1 -1
  23. package/src/rules/require-csp-headers/index.js +1 -1
  24. package/src/rules/require-mime-type-validation/index.js +1 -1
  25. package/src/rules/require-postmessage-origin-check/index.js +1 -1
  26. package/src/rules/require-url-validation/index.js +1 -1
  27. package/src/utils/analytics-sinks.js +1 -1
  28. package/src/utils/dynamic-code-sinks.js +1 -1
  29. package/src/utils/express-app.js +1 -1
  30. package/src/utils/global-object.js +1 -1
  31. package/src/utils/navigation-targets.js +1 -1
  32. package/src/utils/protocol-inspection.js +1 -1
  33. package/src/utils/sensitive-value-evidence.js +1 -1
  34. package/src/utils/transport-ownership.js +1 -1
  35. package/src/utils/url-taint.js +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnescapedUrlParameter=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const untrusted_text_1=require("./untrusted-text");const url_shape_1=require("./url-shape");const DEFAULT_TRUSTED_LIBRARIES=["url","querystring"];const URL_SINK_FUNCTIONS=new Set(["fetch"]);const URL_SINK_CONSTRUCTORS=new Set(["URL","Request"]);const XHR_OPEN_URL_INDEX=1;const URL_ATTRIBUTES=new Set(["href","src","action","formAction","poster"]);const HTTP_CLIENT_MODULES=new Set(["axios","ky"]);exports.noUnescapedUrlParameter=(0,eslint_devkit_1.createRule)({name:"no-unescaped-url-parameter",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unescaped-url-parameter.md",description:"Detects unescaped URL parameters",cwe:"CWE-79",cvss:6.1},messages:{unescapedUrlParameter:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unescaped URL Parameter",cwe:"CWE-79",description:"Unescaped URL parameter detected: {{parameter}}",severity:"HIGH",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/79.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow unescaped URL parameters in test files"},trustedLibraries:{type:"array",items:{type:"string"},default:["url","querystring"],description:"Modules whose exports produce already-encoded URL text"},ignorePatterns:{type:"array",items:{type:"string"},default:[],description:"Additional safe patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,trustedLibraries:["url","querystring"],ignorePatterns:[]}],create(context,[options={}]){const{allowInTests=false,trustedLibraries=DEFAULT_TRUSTED_LIBRARIES,ignorePatterns=[]}=options;const isTestFile=allowInTests&&(0,eslint_devkit_1.isTestFilePath)(context.filename);if(isTestFile)return{};const sourceCode=context.sourceCode;const trusted=new Set(trustedLibraries);const ignoreRegexes=(0,eslint_devkit_1.compileUserPatterns)(ignorePatterns,"i");function isTrustedLibraryCall(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));if(binding===void 0)return false;const module=binding.module.replace(/^node:/,"");return trusted.has(module)}function isHttpClientCall(node){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&HTTP_CLIENT_MODULES.has(binding.module)}function isUnshadowedGlobal(node,names){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!names.has(node.name)){return false}for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function isUrlSinkPosition(node){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer){const attribute=parent.parent;return attribute?.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&attribute.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier&&URL_ATTRIBUTES.has(attribute.name.name)}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression){return parent.arguments[0]===node&&isUnshadowedGlobal(parent.callee,URL_SINK_CONSTRUCTORS)}if(parent?.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;if(parent.arguments[0]===node&&isUnshadowedGlobal(parent.callee,URL_SINK_FUNCTIONS)){return true}if(parent.arguments[0]===node&&isHttpClientCall(parent))return true;return parent.arguments[XHR_OPEN_URL_INDEX]===node&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!parent.callee.computed&&parent.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.callee.property.name==="open"}function reachesUrlSink(node){if(isUrlSinkPosition(node))return true;const declarator=node.parent;if(declarator?.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator||declarator.init!==node||declarator.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){return false}return sourceCode.getDeclaredVariables(declarator).some(variable=>variable.references.filter(r=>r.isWrite()).length===1&&variable.references.some(reference=>!reference.isWrite()&&isUrlSinkPosition(reference.identifier)))}function isInnerConcatenation(node){const parent=node.parent;return parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&parent.operator==="+"}function check(node){const shape=(0,url_shape_1.urlShape)(node,sourceCode);const kind=(0,url_shape_1.urlKind)(shape.text);if(kind===null)return;if(kind==="relative"&&!reachesUrlSink(node))return;for(const hole of shape.holes){if(!(0,url_shape_1.isEncodingPosition)(shape,hole))continue;if(isTrustedLibraryCall(hole.expression))continue;const text=sourceCode.getText(hole.expression);if(ignoreRegexes.some(regex=>regex.test(text)))continue;if(!(0,untrusted_text_1.carriesUntrustedText)(hole.expression,sourceCode))continue;context.report({node:hole.expression,messageId:"unescapedUrlParameter",data:{parameter:text,safeAlternative:`Wrap it: encodeURIComponent(${text}) \u2014 or build the query with URLSearchParams.`}})}}return{TemplateLiteral(node){if(isInnerConcatenation(node))return;const parent=node.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.TaggedTemplateExpression){return}check(node)},BinaryExpression(node){if(node.operator!=="+")return;if(isInnerConcatenation(node))return;check(node)}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnescapedUrlParameter=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const untrusted_text_1=require("./untrusted-text");const url_shape_1=require("./url-shape");const DEFAULT_TRUSTED_LIBRARIES=["url","querystring"];const URL_SINK_FUNCTIONS=new Set(["fetch"]);const URL_SINK_CONSTRUCTORS=new Set(["URL","Request"]);const XHR_OPEN_URL_INDEX=1;const URL_ATTRIBUTES=new Set(["href","src","action","formAction","poster"]);const HTTP_CLIENT_MODULES=new Set(["axios","ky"]);exports.noUnescapedUrlParameter=(0,eslint_devkit_1.createRule)({name:"no-unescaped-url-parameter",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unescaped-url-parameter.md",description:"Detects unescaped URL parameters",cwe:"CWE-79",cvss:6.1},messages:{unescapedUrlParameter:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unescaped URL Parameter",cwe:"CWE-79",description:"Unescaped URL parameter detected: {{parameter}}",severity:"HIGH",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/79.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow unescaped URL parameters in test files"},trustedLibraries:{type:"array",items:{type:"string"},default:["url","querystring"],description:"Modules whose exports produce already-encoded URL text"},ignorePatterns:{type:"array",items:{type:"string"},default:[],description:"Additional safe patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,trustedLibraries:["url","querystring"],ignorePatterns:[]}],create(context,[options={}]){const{allowInTests=false,trustedLibraries=DEFAULT_TRUSTED_LIBRARIES,ignorePatterns=[]}=options;const isTestFile=allowInTests&&(0,eslint_devkit_1.isTestFilePath)(context.filename);if(isTestFile)return{};const sourceCode=context.sourceCode;const trusted=new Set(trustedLibraries);const ignoreRegexes=(0,eslint_devkit_1.compileUserPatterns)(ignorePatterns,"i");function isTrustedLibraryCall(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));if(binding===void 0)return false;const module=binding.module.replace(/^node:/,"");return trusted.has(module)}function isHttpClientCall(node){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&HTTP_CLIENT_MODULES.has(binding.module)}function isUnshadowedGlobal(node,names){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!names.has(node.name)){return false}for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function isUrlSinkPosition(node){const parent=node.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer){const attribute=parent.parent;return attribute?.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&attribute.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier&&URL_ATTRIBUTES.has(attribute.name.name)}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression){return parent.arguments[0]===node&&isUnshadowedGlobal(parent.callee,URL_SINK_CONSTRUCTORS)}if(parent?.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;if(parent.arguments[0]===node&&isUnshadowedGlobal(parent.callee,URL_SINK_FUNCTIONS)){return true}if(parent.arguments[0]===node&&isHttpClientCall(parent))return true;return parent.arguments[XHR_OPEN_URL_INDEX]===node&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(parent.callee)==="open"}function reachesUrlSink(node){if(isUrlSinkPosition(node))return true;const declarator=node.parent;if(declarator?.type!==eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator||declarator.init!==node||declarator.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){return false}return sourceCode.getDeclaredVariables(declarator).some(variable=>variable.references.filter(r=>r.isWrite()).length===1&&variable.references.some(reference=>!reference.isWrite()&&isUrlSinkPosition(reference.identifier)))}function isInnerConcatenation(node){const parent=node.parent;return parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&parent.operator==="+"}function check(node){const shape=(0,url_shape_1.urlShape)(node,sourceCode);const kind=(0,url_shape_1.urlKind)(shape.text);if(kind===null)return;if(kind==="relative"&&!reachesUrlSink(node))return;for(const hole of shape.holes){if(!(0,url_shape_1.isEncodingPosition)(shape,hole))continue;if(isTrustedLibraryCall(hole.expression))continue;const text=sourceCode.getText(hole.expression);if(ignoreRegexes.some(regex=>regex.test(text)))continue;if(!(0,untrusted_text_1.carriesUntrustedText)(hole.expression,sourceCode))continue;context.report({node:hole.expression,messageId:"unescapedUrlParameter",data:{parameter:text,safeAlternative:`Wrap it: encodeURIComponent(${text}) \u2014 or build the query with URLSearchParams.`}})}}return{TemplateLiteral(node){if(isInnerConcatenation(node))return;const parent=node.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.TaggedTemplateExpression){return}check(node)},BinaryExpression(node){if(node.operator!=="+")return;if(isInnerConcatenation(node))return;check(node)}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.carriesUntrustedText=carriesUntrustedText;const eslint_devkit_1=require("@interlace/eslint-devkit");const url_taint_1=require("../../utils/url-taint");const TEXT_PRESERVING_METHODS=new Set([...url_taint_1.STEERABILITY_PRESERVING_METHODS,"join","concat","padStart","padEnd","repeat"]);const DOM_TEXT_PROPS=new Set(["value","textContent","innerText"]);const DOM_QUERY_METHODS=new Set(["getElementById","querySelector","querySelectorAll","getElementsByName","getElementsByClassName","getElementsByTagName","closest"]);const DOCUMENT_GLOBALS=new Set(["document"]);const REACT_MODULES=new Set(["react","preact/hooks"]);const EVENT_TARGET_PROPS=new Set(["target","currentTarget"]);function staticProperty(node){if(!node.computed){return node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.property.name:null}return node.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.property.value==="string"?node.property.value:null}function isUnshadowedGlobal(node,names,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!names.has(node.name)){return false}for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function parameterDefinition(node,sourceCode){for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;const def=variable.defs[0];if(def===void 0||def.type!=="Parameter")return null;return{owner:def.node,parameter:def.name}}return null}function isHandlerFunction(fn){const parent=fn.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!parent.callee.computed&&parent.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&parent.callee.property.name==="addEventListener"){return true}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer){return parent.parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute}return parent?.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===fn&&parent.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression}function isReactRef(node,sourceCode,seen){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&REACT_MODULES.has(binding.module)}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isReactRef(init,sourceCode,seen)}function isDomElement(node,sourceCode,seen){switch(node.type){case eslint_devkit_1.AST_NODE_TYPES.CallExpression:{const callee=node.callee;if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;const method=staticProperty(callee);if(method===null||!DOM_QUERY_METHODS.has(method))return false;return isUnshadowedGlobal(callee.object,DOCUMENT_GLOBALS,sourceCode)||isDomElement(callee.object,sourceCode,seen)}case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:{if(node.computed&&node.property.type!==eslint_devkit_1.AST_NODE_TYPES.Literal){return isDomElement(node.object,sourceCode,seen)}const property=staticProperty(node);if(property===null)return isDomElement(node.object,sourceCode,seen);if(property==="current"){return isReactRef(node.object,sourceCode,seen)}if(!EVENT_TARGET_PROPS.has(property))return false;if(node.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const definition=parameterDefinition(node.object,sourceCode);return definition!==null&&isHandlerFunction(definition.owner)}case eslint_devkit_1.AST_NODE_TYPES.Identifier:{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isDomElement(init,sourceCode,seen)}default:return false}}const FORM_DATA_CONSTRUCTORS=new Set(["FormData"]);const FORM_DATA_READERS=new Set(["get","getAll"]);function isFormData(node,sourceCode,seen){if(node.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression){return isUnshadowedGlobal(node.callee,FORM_DATA_CONSTRUCTORS,sourceCode)}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isFormData(init,sourceCode,seen)}function isFormDataRead(node,sourceCode,seen){const callee=node.callee;return callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&FORM_DATA_READERS.has(callee.property.name)&&isFormData(callee.object,sourceCode,new Set(seen))}function isExportedDeclaration(node){const parent=node.parent;return parent?.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration||parent?.type===eslint_devkit_1.AST_NODE_TYPES.ExportDefaultDeclaration}function isExportedFunction(fn){if(isExportedDeclaration(fn))return true;const parent=fn.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.init===fn){return isExportedDeclaration(parent.parent)}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MethodDefinition||parent?.type===eslint_devkit_1.AST_NODE_TYPES.PropertyDefinition){return isExportedDeclaration(parent.parent.parent)}return false}function isUnknowableParameter(node,sourceCode){const definition=parameterDefinition(node,sourceCode);if(definition===null||!isExportedFunction(definition.owner)){return false}return!hasClosedType(definition.parameter.typeAnnotation?.typeAnnotation)}function hasClosedType(annotation){if(annotation===void 0)return false;switch(annotation.type){case eslint_devkit_1.AST_NODE_TYPES.TSLiteralType:return annotation.literal.type===eslint_devkit_1.AST_NODE_TYPES.Literal;case eslint_devkit_1.AST_NODE_TYPES.TSNumberKeyword:case eslint_devkit_1.AST_NODE_TYPES.TSBooleanKeyword:case eslint_devkit_1.AST_NODE_TYPES.TSBigIntKeyword:return true;case eslint_devkit_1.AST_NODE_TYPES.TSUnionType:return annotation.types.every(hasClosedType);default:return false}}function isArithmetic(node){const isNumericLiteral=n=>n.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof n.value==="number";const isTextual=n=>(0,eslint_devkit_1.staticString)(n)!==null||n.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral;const left=node.left;return(isNumericLiteral(left)||isNumericLiteral(node.right))&&!isTextual(left)&&!isTextual(node.right)}function carriesUntrustedText(node,sourceCode,seen=new Set){switch(node.type){case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:{if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;const property=staticProperty(node);return property!==null&&DOM_TEXT_PROPS.has(property)&&isDomElement(node.object,sourceCode,new Set(seen))}case eslint_devkit_1.AST_NODE_TYPES.CallExpression:{if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;if(isFormDataRead(node,sourceCode,seen))return true;const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&TEXT_PRESERVING_METHODS.has(callee.property.name)){return carriesUntrustedText(callee.object,sourceCode,seen)}const[first]=node.arguments;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&url_taint_1.STEERABILITY_PRESERVING_FUNCTIONS.has(callee.name)&&first!==void 0&&first.type!==eslint_devkit_1.AST_NODE_TYPES.SpreadElement){return carriesUntrustedText(first,sourceCode,seen)}return false}case eslint_devkit_1.AST_NODE_TYPES.Identifier:{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);if(init!==void 0){return carriesUntrustedText(init,sourceCode,seen)}return isUnknowableParameter(node,sourceCode)}case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:return node.operator==="+"&&!isArithmetic(node)&&(carriesUntrustedText(node.left,sourceCode,seen)||carriesUntrustedText(node.right,sourceCode,seen));case eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral:return node.expressions.some(expression=>carriesUntrustedText(expression,sourceCode,seen));case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:return carriesUntrustedText(node.left,sourceCode,seen)||carriesUntrustedText(node.right,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:return carriesUntrustedText(node.consequent,sourceCode,seen)||carriesUntrustedText(node.alternate,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.TSAsExpression:case eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression:case eslint_devkit_1.AST_NODE_TYPES.TSSatisfiesExpression:return carriesUntrustedText(node.expression,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.ChainExpression:return carriesUntrustedText(node.expression,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.AwaitExpression:return carriesUntrustedText(node.argument,sourceCode,seen);default:return false}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.carriesUntrustedText=carriesUntrustedText;const eslint_devkit_1=require("@interlace/eslint-devkit");const url_taint_1=require("../../utils/url-taint");const TEXT_PRESERVING_METHODS=new Set([...url_taint_1.STEERABILITY_PRESERVING_METHODS,"join","concat","padStart","padEnd","repeat"]);const DOM_TEXT_PROPS=new Set(["value","textContent","innerText"]);const DOM_QUERY_METHODS=new Set(["getElementById","querySelector","querySelectorAll","getElementsByName","getElementsByClassName","getElementsByTagName","closest"]);const DOCUMENT_GLOBALS=new Set(["document"]);const REACT_MODULES=new Set(["react","preact/hooks"]);const EVENT_TARGET_PROPS=new Set(["target","currentTarget"]);function staticProperty(node){if(!node.computed){return node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?node.property.name:null}return node.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.property.value==="string"?node.property.value:null}function isUnshadowedGlobal(node,names,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!names.has(node.name)){return false}for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function parameterDefinition(node,sourceCode){for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;const def=variable.defs[0];if(def===void 0||def.type!=="Parameter")return null;return{owner:def.node,parameter:def.name}}return null}function isHandlerFunction(fn){const parent=fn.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&staticProperty(parent.callee)==="addEventListener"){return true}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer){return parent.parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute}return parent?.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===fn&&parent.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression}function isReactRef(node,sourceCode,seen){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&REACT_MODULES.has(binding.module)}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isReactRef(init,sourceCode,seen)}function isDomElement(node,sourceCode,seen){switch(node.type){case eslint_devkit_1.AST_NODE_TYPES.CallExpression:{const callee=node.callee;if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;const method=staticProperty(callee);if(method===null||!DOM_QUERY_METHODS.has(method))return false;return isUnshadowedGlobal(callee.object,DOCUMENT_GLOBALS,sourceCode)||isDomElement(callee.object,sourceCode,seen)}case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:{if(node.computed&&node.property.type!==eslint_devkit_1.AST_NODE_TYPES.Literal){return isDomElement(node.object,sourceCode,seen)}const property=staticProperty(node);if(property===null)return isDomElement(node.object,sourceCode,seen);if(property==="current"){return isReactRef(node.object,sourceCode,seen)}if(!EVENT_TARGET_PROPS.has(property))return false;if(node.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const definition=parameterDefinition(node.object,sourceCode);return definition!==null&&isHandlerFunction(definition.owner)}case eslint_devkit_1.AST_NODE_TYPES.Identifier:{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isDomElement(init,sourceCode,seen)}default:return false}}const FORM_DATA_CONSTRUCTORS=new Set(["FormData"]);const FORM_DATA_READERS=new Set(["get","getAll"]);function isFormData(node,sourceCode,seen){if(node.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression){return isUnshadowedGlobal(node.callee,FORM_DATA_CONSTRUCTORS,sourceCode)}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);return init!==void 0&&isFormData(init,sourceCode,seen)}function isFormDataRead(node,sourceCode,seen){const callee=node.callee;return callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),FORM_DATA_READERS)&&isFormData(callee.object,sourceCode,new Set(seen))}function isExportedDeclaration(node){const parent=node.parent;return parent?.type===eslint_devkit_1.AST_NODE_TYPES.ExportNamedDeclaration||parent?.type===eslint_devkit_1.AST_NODE_TYPES.ExportDefaultDeclaration}function isExportedFunction(fn){if(isExportedDeclaration(fn))return true;const parent=fn.parent;if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.init===fn){return isExportedDeclaration(parent.parent)}if(parent?.type===eslint_devkit_1.AST_NODE_TYPES.MethodDefinition||parent?.type===eslint_devkit_1.AST_NODE_TYPES.PropertyDefinition){return isExportedDeclaration(parent.parent.parent)}return false}function isUnknowableParameter(node,sourceCode){const definition=parameterDefinition(node,sourceCode);if(definition===null||!isExportedFunction(definition.owner)){return false}return!hasClosedType(definition.parameter.typeAnnotation?.typeAnnotation)}function hasClosedType(annotation){if(annotation===void 0)return false;switch(annotation.type){case eslint_devkit_1.AST_NODE_TYPES.TSLiteralType:return annotation.literal.type===eslint_devkit_1.AST_NODE_TYPES.Literal;case eslint_devkit_1.AST_NODE_TYPES.TSNumberKeyword:case eslint_devkit_1.AST_NODE_TYPES.TSBooleanKeyword:case eslint_devkit_1.AST_NODE_TYPES.TSBigIntKeyword:return true;case eslint_devkit_1.AST_NODE_TYPES.TSUnionType:return annotation.types.every(hasClosedType);default:return false}}function isArithmetic(node){const isNumericLiteral=n=>n.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof n.value==="number";const isTextual=n=>(0,eslint_devkit_1.staticString)(n)!==null||n.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral;const left=node.left;return(isNumericLiteral(left)||isNumericLiteral(node.right))&&!isTextual(left)&&!isTextual(node.right)}function carriesUntrustedText(node,sourceCode,seen=new Set){switch(node.type){case eslint_devkit_1.AST_NODE_TYPES.MemberExpression:{if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;const property=staticProperty(node);return property!==null&&DOM_TEXT_PROPS.has(property)&&isDomElement(node.object,sourceCode,new Set(seen))}case eslint_devkit_1.AST_NODE_TYPES.CallExpression:{if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;if(isFormDataRead(node,sourceCode,seen))return true;const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),TEXT_PRESERVING_METHODS)){return carriesUntrustedText(callee.object,sourceCode,seen)}const[first]=node.arguments;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&url_taint_1.STEERABILITY_PRESERVING_FUNCTIONS.has(callee.name)&&first!==void 0&&first.type!==eslint_devkit_1.AST_NODE_TYPES.SpreadElement){return carriesUntrustedText(first,sourceCode,seen)}return false}case eslint_devkit_1.AST_NODE_TYPES.Identifier:{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,url_taint_1.resolveBoundInitializer)(node,sourceCode);if(init!==void 0){return carriesUntrustedText(init,sourceCode,seen)}return isUnknowableParameter(node,sourceCode)}case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:return node.operator==="+"&&!isArithmetic(node)&&(carriesUntrustedText(node.left,sourceCode,seen)||carriesUntrustedText(node.right,sourceCode,seen));case eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral:return node.expressions.some(expression=>carriesUntrustedText(expression,sourceCode,seen));case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:return carriesUntrustedText(node.left,sourceCode,seen)||carriesUntrustedText(node.right,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:return carriesUntrustedText(node.consequent,sourceCode,seen)||carriesUntrustedText(node.alternate,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.TSAsExpression:case eslint_devkit_1.AST_NODE_TYPES.TSNonNullExpression:case eslint_devkit_1.AST_NODE_TYPES.TSSatisfiesExpression:return carriesUntrustedText(node.expression,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.ChainExpression:return carriesUntrustedText(node.expression,sourceCode,seen);case eslint_devkit_1.AST_NODE_TYPES.AwaitExpression:return carriesUntrustedText(node.argument,sourceCode,seen);default:return false}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedDeeplinks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const navigation_targets_1=require("../../utils/navigation-targets");const resolve_binding_1=require("../../utils/resolve-binding");function memberPath(node,sourceCode,depth=0){if(depth>4)return null;const parts=[];let current=node;while(current.type==="MemberExpression"){if(!current.computed&&current.property.type==="Identifier"){parts.unshift(current.property.name)}current=current.object}if(current.type!=="Identifier")return null;const init=(0,resolve_binding_1.resolveInitializer)(current,sourceCode);if(init!==void 0){const base=memberPath(init,sourceCode,depth+1);if(base!==null)return[...base,...parts]}parts.unshift(current.name);return parts}function isRouteParam(node,sourceCode){const path=memberPath(node,sourceCode);if(path===null)return false;for(let i=0;i+2<path.length;i+=1){if((path[i]==="route"||path[i]==="routes")&&path[i+1]==="params"){return true}}return false}function isLinkingCall(node,method){return node.type==="CallExpression"&&node.callee.type==="MemberExpression"&&!node.callee.computed&&node.callee.object.type==="Identifier"&&node.callee.object.name==="Linking"&&node.callee.property.type==="Identifier"&&node.callee.property.name===method}function deepLinkParamKind(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable===void 0)continue;if(variable.defs.length!==1)return null;const def=variable.defs[0];if(def.type!=="Parameter")return null;const fn=def.node;const call=fn.parent;if(call===void 0||call.type!=="CallExpression")return null;if(isLinkingCall(call,"addEventListener")&&call.arguments[0]?.type==="Literal"&&call.arguments[0].value==="url"){return"event"}if(call.callee.type==="MemberExpression"&&!call.callee.computed&&call.callee.property.type==="Identifier"&&call.callee.property.name==="then"&&isLinkingCall(call.callee.object,"getInitialURL")){return"url"}return null}return null}function isDeepLinkSteerable(node,sourceCode){if(node.type==="ChainExpression"){return isDeepLinkSteerable(node.expression,sourceCode)}if((0,navigation_targets_1.isSteerableUrlValue)(node,sourceCode))return true;if(isRouteParam(node,sourceCode))return true;if(node.type==="CallExpression"){const index=(0,navigation_targets_1.identityArgumentIndex)(node,sourceCode);if(index!==null){const argument=node.arguments[index];return argument!==void 0&&argument.type!=="SpreadElement"&&isDeepLinkSteerable(argument,sourceCode)}}if(node.type==="AwaitExpression"){return isLinkingCall(node.argument,"getInitialURL")}if(node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"&&node.property.name==="url"&&node.object.type==="Identifier"){return deepLinkParamKind(node.object,sourceCode)==="event"}if(node.type==="Identifier"){if(deepLinkParamKind(node,sourceCode)==="url")return true;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isDeepLinkSteerable(init,sourceCode)}return false}exports.noUnvalidatedDeeplinks=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-deeplinks",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unvalidated-deeplinks.md",description:"Require validation of deep link URLs",cwe:"CWE-939",cvss:6.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Deeplink",cwe:"CWE-939",description:"Deep link URL used without validation - potential open redirect",severity:"HIGH",fix:"Validate deep link URLs against a whitelist before navigation",documentationLink:"https://cwe.mitre.org/data/definitions/939.html"})},schema:[]},defaultOptions:[],create(context){const{sourceCode}=context;function report(node){context.report({node,messageId:"violationDetected"})}return{CallExpression(node){if(isLinkingCall(node,"openURL")){const urlArg=node.arguments[0];if(urlArg&&isDeepLinkSteerable(urlArg,sourceCode)){report(node)}}if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="navigate"){const urlArg=node.arguments[0];if(urlArg&&(0,navigation_targets_1.isSteerableUrlValue)(urlArg,context.sourceCode)){report(node)}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedDeeplinks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const navigation_targets_1=require("../../utils/navigation-targets");const resolve_binding_1=require("../../utils/resolve-binding");function memberPath(node,sourceCode,depth=0){if(depth>4)return null;const parts=[];let current=node;while(current.type==="MemberExpression"){const link=(0,eslint_devkit_1.propertyName)(current);if(link!==null){parts.unshift(link)}current=current.object}if(current.type!=="Identifier")return null;const init=(0,resolve_binding_1.resolveInitializer)(current,sourceCode);if(init!==void 0){const base=memberPath(init,sourceCode,depth+1);if(base!==null)return[...base,...parts]}parts.unshift(current.name);return parts}function isRouteParam(node,sourceCode){const path=memberPath(node,sourceCode);if(path===null)return false;for(let i=0;i+2<path.length;i+=1){if((path[i]==="route"||path[i]==="routes")&&path[i+1]==="params"){return true}}return false}function isLinkingCall(node,method){return node.type==="CallExpression"&&node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&node.callee.object.name==="Linking"&&(0,eslint_devkit_1.propertyName)(node.callee)===method}function deepLinkParamKind(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable===void 0)continue;if(variable.defs.length!==1)return null;const def=variable.defs[0];if(def.type!=="Parameter")return null;const fn=def.node;const call=fn.parent;if(call===void 0||call.type!=="CallExpression")return null;if(isLinkingCall(call,"addEventListener")&&call.arguments[0]?.type==="Literal"&&call.arguments[0].value==="url"){return"event"}if(call.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(call.callee)==="then"&&isLinkingCall(call.callee.object,"getInitialURL")){return"url"}return null}return null}function isDeepLinkSteerable(node,sourceCode){if(node.type==="ChainExpression"){return isDeepLinkSteerable(node.expression,sourceCode)}if((0,navigation_targets_1.isSteerableUrlValue)(node,sourceCode))return true;if(isRouteParam(node,sourceCode))return true;if(node.type==="CallExpression"){const index=(0,navigation_targets_1.identityArgumentIndex)(node,sourceCode);if(index!==null){const argument=node.arguments[index];return argument!==void 0&&argument.type!=="SpreadElement"&&isDeepLinkSteerable(argument,sourceCode)}}if(node.type==="AwaitExpression"){return isLinkingCall(node.argument,"getInitialURL")}if(node.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node)==="url"&&node.object.type==="Identifier"){return deepLinkParamKind(node.object,sourceCode)==="event"}if(node.type==="Identifier"){if(deepLinkParamKind(node,sourceCode)==="url")return true;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isDeepLinkSteerable(init,sourceCode)}return false}exports.noUnvalidatedDeeplinks=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-deeplinks",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unvalidated-deeplinks.md",description:"Require validation of deep link URLs",cwe:"CWE-939",cvss:6.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Deeplink",cwe:"CWE-939",description:"Deep link URL used without validation - potential open redirect",severity:"HIGH",fix:"Validate deep link URLs against a whitelist before navigation",documentationLink:"https://cwe.mitre.org/data/definitions/939.html"})},schema:[]},defaultOptions:[],create(context){const{sourceCode}=context;function report(node){context.report({node,messageId:"violationDetected"})}return{CallExpression(node){if(isLinkingCall(node,"openURL")){const urlArg=node.arguments[0];if(urlArg&&isDeepLinkSteerable(urlArg,sourceCode)){report(node)}}if(node.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node.callee)==="navigate"){const urlArg=node.arguments[0];if(urlArg&&(0,navigation_targets_1.isSteerableUrlValue)(urlArg,context.sourceCode)){report(node)}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWebsocketInnerhtml=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_PROPERTIES=new Set(["innerHTML","outerHTML"]);const DANGEROUS_METHODS=new Set(["insertAdjacentHTML","write","writeln"]);exports.noWebsocketInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-websocket-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-websocket-innerhtml.md",description:"Disallow using innerHTML or similar methods with WebSocket message data",cwe:"CWE-79",cvss:8.1},messages:{unsafeInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via WebSocket",cwe:"CWE-79",owasp:"A03:2021",cvss:8.1,description:"Using {{method}} with WebSocket data enables XSS attacks. Malicious server or MITM can send crafted HTML to execute scripts.",severity:"HIGH",fix:"Use textContent for plain text, or sanitize with DOMPurify before using innerHTML.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/WebSocket"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_PROPERTIES.has(node.left.property.name)){if(payloadSource(node.right)==="websocket"){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.left.property.name}})}}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_METHODS.has(node.callee.property.name)){for(const arg of node.arguments){if(payloadSource(arg)==="websocket"){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.callee.property.name}});break}}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWebsocketInnerhtml=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_PROPERTIES=new Set(["innerHTML","outerHTML"]);const DANGEROUS_METHODS=new Set(["insertAdjacentHTML","write","writeln"]);exports.noWebsocketInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-websocket-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-websocket-innerhtml.md",description:"Disallow using innerHTML or similar methods with WebSocket message data",cwe:"CWE-79",cvss:8.1},messages:{unsafeInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via WebSocket",cwe:"CWE-79",owasp:"A03:2021",cvss:8.1,description:"Using {{method}} with WebSocket data enables XSS attacks. Malicious server or MITM can send crafted HTML to execute scripts.",severity:"HIGH",fix:"Use textContent for plain text, or sanitize with DOMPurify before using innerHTML.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/WebSocket"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.left),DANGEROUS_PROPERTIES)){if(payloadSource(node.right)==="websocket"){context.report({node,messageId:"unsafeInnerhtml",data:{method:(0,eslint_devkit_1.propertyName)(node.left)}})}}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),DANGEROUS_METHODS)){for(const arg of node.arguments){if(payloadSource(arg)==="websocket"){context.report({node,messageId:"unsafeInnerhtml",data:{method:(0,eslint_devkit_1.propertyName)(node.callee)}});break}}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWorkerMessageInnerhtml=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_PROPERTIES=new Set(["innerHTML","outerHTML"]);const DANGEROUS_METHODS=new Set(["insertAdjacentHTML","write","writeln"]);exports.noWorkerMessageInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-worker-message-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-worker-message-innerhtml.md",description:"Disallow using innerHTML with Web Worker message data",cwe:"CWE-79",cvss:7.5},messages:{workerInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via Worker Message",cwe:"CWE-79",owasp:"A03:2021",cvss:7.5,description:"Using {{method}} with Worker message data can enable XSS if the worker processes untrusted input.",severity:"HIGH",fix:"Sanitize worker data with DOMPurify before rendering, or use textContent.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Worker/message_event"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_PROPERTIES.has(node.left.property.name)){if(payloadSource(node.right)==="worker"){context.report({node,messageId:"workerInnerhtml",data:{method:node.left.property.name}})}}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_METHODS.has(node.callee.property.name)){for(const arg of node.arguments){if(payloadSource(arg)==="worker"){context.report({node,messageId:"workerInnerhtml",data:{method:node.callee.property.name}});break}}}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noWorkerMessageInnerhtml=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_PROPERTIES=new Set(["innerHTML","outerHTML"]);const DANGEROUS_METHODS=new Set(["insertAdjacentHTML","write","writeln"]);exports.noWorkerMessageInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-worker-message-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-worker-message-innerhtml.md",description:"Disallow using innerHTML with Web Worker message data",cwe:"CWE-79",cvss:7.5},messages:{workerInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via Worker Message",cwe:"CWE-79",owasp:"A03:2021",cvss:7.5,description:"Using {{method}} with Worker message data can enable XSS if the worker processes untrusted input.",severity:"HIGH",fix:"Sanitize worker data with DOMPurify before rendering, or use textContent.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Worker/message_event"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.left),DANGEROUS_PROPERTIES)){if(payloadSource(node.right)==="worker"){context.report({node,messageId:"workerInnerhtml",data:{method:(0,eslint_devkit_1.propertyName)(node.left)}})}}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node.callee),DANGEROUS_METHODS)){for(const arg of node.arguments){if(payloadSource(arg)==="worker"){context.report({node,messageId:"workerInnerhtml",data:{method:(0,eslint_devkit_1.propertyName)(node.callee)}});break}}}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireBlobUrlRevocation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("../../utils/global-object");const URL_GLOBAL=new Set(["URL"]);function isUrlMethod(node,method){const callee=node.callee;return callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.property.name===method&&(0,global_object_1.resolveGlobalObject)(callee.object,URL_GLOBAL)!==null}function pathKey(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return node.name;if(node.type===eslint_devkit_1.AST_NODE_TYPES.ThisExpression)return"this";if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const base=pathKey(node.object);return base===null?null:`${base}.${node.property.name}`}return null}function ownerOf(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const found=scope.variables.find(v=>v.name===identifier.name);if(found!==void 0)return found}return identifier.name}function escapes(node){const parent=node.parent;return parent.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement||parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.Property||parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression}exports.requireBlobUrlRevocation=(0,eslint_devkit_1.createRule)({name:"require-blob-url-revocation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-blob-url-revocation.md",description:"Require revoking Blob URLs to prevent memory leaks",cwe:"CWE-401",cvss:5.3},messages:{missingRevoke:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Blob URL Memory Leak",cwe:"CWE-401",owasp:"A06:2021",cvss:5.3,description:"URL.createObjectURL() creates a reference that persists until explicitly revoked. Without revokeObjectURL(), memory leaks occur.",severity:"MEDIUM",fix:"Call URL.revokeObjectURL(blobUrl) when the URL is no longer needed.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const sourceCode=context.sourceCode;const byOwner=new Map;const byPath=new Map;const unreachable=[];const revokedOwners=new Set;const revokedPaths=new Set;function trackCreation(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){byOwner.set(ownerOf(parent.id,sourceCode),parent);return}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression){if(parent.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){byOwner.set(ownerOf(parent.left,sourceCode),parent);return}const key=pathKey(parent.left);if(key!==null)byPath.set(key,parent);return}if(escapes(node))return;unreachable.push(node)}function trackRevocation(node){const arg=node.arguments[0];if(arg===void 0)return;if(arg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){revokedOwners.add(ownerOf(arg,sourceCode));return}const key=pathKey(arg);if(key!==null)revokedPaths.add(key)}return{CallExpression(node){if(isUrlMethod(node,"createObjectURL"))trackCreation(node);if(isUrlMethod(node,"revokeObjectURL"))trackRevocation(node)},"Program:exit"(){for(const[owner,site]of byOwner){if(!revokedOwners.has(owner)){context.report({node:site,messageId:"missingRevoke"})}}for(const[key,site]of byPath){if(!revokedPaths.has(key)){context.report({node:site,messageId:"missingRevoke"})}}for(const site of unreachable){context.report({node:site,messageId:"missingRevoke"})}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireBlobUrlRevocation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("../../utils/global-object");const URL_GLOBAL=new Set(["URL"]);function isUrlMethod(node,method){const callee=node.callee;return callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(callee)===method&&(0,global_object_1.resolveGlobalObject)(callee.object,URL_GLOBAL)!==null}function pathKey(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return node.name;if(node.type===eslint_devkit_1.AST_NODE_TYPES.ThisExpression)return"this";if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const base=pathKey(node.object);return base===null?null:`${base}.${node.property.name}`}return null}function ownerOf(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const found=scope.variables.find(v=>v.name===identifier.name);if(found!==void 0)return found}return identifier.name}function escapes(node){const parent=node.parent;return parent.type===eslint_devkit_1.AST_NODE_TYPES.ReturnStatement||parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression||parent.type===eslint_devkit_1.AST_NODE_TYPES.Property||parent.type===eslint_devkit_1.AST_NODE_TYPES.ArrayExpression}exports.requireBlobUrlRevocation=(0,eslint_devkit_1.createRule)({name:"require-blob-url-revocation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-blob-url-revocation.md",description:"Require revoking Blob URLs to prevent memory leaks",cwe:"CWE-401",cvss:5.3},messages:{missingRevoke:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Blob URL Memory Leak",cwe:"CWE-401",owasp:"A06:2021",cvss:5.3,description:"URL.createObjectURL() creates a reference that persists until explicitly revoked. Without revokeObjectURL(), memory leaks occur.",severity:"MEDIUM",fix:"Call URL.revokeObjectURL(blobUrl) when the URL is no longer needed.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=(0,eslint_devkit_1.isTestFilePath)(filename);if(allowInTests&&isTestFile){return{}}const sourceCode=context.sourceCode;const byOwner=new Map;const byPath=new Map;const unreachable=[];const revokedOwners=new Set;const revokedPaths=new Set;function trackCreation(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){byOwner.set(ownerOf(parent.id,sourceCode),parent);return}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression){if(parent.left.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){byOwner.set(ownerOf(parent.left,sourceCode),parent);return}const key=pathKey(parent.left);if(key!==null)byPath.set(key,parent);return}if(escapes(node))return;unreachable.push(node)}function trackRevocation(node){const arg=node.arguments[0];if(arg===void 0)return;if(arg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){revokedOwners.add(ownerOf(arg,sourceCode));return}const key=pathKey(arg);if(key!==null)revokedPaths.add(key)}return{CallExpression(node){if(isUrlMethod(node,"createObjectURL"))trackCreation(node);if(isUrlMethod(node,"revokeObjectURL"))trackRevocation(node)},"Program:exit"(){for(const[owner,site]of byOwner){if(!revokedOwners.has(owner)){context.report({node:site,messageId:"missingRevoke"})}}for(const[key,site]of byPath){if(!revokedPaths.has(key)){context.report({node:site,messageId:"missingRevoke"})}}for(const site of unreachable){context.report({node:site,messageId:"missingRevoke"})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireCspHeaders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const resolve_binding_1=require("../../utils/resolve-binding");const EMIT_METHODS=new Set(["send","end","write","render"]);const FILE_METHODS=new Set(["sendFile"]);const DOCUMENT_EXTENSIONS=new Set([".html",".htm"]);const HEADER_METHODS=new Set(["setHeader","writeHead","header","set"]);const CSP_HEADER="content-security-policy";const HELMET_MODULE=/^helmet(\/|$)/;function isNode(value){return typeof value==="object"&&value!==null&&typeof value.type==="string"}function staticString(node,sourceCode,depth){if(depth>5)return null;if(node.type==="Literal"){return typeof node.value==="string"?node.value:null}if(node.type==="TemplateLiteral"){return node.quasis.map(q=>q.value?.raw??"").join(" ")}if(node.type==="Identifier"){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:staticString(init,sourceCode,depth+1)}if(node.type==="MemberExpression"&&node.computed){const index=node.property;if(index.type!=="Literal"||typeof index.value!=="number")return null;const array=foldToArray(node.object,sourceCode,depth+1);const element=array?.elements[index.value];return element==null?null:staticString(element,sourceCode,depth+1)}if(node.type==="CallExpression"&&node.callee.type==="Identifier"){const fn=resolveLocalFunction(node.callee,sourceCode);if(fn===null)return null;return returnedString(fn,sourceCode,depth+1)}return null}function foldToArray(node,sourceCode,depth){if(depth>5)return null;if(node.type==="ArrayExpression")return node;if(node.type==="Identifier"){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:foldToArray(init,sourceCode,depth+1)}if(node.type==="MemberExpression"&&node.computed){const index=node.property;if(index.type!=="Literal"||typeof index.value!=="number")return null;const outer=foldToArray(node.object,sourceCode,depth+1);const element=outer?.elements[index.value];return element==null?null:foldToArray(element,sourceCode,depth+1)}return null}function resolveLocalFunction(callee,sourceCode){for(let scope=sourceCode.getScope(callee);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===callee.name);if(variable===void 0)continue;if(variable.defs.length!==1)return null;const def=variable.defs[0];if(def.type==="FunctionName")return def.node;if(def.type==="Variable"){const init=def.node.init;return init?.type==="ArrowFunctionExpression"||init?.type==="FunctionExpression"?init:null}return null}return null}function returnedString(fn,sourceCode,depth){if((fn.type==="ArrowFunctionExpression"||fn.type==="FunctionExpression"||fn.type==="FunctionDeclaration")&&fn.body.type!=="BlockStatement"){return staticString(fn.body,sourceCode,depth)}const parts=[];walk(fn,child=>{if(child.type!=="ReturnStatement"||child.argument===null)return;const value=staticString(child.argument,sourceCode,depth);if(value!==null)parts.push(value)});return parts.length>0?parts.join(" "):null}function walk(node,visit){visit(node);for(const key of Object.keys(node)){if(key==="parent")continue;const child=node[key];if(Array.isArray(child)){for(const item of child)if(isNode(item))walk(item,visit)}else if(isNode(child)){walk(child,visit)}}}function isHtmlDocument(text){const lower=text.toLowerCase();return lower.includes("<!doctype")||lower.includes("<html")}function mayHoldDocument(node,sourceCode){const folded=staticString(node,sourceCode,0);if(folded!==null&&isHtmlDocument(folded))return true;if(node.type!=="Identifier")return false;const variable=sourceCode.getScope(node).references.find(ref=>ref.identifier===node)?.resolved;if(variable==null)return false;for(const def of variable.defs){if(def.type!=="Variable"||def.node.init==null)continue;const value=staticString(def.node.init,sourceCode,0);if(value!==null&&isHtmlDocument(value))return true}for(const reference of variable.references){if(!reference.isWrite())continue;const written=reference.writeExpr;if(written==null)continue;const value=staticString(written,sourceCode,0);if(value!==null&&isHtmlDocument(value))return true}return false}function namesDocumentFile(node,sourceCode){const candidates=[];const direct=staticString(node,sourceCode,0);if(direct!==null)candidates.push(direct);if(node.type==="CallExpression"){for(const arg of node.arguments){const value=staticString(arg,sourceCode,0);if(value!==null)candidates.push(value)}}return candidates.some(candidate=>{const dot=candidate.lastIndexOf(".");return dot!==-1&&DOCUMENT_EXTENSIONS.has(candidate.slice(dot).toLowerCase())})}exports.requireCspHeaders=(0,eslint_devkit_1.createRule)({name:"require-csp-headers",skipTestFiles:true,meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-csp-headers.md",description:"Require Content Security Policy headers",cwe:"CWE-1021",cvss:6.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing CSP",cwe:"CWE-1021",description:"HTML response without Content-Security-Policy header",severity:"MEDIUM",fix:"Use helmet.contentSecurityPolicy() or set CSP header manually",documentationLink:"https://cwe.mitre.org/data/definitions/1021.html"})},schema:[{type:"object",properties:{responseReceivers:{type:"array",items:{type:"string"},default:["res","response","reply"],description:"Identifiers that name a response object, so `<name>.render(view)` emits a response rather than returning a string. Anything unlisted is treated as a template engine."}},additionalProperties:false}]},defaultOptions:[{responseReceivers:["res","response","reply"]}],create(context,[options]){const responseReceivers=new Set(options.responseReceivers.map(name=>name.toLowerCase()));function report(node){context.report({node,messageId:"violationDetected"})}let cspEstablished;function fileEstablishesCsp(){if(cspEstablished!==void 0)return cspEstablished;let found=false;walk(context.sourceCode.ast,node=>{if(found||!establishesCsp(node))return;found=true});cspEstablished=found;return found}return{CallExpression(node){const method=calleeMethodOf(node);if(method===null)return;if(FILE_METHODS.has(method)){const target=node.arguments[0];if(target===void 0||!namesDocumentFile(target,context.sourceCode)){return}}else{if(!EMIT_METHODS.has(method))return;if(method==="render"&&!receiverLooksLikeResponse(node))return;if(method!=="render"){const body=node.arguments[0];if(body===void 0)return;if(!mayHoldDocument(body,context.sourceCode))return}}if(fileEstablishesCsp())return;if(scopeSetsResponseHeaders(node))return;report(node)}};function receiverLooksLikeResponse(node){const callee=node.callee;if(callee.object.type===eslint_devkit_2.AST_NODE_TYPES.Identifier){const initializer=(0,resolve_binding_1.resolveInitializer)(callee.object,context.sourceCode);if(initializer!==void 0){return false}}let object=callee.object;if(object.type==="MemberExpression"&&!object.computed){object=object.property}return object.type==="Identifier"&&responseReceivers.has(object.name.toLowerCase())}function calleeMethodOf(node){if(node.callee.type!=="MemberExpression")return null;const property=node.callee.property;return node.callee.computed?staticString(property,context.sourceCode,0):property.name}function scopeSetsResponseHeaders(node){let scope=context.sourceCode.ast;for(let current=node.parent;current!=null;current=current.parent){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){scope=current;break}}let found=false;walk(scope,child=>{if(child.type==="CallExpression"&&child.callee.type==="MemberExpression"&&!child.callee.computed&&child.callee.property.type==="Identifier"&&HEADER_METHODS.has(child.callee.property.name)){found=true}});return found}}});function establishesCsp(node){if(node.type==="ImportDeclaration"){return typeof node.source.value==="string"&&HELMET_MODULE.test(node.source.value)}if(node.type==="CallExpression"){const arg=node.arguments[0];return node.callee.type==="Identifier"&&node.callee.name==="require"&&arg?.type==="Literal"&&typeof arg.value==="string"&&HELMET_MODULE.test(arg.value)}if(node.type==="Literal"){return typeof node.value==="string"&&node.value.toLowerCase()===CSP_HEADER&&isHeaderNamePosition(node)}if(node.type==="JSXAttribute"){return node.name.type==="JSXIdentifier"&&(node.name.name==="httpEquiv"||node.name.name==="http-equiv")&&node.value?.type==="Literal"&&typeof node.value.value==="string"&&node.value.value.toLowerCase()===CSP_HEADER}return false}function isHeaderNamePosition(node){const parent=node.parent;if(parent.type==="CallExpression"&&parent.arguments[0]===node&&parent.callee.type==="MemberExpression"&&!parent.callee.computed&&parent.callee.property.type==="Identifier"&&HEADER_METHODS.has(parent.callee.property.name)){return true}if(parent.type==="Property"&&!parent.computed){if(parent.key===node)return true;if(parent.value===node&&parent.key.type==="Identifier"&&parent.key.name==="key"){return true}}return false}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireCspHeaders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const resolve_binding_1=require("../../utils/resolve-binding");const EMIT_METHODS=new Set(["send","end","write","render"]);const FILE_METHODS=new Set(["sendFile"]);const DOCUMENT_EXTENSIONS=new Set([".html",".htm"]);const HEADER_METHODS=new Set(["setHeader","writeHead","header","set"]);const CSP_HEADER="content-security-policy";const HELMET_MODULE=/^helmet(\/|$)/;function isNode(value){return typeof value==="object"&&value!==null&&typeof value.type==="string"}function staticString(node,sourceCode,depth){if(depth>5)return null;if(node.type==="Literal"){return typeof node.value==="string"?node.value:null}if(node.type==="TemplateLiteral"){return node.quasis.map(q=>q.value?.raw??"").join(" ")}if(node.type==="Identifier"){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:staticString(init,sourceCode,depth+1)}if(node.type==="MemberExpression"&&node.computed){const index=node.property;if(index.type!=="Literal"||typeof index.value!=="number")return null;const array=foldToArray(node.object,sourceCode,depth+1);const element=array?.elements[index.value];return element==null?null:staticString(element,sourceCode,depth+1)}if(node.type==="CallExpression"&&node.callee.type==="Identifier"){const fn=resolveLocalFunction(node.callee,sourceCode);if(fn===null)return null;return returnedString(fn,sourceCode,depth+1)}return null}function foldToArray(node,sourceCode,depth){if(depth>5)return null;if(node.type==="ArrayExpression")return node;if(node.type==="Identifier"){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:foldToArray(init,sourceCode,depth+1)}if(node.type==="MemberExpression"&&node.computed){const index=node.property;if(index.type!=="Literal"||typeof index.value!=="number")return null;const outer=foldToArray(node.object,sourceCode,depth+1);const element=outer?.elements[index.value];return element==null?null:foldToArray(element,sourceCode,depth+1)}return null}function resolveLocalFunction(callee,sourceCode){for(let scope=sourceCode.getScope(callee);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===callee.name);if(variable===void 0)continue;if(variable.defs.length!==1)return null;const def=variable.defs[0];if(def.type==="FunctionName")return def.node;if(def.type==="Variable"){const init=def.node.init;return init?.type==="ArrowFunctionExpression"||init?.type==="FunctionExpression"?init:null}return null}return null}function returnedString(fn,sourceCode,depth){if((fn.type==="ArrowFunctionExpression"||fn.type==="FunctionExpression"||fn.type==="FunctionDeclaration")&&fn.body.type!=="BlockStatement"){return staticString(fn.body,sourceCode,depth)}const parts=[];walk(fn,child=>{if(child.type!=="ReturnStatement"||child.argument===null)return;const value=staticString(child.argument,sourceCode,depth);if(value!==null)parts.push(value)});return parts.length>0?parts.join(" "):null}function walk(node,visit){visit(node);for(const key of Object.keys(node)){if(key==="parent")continue;const child=node[key];if(Array.isArray(child)){for(const item of child)if(isNode(item))walk(item,visit)}else if(isNode(child)){walk(child,visit)}}}function isHtmlDocument(text){const lower=text.toLowerCase();return lower.includes("<!doctype")||lower.includes("<html")}function mayHoldDocument(node,sourceCode){const folded=staticString(node,sourceCode,0);if(folded!==null&&isHtmlDocument(folded))return true;if(node.type!=="Identifier")return false;const variable=sourceCode.getScope(node).references.find(ref=>ref.identifier===node)?.resolved;if(variable==null)return false;for(const def of variable.defs){if(def.type!=="Variable"||def.node.init==null)continue;const value=staticString(def.node.init,sourceCode,0);if(value!==null&&isHtmlDocument(value))return true}for(const reference of variable.references){if(!reference.isWrite())continue;const written=reference.writeExpr;if(written==null)continue;const value=staticString(written,sourceCode,0);if(value!==null&&isHtmlDocument(value))return true}return false}function namesDocumentFile(node,sourceCode){const candidates=[];const direct=staticString(node,sourceCode,0);if(direct!==null)candidates.push(direct);if(node.type==="CallExpression"){for(const arg of node.arguments){const value=staticString(arg,sourceCode,0);if(value!==null)candidates.push(value)}}return candidates.some(candidate=>{const dot=candidate.lastIndexOf(".");return dot!==-1&&DOCUMENT_EXTENSIONS.has(candidate.slice(dot).toLowerCase())})}exports.requireCspHeaders=(0,eslint_devkit_1.createRule)({name:"require-csp-headers",skipTestFiles:true,meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-csp-headers.md",description:"Require Content Security Policy headers",cwe:"CWE-1021",cvss:6.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing CSP",cwe:"CWE-1021",description:"HTML response without Content-Security-Policy header",severity:"MEDIUM",fix:"Use helmet.contentSecurityPolicy() or set CSP header manually",documentationLink:"https://cwe.mitre.org/data/definitions/1021.html"})},schema:[{type:"object",properties:{responseReceivers:{type:"array",items:{type:"string"},default:["res","response","reply"],description:"Identifiers that name a response object, so `<name>.render(view)` emits a response rather than returning a string. Anything unlisted is treated as a template engine."}},additionalProperties:false}]},defaultOptions:[{responseReceivers:["res","response","reply"]}],create(context,[options]){const responseReceivers=new Set(options.responseReceivers.map(name=>name.toLowerCase()));function report(node){context.report({node,messageId:"violationDetected"})}let cspEstablished;function fileEstablishesCsp(){if(cspEstablished!==void 0)return cspEstablished;let found=false;walk(context.sourceCode.ast,node=>{if(found||!establishesCsp(node))return;found=true});cspEstablished=found;return found}return{CallExpression(node){const method=calleeMethodOf(node);if(method===null)return;if(FILE_METHODS.has(method)){const target=node.arguments[0];if(target===void 0||!namesDocumentFile(target,context.sourceCode)){return}}else{if(!EMIT_METHODS.has(method))return;if(method==="render"&&!receiverLooksLikeResponse(node))return;if(method!=="render"){const body=node.arguments[0];if(body===void 0)return;if(!mayHoldDocument(body,context.sourceCode))return}}if(fileEstablishesCsp())return;if(scopeSetsResponseHeaders(node))return;report(node)}};function receiverLooksLikeResponse(node){const callee=node.callee;if(callee.object.type===eslint_devkit_2.AST_NODE_TYPES.Identifier){const initializer=(0,resolve_binding_1.resolveInitializer)(callee.object,context.sourceCode);if(initializer!==void 0){return false}}let object=callee.object;if(object.type==="MemberExpression"&&!object.computed){object=object.property}return object.type==="Identifier"&&responseReceivers.has(object.name.toLowerCase())}function calleeMethodOf(node){if(node.callee.type!=="MemberExpression")return null;const property=node.callee.property;return node.callee.computed?staticString(property,context.sourceCode,0):property.name}function scopeSetsResponseHeaders(node){let scope=context.sourceCode.ast;for(let current=node.parent;current!=null;current=current.parent){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){scope=current;break}}let found=false;walk(scope,child=>{if(child.type==="CallExpression"&&child.callee.type==="MemberExpression"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(child.callee),HEADER_METHODS)){found=true}});return found}}});function establishesCsp(node){if(node.type==="ImportDeclaration"){return typeof node.source.value==="string"&&HELMET_MODULE.test(node.source.value)}if(node.type==="CallExpression"){const arg=node.arguments[0];return node.callee.type==="Identifier"&&node.callee.name==="require"&&arg?.type==="Literal"&&typeof arg.value==="string"&&HELMET_MODULE.test(arg.value)}if(node.type==="Literal"){return typeof node.value==="string"&&node.value.toLowerCase()===CSP_HEADER&&isHeaderNamePosition(node)}if(node.type==="JSXAttribute"){return node.name.type==="JSXIdentifier"&&(node.name.name==="httpEquiv"||node.name.name==="http-equiv")&&node.value?.type==="Literal"&&typeof node.value.value==="string"&&node.value.value.toLowerCase()===CSP_HEADER}return false}function isHeaderNamePosition(node){const parent=node.parent;if(parent.type==="CallExpression"&&parent.arguments[0]===node&&parent.callee.type==="MemberExpression"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(parent.callee),HEADER_METHODS)){return true}if(parent.type==="Property"&&!parent.computed){if(parent.key===node)return true;if(parent.value===node&&parent.key.type==="Identifier"&&parent.key.name==="key"){return true}}return false}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireMimeTypeValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const resolve_binding_1=require("../../utils/resolve-binding");const IANA_TOP_LEVEL_TYPES=new Set(["application","audio","example","font","haptics","image","message","model","multipart","text","video"]);const SUBSTRING_TESTS=new Set(["startsWith","endsWith","includes","indexOf","lastIndexOf","search","match"]);const MULTER_FIELD_METHODS=new Set(["single","array","fields","any","none"]);function isMediaTypeLiteral(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Literal)return false;if(typeof node.value!=="string")return false;const slash=node.value.indexOf("/");if(slash<=0)return false;return IANA_TOP_LEVEL_TYPES.has(node.value.slice(0,slash))}function isTypeRead(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="type"}function isFilesRead(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="files"}function walk(node,visit){visit(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(isNode(child))walk(child,visit)}else if(isNode(value)){walk(value,visit)}}}function isNode(value){return typeof value==="object"&&value!==null&&typeof value.type==="string"}function enclosingFunction(node,sourceCode){return sourceCode.getScope(node).variableScope.block}function isUploadSink(node){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.name==="fetch"&&node.arguments[1]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){return node.arguments[1].properties.some(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&!property.computed&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.key.name==="body")}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(callee.property.name==="send")return node.arguments.length>0;if(callee.property.name==="append")return node.arguments.length>=2}return false}function multerCall(node,scope,sourceCode){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){return(0,eslint_devkit_1.isModuleBinding)(node.callee,scope,"multer")?node:void 0}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?void 0:multerCall(init,scope,sourceCode)}return void 0}exports.requireMimeTypeValidation=(0,eslint_devkit_1.createRule)({name:"require-mime-type-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-mime-type-validation.md",description:"Require MIME type validation for file uploads",cwe:"CWE-434",cvss:8.8},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing MIME Validation",cwe:"CWE-434",description:"File upload without MIME type validation - unrestricted upload vulnerability",severity:"HIGH",fix:"Add a fileFilter option that compares file.mimetype against an exact allowlist. A limits option caps file SIZE and validates no type.",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"}),prefixMimeCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MIME Type Checked by Prefix",cwe:"CWE-434",description:'A media type tested with {{method}} rather than compared for equality. "image/svg+xml" satisfies a prefix test for "image/" and then executes script when the file is served back.',severity:"HIGH",fix:"Compare the type for exact equality against an allowlist: ALLOWED.has(file.type).",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"}),missingMimeValidation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"File Uploaded Without MIME Validation",cwe:"CWE-434",description:"Selected files are uploaded without any media-type check in this handler - unrestricted upload vulnerability.",severity:"HIGH",fix:"Compare file.type for exact equality against an allowlist before uploading. The accept attribute is a UI hint and is not enforced.",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"})},schema:[]},defaultOptions:[],create(context){const sourceCode=context.sourceCode;const reportedScopes=new Set;function hasMimeEvidence(scope){let found=false;walk(scope,node=>{if(found)return;if(isTypeRead(node)||isMediaTypeLiteral(node))found=true});return found}function readsSelectedFiles(scope){let found=false;walk(scope,node=>{if(found)return;if(isFilesRead(node))found=true});return found}return{CallExpression(node){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&SUBSTRING_TESTS.has(callee.property.name)&&isTypeRead(callee.object)&&node.arguments.some(isMediaTypeLiteral)){context.report({node,messageId:"prefixMimeCheck",data:{method:callee.property.name}});return}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&MULTER_FIELD_METHODS.has(callee.property.name)){const factory=multerCall(callee.object,sourceCode.getScope(node),sourceCode);if(factory!==void 0){const config=factory.arguments[0];const hasFileFilter=config?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression&&config.properties.some(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&!property.computed&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.key.name==="fileFilter");if(!hasFileFilter){context.report({node,messageId:"violationDetected"})}return}}if(!isUploadSink(node))return;const scope=enclosingFunction(node,sourceCode);if(reportedScopes.has(scope))return;if(!readsSelectedFiles(scope))return;if(hasMimeEvidence(scope))return;reportedScopes.add(scope);context.report({node,messageId:"missingMimeValidation"})}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireMimeTypeValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const resolve_binding_1=require("../../utils/resolve-binding");const IANA_TOP_LEVEL_TYPES=new Set(["application","audio","example","font","haptics","image","message","model","multipart","text","video"]);const SUBSTRING_TESTS=new Set(["startsWith","endsWith","includes","indexOf","lastIndexOf","search","match"]);const MULTER_FIELD_METHODS=new Set(["single","array","fields","any","none"]);function isMediaTypeLiteral(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Literal)return false;if(typeof node.value!=="string")return false;const slash=node.value.indexOf("/");if(slash<=0)return false;return IANA_TOP_LEVEL_TYPES.has(node.value.slice(0,slash))}function isTypeRead(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(node)==="type"}function isFilesRead(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(node)==="files"}function walk(node,visit){visit(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(isNode(child))walk(child,visit)}else if(isNode(value)){walk(value,visit)}}}function isNode(value){return typeof value==="object"&&value!==null&&typeof value.type==="string"}function enclosingFunction(node,sourceCode){return sourceCode.getScope(node).variableScope.block}function isUploadSink(node){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.name==="fetch"&&node.arguments[1]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){return node.arguments[1].properties.some(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&!property.computed&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.key.name==="body")}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const method=(0,eslint_devkit_1.propertyName)(callee);if(method==="send")return node.arguments.length>0;if(method==="append")return node.arguments.length>=2}return false}function multerCall(node,scope,sourceCode){if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){return(0,eslint_devkit_1.isModuleBinding)(node.callee,scope,"multer")?node:void 0}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?void 0:multerCall(init,scope,sourceCode)}return void 0}exports.requireMimeTypeValidation=(0,eslint_devkit_1.createRule)({name:"require-mime-type-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-mime-type-validation.md",description:"Require MIME type validation for file uploads",cwe:"CWE-434",cvss:8.8},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing MIME Validation",cwe:"CWE-434",description:"File upload without MIME type validation - unrestricted upload vulnerability",severity:"HIGH",fix:"Add a fileFilter option that compares file.mimetype against an exact allowlist. A limits option caps file SIZE and validates no type.",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"}),prefixMimeCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"MIME Type Checked by Prefix",cwe:"CWE-434",description:'A media type tested with {{method}} rather than compared for equality. "image/svg+xml" satisfies a prefix test for "image/" and then executes script when the file is served back.',severity:"HIGH",fix:"Compare the type for exact equality against an allowlist: ALLOWED.has(file.type).",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"}),missingMimeValidation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"File Uploaded Without MIME Validation",cwe:"CWE-434",description:"Selected files are uploaded without any media-type check in this handler - unrestricted upload vulnerability.",severity:"HIGH",fix:"Compare file.type for exact equality against an allowlist before uploading. The accept attribute is a UI hint and is not enforced.",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"})},schema:[]},defaultOptions:[],create(context){const sourceCode=context.sourceCode;const reportedScopes=new Set;function hasMimeEvidence(scope){let found=false;walk(scope,node=>{if(found)return;if(isTypeRead(node)||isMediaTypeLiteral(node))found=true});return found}function readsSelectedFiles(scope){let found=false;walk(scope,node=>{if(found)return;if(isFilesRead(node))found=true});return found}return{CallExpression(node){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),SUBSTRING_TESTS)&&isTypeRead(callee.object)&&node.arguments.some(isMediaTypeLiteral)){context.report({node,messageId:"prefixMimeCheck",data:{method:(0,eslint_devkit_1.propertyName)(callee)}});return}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),MULTER_FIELD_METHODS)){const factory=multerCall(callee.object,sourceCode.getScope(node),sourceCode);if(factory!==void 0){const config=factory.arguments[0];const hasFileFilter=config?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression&&config.properties.some(property=>property.type===eslint_devkit_1.AST_NODE_TYPES.Property&&!property.computed&&property.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.key.name==="fileFilter");if(!hasFileFilter){context.report({node,messageId:"violationDetected"})}return}}if(!isUploadSink(node))return;const scope=enclosingFunction(node,sourceCode);if(reportedScopes.has(scope))return;if(!readsSelectedFiles(scope))return;if(hasMimeEvidence(scope))return;reportedScopes.add(scope);context.report({node,messageId:"missingMimeValidation"})}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requirePostmessageOriginCheck=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const regexp_anchoring_1=require("../../utils/regexp-anchoring");const NON_WINDOW_RECEIVERS=new Set(["WebSocket","EventSource","Worker","SharedWorker","BroadcastChannel","MessagePort","MessageChannel"]);function receiverKey(node){if(node.type==="Identifier")return node.name;if(node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"){if(node.object.type==="ThisExpression"){return`this.${node.property.name}`}if(node.object.type==="Identifier"){return`${node.object.name}.${node.property.name}`}}return void 0}function annotatedTypeName(annotation){const type=annotation?.typeAnnotation;if(type?.type==="TSTypeReference"&&type.typeName.type==="Identifier"){return type.typeName.name}return void 0}function hasOriginCheck(node,sourceCode){const text=sourceCode.getText(node);const originPatterns=[/event\.origin\s*[!=]==?\s*/,/e\.origin\s*[!=]==?\s*/,/\.origin\s*[!=]==?\s*/,/origin\s*[!=]==?\s*/,/checkOrigin/i,/validateOrigin/i,/isAllowedOrigin/i,/trustedOrigins/i,/allowedOrigins/i];return originPatterns.some(pattern=>pattern.test(text))}exports.requirePostmessageOriginCheck=(0,eslint_devkit_1.createRule)({name:"require-postmessage-origin-check",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-postmessage-origin-check.md",description:"Require origin validation in postMessage event listeners",cwe:"CWE-346",cvss:7.5},messages:{missingOriginCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing postMessage Origin Validation",cwe:"CWE-346",description:"postMessage listener lacks origin check. Malicious sites can send messages that will be processed.",severity:"HIGH",fix:"Add origin validation: if (event.origin !== 'https://trusted-domain.com') return;",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{allowInTests:false}],create(context,[options={}]){const{allowInTests=false}=options;const filename=context.filename;const isTestFile=allowInTests&&(0,eslint_devkit_1.isTestFilePath)(filename);if(isTestFile){return{}}const sourceCode=context.sourceCode;const unverified=[];const nonWindowReceivers=new Set;function rememberIfNonWindow(key,typeName){if(key===void 0||typeName===void 0)return;if(NON_WINDOW_RECEIVERS.has(typeName))nonWindowReceivers.add(key)}const anchoredOriginTests=[];function isOriginRead(node){return node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"&&node.property.name==="origin"}return{PropertyDefinition(node){if(node.key.type!=="Identifier")return;rememberIfNonWindow(`this.${node.key.name}`,annotatedTypeName(node.typeAnnotation))},VariableDeclarator(node){if(node.id.type!=="Identifier")return;rememberIfNonWindow(node.id.name,annotatedTypeName(node.id.typeAnnotation))},NewExpression(node){if(node.callee.type!=="Identifier")return;const typeName=node.callee.name;const parent=node.parent;if(parent?.type==="VariableDeclarator"&&parent.init===node){rememberIfNonWindow(receiverKey(parent.id),typeName);return}if(parent?.type==="AssignmentExpression"&&parent.right===node){rememberIfNonWindow(receiverKey(parent.left),typeName)}},CallExpression(node){const callee=node.callee;if(node.arguments.length===1&&isOriginRead(node.arguments[0])&&(0,regexp_anchoring_1.isAnchoredRegexpTest)(node,sourceCode)){anchoredOriginTests.push([node.range[0],node.range[1]])}let isMessageListener=false;let receiver;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true;receiver=receiverKey(callee.object);if(callee.object.type==="NewExpression"&&callee.object.callee.type==="Identifier"&&NON_WINDOW_RECEIVERS.has(callee.object.callee.name)){return}}}if(callee.type==="Identifier"&&callee.name==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true}}if(!isMessageListener){return}const handlerArg=node.arguments[1];if(!handlerArg){return}if(handlerArg.type==="FunctionExpression"||handlerArg.type==="ArrowFunctionExpression"){if(!hasOriginCheck(handlerArg,sourceCode)){unverified.push({handler:handlerArg,receiver})}}if(handlerArg.type==="Identifier"){}},"Program:exit"(){for(const{handler,receiver}of unverified){if(receiver!==void 0&&nonWindowReceivers.has(receiver)){continue}const guarded=anchoredOriginTests.some(([start,end])=>start>=handler.range[0]&&end<=handler.range[1]);if(guarded)continue;context.report({node:handler,messageId:"missingOriginCheck"})}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requirePostmessageOriginCheck=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const regexp_anchoring_1=require("../../utils/regexp-anchoring");const NON_WINDOW_RECEIVERS=new Set(["WebSocket","EventSource","Worker","SharedWorker","BroadcastChannel","MessagePort","MessageChannel"]);function receiverKey(node){if(node.type==="Identifier")return node.name;if(node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"){if(node.object.type==="ThisExpression"){return`this.${node.property.name}`}if(node.object.type==="Identifier"){return`${node.object.name}.${node.property.name}`}}return void 0}function annotatedTypeName(annotation){const type=annotation?.typeAnnotation;if(type?.type==="TSTypeReference"&&type.typeName.type==="Identifier"){return type.typeName.name}return void 0}function hasOriginCheck(node,sourceCode){const text=sourceCode.getText(node);const originPatterns=[/event\.origin\s*[!=]==?\s*/,/e\.origin\s*[!=]==?\s*/,/\.origin\s*[!=]==?\s*/,/origin\s*[!=]==?\s*/,/checkOrigin/i,/validateOrigin/i,/isAllowedOrigin/i,/trustedOrigins/i,/allowedOrigins/i];return originPatterns.some(pattern=>pattern.test(text))}exports.requirePostmessageOriginCheck=(0,eslint_devkit_1.createRule)({name:"require-postmessage-origin-check",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-postmessage-origin-check.md",description:"Require origin validation in postMessage event listeners",cwe:"CWE-346",cvss:7.5},messages:{missingOriginCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing postMessage Origin Validation",cwe:"CWE-346",description:"postMessage listener lacks origin check. Malicious sites can send messages that will be processed.",severity:"HIGH",fix:"Add origin validation: if (event.origin !== 'https://trusted-domain.com') return;",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{allowInTests:false}],create(context,[options={}]){const{allowInTests=false}=options;const filename=context.filename;const isTestFile=allowInTests&&(0,eslint_devkit_1.isTestFilePath)(filename);if(isTestFile){return{}}const sourceCode=context.sourceCode;const unverified=[];const nonWindowReceivers=new Set;function rememberIfNonWindow(key,typeName){if(key===void 0||typeName===void 0)return;if(NON_WINDOW_RECEIVERS.has(typeName))nonWindowReceivers.add(key)}const anchoredOriginTests=[];function isOriginRead(node){return node.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node)==="origin"}return{PropertyDefinition(node){if(node.key.type!=="Identifier")return;rememberIfNonWindow(`this.${node.key.name}`,annotatedTypeName(node.typeAnnotation))},VariableDeclarator(node){if(node.id.type!=="Identifier")return;rememberIfNonWindow(node.id.name,annotatedTypeName(node.id.typeAnnotation))},NewExpression(node){if(node.callee.type!=="Identifier")return;const typeName=node.callee.name;const parent=node.parent;if(parent?.type==="VariableDeclarator"&&parent.init===node){rememberIfNonWindow(receiverKey(parent.id),typeName);return}if(parent?.type==="AssignmentExpression"&&parent.right===node){rememberIfNonWindow(receiverKey(parent.left),typeName)}},CallExpression(node){const callee=node.callee;if(node.arguments.length===1&&isOriginRead(node.arguments[0])&&(0,regexp_anchoring_1.isAnchoredRegexpTest)(node,sourceCode)){anchoredOriginTests.push([node.range[0],node.range[1]])}let isMessageListener=false;let receiver;if(callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(callee)==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true;receiver=receiverKey(callee.object);if(callee.object.type==="NewExpression"&&callee.object.callee.type==="Identifier"&&NON_WINDOW_RECEIVERS.has(callee.object.callee.name)){return}}}if(callee.type==="Identifier"&&callee.name==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true}}if(!isMessageListener){return}const handlerArg=node.arguments[1];if(!handlerArg){return}if(handlerArg.type==="FunctionExpression"||handlerArg.type==="ArrowFunctionExpression"){if(!hasOriginCheck(handlerArg,sourceCode)){unverified.push({handler:handlerArg,receiver})}}if(handlerArg.type==="Identifier"){}},"Program:exit"(){for(const{handler,receiver}of unverified){if(receiver!==void 0&&nonWindowReceivers.has(receiver)){continue}const guarded=anchoredOriginTests.some(([start,end])=>start>=handler.range[0]&&end<=handler.range[1]);if(guarded)continue;context.report({node:handler,messageId:"missingOriginCheck"})}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireUrlValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const navigation_targets_1=require("../../utils/navigation-targets");const regexp_anchoring_1=require("../../utils/regexp-anchoring");exports.requireUrlValidation=(0,eslint_devkit_1.createRule)({name:"require-url-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-url-validation.md",description:"Enforce URL validation before navigation",cwe:"CWE-601",cvss:6.1},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"URL Validation Required",cwe:"CWE-601",description:"Unvalidated URL used for navigation - this is a security risk",severity:"HIGH",fix:"Validate URLs before using them for navigation",documentationLink:"https://cwe.mitre.org/data/definitions/601.html"})},schema:[]},defaultOptions:[],create(context){const{sourceCode}=context;function report(node){context.report({node,messageId:"violationDetected"})}const provesSafeDestination=test=>(0,regexp_anchoring_1.isAnchoredHostGuard)(test,sourceCode)||(0,navigation_targets_1.isRelativePathGuard)(test,sourceCode)||(0,navigation_targets_1.isOriginEqualityGuard)(test,sourceCode);const OPENERS=new Set(["window","self","globalThis","top","parent"]);function calleeParts(node){const callee=node.callee;if(callee.type!=="MemberExpression"||callee.computed)return null;if(callee.property.type!=="Identifier")return null;return{object:callee.object,method:callee.property.name}}return{CallExpression(node){const parts=calleeParts(node);if(parts===null)return;const urlArg=node.arguments[0];if(urlArg===void 0)return;const isOpen=parts.method==="open"&&parts.object.type==="Identifier"&&OPENERS.has(parts.object.name);const isRouterNavigation=(parts.method==="push"||parts.method==="replace")&&(0,navigation_targets_1.isRouterObject)(parts.object,sourceCode);if(!isOpen&&!isRouterNavigation)return;if(!(0,navigation_targets_1.isSteerableUrlValue)(urlArg,sourceCode))return;if((0,navigation_targets_1.isGuardedDestination)(node,urlArg,sourceCode,provesSafeDestination)){return}report(node)}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireUrlValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const navigation_targets_1=require("../../utils/navigation-targets");const regexp_anchoring_1=require("../../utils/regexp-anchoring");exports.requireUrlValidation=(0,eslint_devkit_1.createRule)({name:"require-url-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-url-validation.md",description:"Enforce URL validation before navigation",cwe:"CWE-601",cvss:6.1},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"URL Validation Required",cwe:"CWE-601",description:"Unvalidated URL used for navigation - this is a security risk",severity:"HIGH",fix:"Validate URLs before using them for navigation",documentationLink:"https://cwe.mitre.org/data/definitions/601.html"})},schema:[]},defaultOptions:[],create(context){const{sourceCode}=context;function report(node){context.report({node,messageId:"violationDetected"})}const provesSafeDestination=test=>(0,regexp_anchoring_1.isAnchoredHostGuard)(test,sourceCode)||(0,navigation_targets_1.isRelativePathGuard)(test,sourceCode)||(0,navigation_targets_1.isOriginEqualityGuard)(test,sourceCode);const OPENERS=new Set(["window","self","globalThis","top","parent"]);function calleeParts(node){const callee=node.callee;if(callee.type!=="MemberExpression")return null;const method=(0,eslint_devkit_1.propertyName)(callee);return method===null?null:{object:callee.object,method}}return{CallExpression(node){const parts=calleeParts(node);if(parts===null)return;const urlArg=node.arguments[0];if(urlArg===void 0)return;const isOpen=parts.method==="open"&&parts.object.type==="Identifier"&&OPENERS.has(parts.object.name);const isRouterNavigation=(parts.method==="push"||parts.method==="replace")&&(0,navigation_targets_1.isRouterObject)(parts.object,sourceCode);if(!isOpen&&!isRouterNavigation)return;if(!(0,navigation_targets_1.isSteerableUrlValue)(urlArg,sourceCode))return;if((0,navigation_targets_1.isGuardedDestination)(node,urlArg,sourceCode,provesSafeDestination)){return}report(node)}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isAnalyticsTransmission=isAnalyticsTransmission;const eslint_devkit_1=require("@interlace/eslint-devkit");const ANALYTICS_METHODS=new Map([["analytics",new Set(["track","identify","page","screen","group"])],["mixpanel",new Set(["track","identify","register"])],["posthog",new Set(["capture","identify","setPersonProperties"])],["amplitude",new Set(["track","logEvent","identify"])],["Sentry",new Set(["setUser","setContext"])],["dataLayer",new Set(["push"])]]);const ANALYTICS_FUNCTIONS=new Set(["gtag"]);const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function analyticsClientName(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return ANALYTICS_METHODS.has(node.name)?node.name:null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&ANALYTICS_METHODS.has(node.property.name)&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&GLOBAL_ALIASES.has(node.object.name)){return node.property.name}return null}function isAnalyticsTransmission(node,extraAnalyticsMethods=[]){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&ANALYTICS_FUNCTIONS.has(callee.name)){return true}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||callee.computed||callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){return false}const client=analyticsClientName(callee.object);if(client===null)return false;const method=callee.property.name;if(ANALYTICS_METHODS.get(client)?.has(method)===true)return true;return client==="analytics"&&extraAnalyticsMethods.includes(method)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isAnalyticsTransmission=isAnalyticsTransmission;const eslint_devkit_1=require("@interlace/eslint-devkit");const ANALYTICS_METHODS=new Map([["analytics",new Set(["track","identify","page","screen","group"])],["mixpanel",new Set(["track","identify","register"])],["posthog",new Set(["capture","identify","setPersonProperties"])],["amplitude",new Set(["track","logEvent","identify"])],["Sentry",new Set(["setUser","setContext"])],["dataLayer",new Set(["push"])]]);const ANALYTICS_FUNCTIONS=new Set(["gtag"]);const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function analyticsClientName(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return ANALYTICS_METHODS.has(node.name)?node.name:null}if(node.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return null;const client=(0,eslint_devkit_1.propertyName)(node);return client!==null&&ANALYTICS_METHODS.has(client)&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&GLOBAL_ALIASES.has(node.object.name)?client:null}function isAnalyticsTransmission(node,extraAnalyticsMethods=[]){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&ANALYTICS_FUNCTIONS.has(callee.name)){return true}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;const method=(0,eslint_devkit_1.propertyName)(callee);if(method===null)return false;const client=analyticsClientName(callee.object);if(client===null)return false;if(ANALYTICS_METHODS.get(client)?.has(method)===true)return true;return client==="analytics"&&extraAnalyticsMethods.includes(method)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.dynamicCodeSink=dynamicCodeSink;const eslint_devkit_1=require("@interlace/eslint-devkit");const resolve_binding_1=require("./resolve-binding");const DYNAMIC_CODE_NAMES=new Set(["eval","Function","execScript"]);const GLOBAL_RECEIVERS=new Set(["window","self","globalThis","global"]);const TIMER_NAMES=new Set(["setTimeout","setInterval","setImmediate"]);function isUnshadowedGlobal(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable!==void 0)return variable.defs.length===0}return true}function bareGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return null;if(!DYNAMIC_CODE_NAMES.has(node.name))return null;return isUnshadowedGlobal(node,sourceCode)?node.name:null}function qualifiedGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return null;if(node.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!GLOBAL_RECEIVERS.has(node.object.name)||!isUnshadowedGlobal(node.object,sourceCode)){return null}const property=node.computed?literalString(node.property):node.property.name;if(property===null)return null;return DYNAMIC_CODE_NAMES.has(property)?property:null}function literalString(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"?node.value:null}function constructorChain(node){const isConstructorAccess=n=>n.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!n.computed&&n.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&n.property.name==="constructor";if(!isConstructorAccess(node))return null;return isConstructorAccess(node.object)?"Function":null}function sequenceCallee(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.SequenceExpression)return null;const last=node.expressions[node.expressions.length-1];return bareGlobal(last,sourceCode)}function aliasedGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return null;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init===void 0)return null;return bareGlobal(init,sourceCode)??qualifiedGlobal(init,sourceCode)??constructorChain(init)}function isProvableString(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal)return typeof node.value==="string";if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral)return true;if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){return isProvableString(node.left)||isProvableString(node.right)}return false}function timerName(callee,sourceCode){if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&TIMER_NAMES.has(callee.name)&&isUnshadowedGlobal(callee,sourceCode)){return callee.name}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&GLOBAL_RECEIVERS.has(callee.object.name)&&isUnshadowedGlobal(callee.object,sourceCode)&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&TIMER_NAMES.has(callee.property.name)){return callee.property.name}return null}const LABELS={eval:"eval",Function:"Function constructor",execScript:"execScript"};function dynamicCodeSink(node,sourceCode){const callee=node.callee;const args=node.arguments;const direct=bareGlobal(callee,sourceCode);if(direct!==null){return{kind:"direct",name:direct,label:LABELS[direct],codeArguments:args}}const indirect=qualifiedGlobal(callee,sourceCode)??constructorChain(callee)??sequenceCallee(callee,sourceCode)??aliasedGlobal(callee,sourceCode);if(indirect!==null){return{kind:"indirect",name:indirect,label:LABELS[indirect],codeArguments:args}}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const timer=timerName(callee,sourceCode);const body=args[0];if(timer!==null&&body!==void 0&&isProvableString(body)){return{kind:"timer",name:null,label:`${timer} with string`,codeArguments:[body]}}}return void 0}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.dynamicCodeSink=dynamicCodeSink;const eslint_devkit_1=require("@interlace/eslint-devkit");const resolve_binding_1=require("./resolve-binding");const DYNAMIC_CODE_NAMES=new Set(["eval","Function","execScript"]);const GLOBAL_RECEIVERS=new Set(["window","self","globalThis","global"]);const TIMER_NAMES=new Set(["setTimeout","setInterval","setImmediate"]);function isUnshadowedGlobal(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable!==void 0)return variable.defs.length===0}return true}function bareGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return null;if(!DYNAMIC_CODE_NAMES.has(node.name))return null;return isUnshadowedGlobal(node,sourceCode)?node.name:null}function qualifiedGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return null;if(node.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!GLOBAL_RECEIVERS.has(node.object.name)||!isUnshadowedGlobal(node.object,sourceCode)){return null}const property=node.computed?literalString(node.property):node.property.name;if(property===null)return null;return DYNAMIC_CODE_NAMES.has(property)?property:null}function literalString(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"?node.value:null}function constructorChain(node){const isConstructorAccess=n=>n.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(n)==="constructor";if(!isConstructorAccess(node))return null;return isConstructorAccess(node.object)?"Function":null}function sequenceCallee(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.SequenceExpression)return null;const last=node.expressions[node.expressions.length-1];return bareGlobal(last,sourceCode)}function aliasedGlobal(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return null;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init===void 0)return null;return bareGlobal(init,sourceCode)??qualifiedGlobal(init,sourceCode)??constructorChain(init)}function isProvableString(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal)return typeof node.value==="string";if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral)return true;if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){return isProvableString(node.left)||isProvableString(node.right)}return false}function timerName(callee,sourceCode){if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&TIMER_NAMES.has(callee.name)&&isUnshadowedGlobal(callee,sourceCode)){return callee.name}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&GLOBAL_RECEIVERS.has(callee.object.name)&&isUnshadowedGlobal(callee.object,sourceCode)&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),TIMER_NAMES)){return(0,eslint_devkit_1.propertyName)(callee)}return null}const LABELS={eval:"eval",Function:"Function constructor",execScript:"execScript"};function dynamicCodeSink(node,sourceCode){const callee=node.callee;const args=node.arguments;const direct=bareGlobal(callee,sourceCode);if(direct!==null){return{kind:"direct",name:direct,label:LABELS[direct],codeArguments:args}}const indirect=qualifiedGlobal(callee,sourceCode)??constructorChain(callee)??sequenceCallee(callee,sourceCode)??aliasedGlobal(callee,sourceCode);if(indirect!==null){return{kind:"indirect",name:indirect,label:LABELS[indirect],codeArguments:args}}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const timer=timerName(callee,sourceCode);const body=args[0];if(timer!==null&&body!==void 0&&isProvableString(body)){return{kind:"timer",name:null,label:`${timer} with string`,codeArguments:[body]}}}return void 0}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isExpressAppOrRouter=isExpressAppOrRouter;exports.asExpressRouteRegistration=asExpressRouteRegistration;const eslint_devkit_1=require("@interlace/eslint-devkit");const ROUTER_RETURNING_METHODS=new Set(["route","use"]);function isExpressAppOrRouter(node,scope,seen=new Set){if(seen.has(node))return false;seen.add(node);if(node.type==="CallExpression"||node.type==="NewExpression"){const{callee}=node;if((0,eslint_devkit_1.isModuleBinding)(callee,scope,"express",[]))return true;if((0,eslint_devkit_1.isModuleBinding)(callee,scope,"express",["Router"]))return true;if(callee.type==="MemberExpression"&&!callee.computed&&callee.property.type==="Identifier"&&ROUTER_RETURNING_METHODS.has(callee.property.name)){return isExpressAppOrRouter(callee.object,scope,seen)}return false}if(node.type!=="Identifier")return false;for(let current=scope;current;current=current.upper){const variable=current.variables.find(v=>v.name===node.name);if(variable===void 0)continue;if(variable.defs.length!==1)return false;const def=variable.defs[0];if(def.type!=="Variable"||def.node.init===null)return false;if(variable.references.filter(ref=>ref.isWrite()).length>1)return false;return isExpressAppOrRouter(def.node.init,scope,seen)}return false}function asExpressRouteRegistration(node,scope,methods){const{callee}=node;if(callee.type!=="MemberExpression"||callee.computed||callee.property.type!=="Identifier"){return null}const method=callee.property.name;if(!methods.has(method.toLowerCase()))return null;if(!isExpressAppOrRouter(callee.object,scope))return null;if(isRouteCall(callee.object)){return node.arguments.length>0?{method,pathArg:null}:null}if(node.arguments.length<2)return null;if(!isRoutePath(node.arguments[0]))return null;return{method,pathArg:node.arguments[0]}}function isRouteCall(node){return node.type==="CallExpression"&&node.callee.type==="MemberExpression"&&!node.callee.computed&&node.callee.property.type==="Identifier"&&node.callee.property.name==="route"}function isRoutePath(node){if(node.type==="Literal"){return typeof node.value==="string"||node.value instanceof RegExp}if(node.type==="TemplateLiteral")return true;if(node.type==="ArrayExpression"){return node.elements.length>0&&node.elements.every(el=>el!==null&&isRoutePath(el))}return false}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isExpressAppOrRouter=isExpressAppOrRouter;exports.asExpressRouteRegistration=asExpressRouteRegistration;const eslint_devkit_1=require("@interlace/eslint-devkit");const ROUTER_RETURNING_METHODS=new Set(["route","use"]);function isExpressAppOrRouter(node,scope,seen=new Set){if(seen.has(node))return false;seen.add(node);if(node.type==="CallExpression"||node.type==="NewExpression"){const{callee}=node;if((0,eslint_devkit_1.isModuleBinding)(callee,scope,"express",[]))return true;if((0,eslint_devkit_1.isModuleBinding)(callee,scope,"express",["Router"]))return true;if(callee.type==="MemberExpression"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(callee),ROUTER_RETURNING_METHODS)){return isExpressAppOrRouter(callee.object,scope,seen)}return false}if(node.type!=="Identifier")return false;for(let current=scope;current;current=current.upper){const variable=current.variables.find(v=>v.name===node.name);if(variable===void 0)continue;if(variable.defs.length!==1)return false;const def=variable.defs[0];if(def.type!=="Variable"||def.node.init===null)return false;if(variable.references.filter(ref=>ref.isWrite()).length>1)return false;return isExpressAppOrRouter(def.node.init,scope,seen)}return false}function asExpressRouteRegistration(node,scope,methods){const{callee}=node;if(callee.type!=="MemberExpression")return null;const method=(0,eslint_devkit_1.propertyName)(callee);if(method===null)return null;if(!methods.has(method.toLowerCase()))return null;if(!isExpressAppOrRouter(callee.object,scope))return null;if(isRouteCall(callee.object)){return node.arguments.length>0?{method,pathArg:null}:null}if(node.arguments.length<2)return null;if(!isRoutePath(node.arguments[0]))return null;return{method,pathArg:node.arguments[0]}}function isRouteCall(node){return node.type==="CallExpression"&&node.callee.type==="MemberExpression"&&(0,eslint_devkit_1.propertyName)(node.callee)==="route"}function isRoutePath(node){if(node.type==="Literal"){return typeof node.value==="string"||node.value instanceof RegExp}if(node.type==="TemplateLiteral")return true;if(node.type==="ArrayExpression"){return node.elements.length>0&&node.elements.every(el=>el!==null&&isRoutePath(el))}return false}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveGlobalObject=resolveGlobalObject;exports.isGlobalObject=isGlobalObject;const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function resolveGlobalObject(node,names){if(node.type==="Identifier"){return names.has(node.name)?node.name:null}if(node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"&&names.has(node.property.name)&&node.object.type==="Identifier"&&GLOBAL_ALIASES.has(node.object.name)){return node.property.name}return null}function isGlobalObject(node,names){return resolveGlobalObject(node,names)!==null}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveGlobalObject=resolveGlobalObject;exports.isGlobalObject=isGlobalObject;const eslint_devkit_1=require("@interlace/eslint-devkit");const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function resolveGlobalObject(node,names){if(node.type==="Identifier"){return names.has(node.name)?node.name:null}if(node.type==="MemberExpression"&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(node),names)&&node.object.type==="Identifier"&&GLOBAL_ALIASES.has(node.object.name)){return(0,eslint_devkit_1.propertyName)(node)}return null}function isGlobalObject(node,names){return resolveGlobalObject(node,names)!==null}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isLocationTarget=isLocationTarget;exports.isLocationNavigationWrite=isLocationNavigationWrite;exports.isLocationNavigationCall=isLocationNavigationCall;exports.identityArgumentIndex=identityArgumentIndex;exports.isSteerableUrlValue=isSteerableUrlValue;exports.isRelativePathGuard=isRelativePathGuard;exports.isOriginEqualityGuard=isOriginEqualityGuard;exports.isOpaquePredicateOverTarget=isOpaquePredicateOverTarget;exports.isGuardedDestination=isGuardedDestination;exports.isRouterObject=isRouterObject;const eslint_devkit_1=require("@interlace/eslint-devkit");const url_taint_1=require("./url-taint");const resolve_binding_1=require("./resolve-binding");const LOCATION_HOLDERS=new Set(["window","document","self","top","parent","globalThis"]);const STEERABLE_LOCATION_PROPS=new Set(["href","search","hash","pathname"]);function staticKey(node){if(!node.computed){return node.property.type==="Identifier"?node.property.name:null}return node.property.type==="Literal"&&typeof node.property.value==="string"?node.property.value:null}function isLocationTarget(node){if(node.type==="Identifier"){return node.name==="location"}return node.type==="MemberExpression"&&staticKey(node)==="location"&&node.object.type==="Identifier"&&LOCATION_HOLDERS.has(node.object.name)}function isLocationNavigationWrite(node){if(node.type!=="MemberExpression")return false;if(isLocationTarget(node)&&node.object.type==="Identifier")return true;return staticKey(node)==="href"&&isLocationTarget(node.object)}function isLocationNavigationCall(node){const callee=node.callee;if(callee.type!=="MemberExpression")return false;const method=staticKey(callee);return(method==="assign"||method==="replace")&&isLocationTarget(callee.object)}function isSteerableLocationRead(node){if(node.type!=="MemberExpression")return false;const key=staticKey(node);return key!==null&&STEERABLE_LOCATION_PROPS.has(key)&&isLocationTarget(node.object)}const ROUTER_MODULES=["next/navigation","next/router","vue-router","react-router","react-router-dom","@tanstack/react-router"];const SEARCH_PARAM_MODULES=["next/navigation","react-router","react-router-dom"];function isHookCallFrom(node,sourceCode,hook,modules){if(node.type!=="CallExpression"||node.callee.type!=="Identifier"){return false}if(node.callee.name!==hook)return false;const scope=sourceCode.getScope(node.callee);return modules.some(module=>(0,eslint_devkit_1.isModuleBinding)(node.callee,scope,module,[hook]))}function urlContainerKind(node,sourceCode,seen){switch(node.type){case"NewExpression":{if(node.callee.type!=="Identifier")return null;const first=node.arguments[0];if(first===void 0||first.type==="SpreadElement")return null;if(node.callee.name==="URLSearchParams"){return isSteerableUrlValue(first,sourceCode,seen)?"params":null}if(node.callee.name==="URL"){return isSteerableUrlValue(first,sourceCode,seen)?"url":null}return null}case"MemberExpression":{if(staticKey(node)==="searchParams"&&urlContainerKind(node.object,sourceCode,seen)==="url"){return"params"}return null}case"CallExpression":{if(isHookCallFrom(node,sourceCode,"useSearchParams",SEARCH_PARAM_MODULES)){return"params"}return null}case"Identifier":{if(seen.has(node.name))return null;seen.add(node.name);const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:urlContainerKind(init,sourceCode,seen)}default:return null}}const PARAM_READERS=new Set(["get","getAll"]);function resolveFunctionNode(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable===void 0)continue;if(variable.defs.length!==1)return void 0;const def=variable.defs[0];if(def.type==="FunctionName"){return def.node.type==="FunctionDeclaration"?def.node:void 0}const init=(0,resolve_binding_1.resolveInitializer)(identifier,sourceCode);if(init!==void 0&&(init.type==="FunctionExpression"||init.type==="ArrowFunctionExpression")){return init}return void 0}return void 0}function identityArgumentIndex(node,sourceCode){if(node.callee.type!=="Identifier")return null;const fn=resolveFunctionNode(node.callee,sourceCode);if(fn===void 0)return null;const returned=fn.body.type==="BlockStatement"?fn.body.body.length===1&&fn.body.body[0].type==="ReturnStatement"?fn.body.body[0].argument:null:fn.body;if(returned===null||returned===void 0)return null;if(returned.type!=="Identifier")return null;const index=fn.params.findIndex(param=>param.type==="Identifier"&&param.name===returned.name);return index===-1?null:index}function isSteerableUrlValue(node,sourceCode,seen=new Set){if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;if(isSteerableLocationRead(node))return true;switch(node.type){case"CallExpression":{const callee=node.callee;if(callee.type==="MemberExpression"&&!callee.computed&&callee.property.type==="Identifier"&&PARAM_READERS.has(callee.property.name)&&urlContainerKind(callee.object,sourceCode,seen)==="params"){return true}const index=identityArgumentIndex(node,sourceCode);if(index!==null){const argument=node.arguments[index];return argument!==void 0&&argument.type!=="SpreadElement"&&isSteerableUrlValue(argument,sourceCode,seen)}return false}case"MemberExpression":{const key=staticKey(node);return key!==null&&STEERABLE_LOCATION_PROPS.has(key)&&urlContainerKind(node.object,sourceCode,seen)==="url"}case"Identifier":{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isSteerableUrlValue(init,sourceCode,seen)}case"BinaryExpression":return node.operator==="+"&&isSteerableUrlValue(node.left,sourceCode,seen);case"TemplateLiteral":return node.quasis[0].value.cooked===""&&node.expressions.length>0&&isSteerableUrlValue(node.expressions[0],sourceCode,seen);case"LogicalExpression":return isSteerableUrlValue(node.left,sourceCode,seen)||isSteerableUrlValue(node.right,sourceCode,seen);case"ConditionalExpression":return isSteerableUrlValue(node.consequent,sourceCode,seen)||isSteerableUrlValue(node.alternate,sourceCode,seen);default:return false}}function isRelativePathGuard(test,sourceCode){const conjuncts=[];const flatten=node=>{if(node.type==="LogicalExpression"&&node.operator==="&&"){flatten(node.left);flatten(node.right);return}conjuncts.push(node)};flatten(test);const startsWith=(node,negated)=>{let current=node;let seenNegation=false;while(current.type==="UnaryExpression"&&current.operator==="!"){seenNegation=!seenNegation;current=current.argument}if(seenNegation!==negated)return null;if(current.type!=="CallExpression"||current.callee.type!=="MemberExpression"||current.callee.computed||current.callee.property.type!=="Identifier"||current.callee.property.name!=="startsWith"){return null}const argument=current.arguments[0];if(argument===void 0||argument.type!=="Literal"||typeof argument.value!=="string"){return null}return{receiver:sourceCode.getText(current.callee.object),prefix:argument.value}};const rejectsBothViaRegex=conjuncts.some(conjunct=>{if(conjunct.type!=="CallExpression"||conjunct.callee.type!=="MemberExpression"||conjunct.callee.computed||conjunct.callee.property.type!=="Identifier"||conjunct.callee.property.name!=="test"||conjunct.callee.object.type!=="Literal"||!("regex"in conjunct.callee.object)||conjunct.callee.object.regex===void 0){return false}const{pattern}=conjunct.callee.object.regex;return pattern.startsWith("^\\/[^/")||pattern.startsWith("^\\/(?!\\/)")});if(rejectsBothViaRegex)return true;const positives=conjuncts.map(conjunct=>startsWith(conjunct,false)).filter(hit=>hit!==null).filter(hit=>hit.prefix==="/");if(positives.length===0)return false;return conjuncts.some(conjunct=>{const hit=startsWith(conjunct,true);return hit!==null&&hit.prefix==="//"&&positives.some(positive=>positive.receiver===hit.receiver)})}const ORIGIN_COMPONENTS=new Set(["origin","host","hostname"]);function isOriginEqualityGuard(test,sourceCode){const isParsedOriginRead=node=>node.type==="MemberExpression"&&ORIGIN_COMPONENTS.has(staticKey(node)??"")&&urlContainerKind(node.object,sourceCode,new Set)==="url";const visit=(node,depth)=>{if(depth>6)return false;switch(node.type){case"LogicalExpression":return visit(node.left,depth+1)||visit(node.right,depth+1);case"BinaryExpression":if(node.operator!=="==="&&node.operator!=="==")return false;return isParsedOriginRead(node.left)||isParsedOriginRead(node.right);default:return false}};return visit(test,0)}function resolvesToKnowableFunction(node,sourceCode){if(node.type!=="Identifier")return false;for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;if(variable.defs.length!==1)return false;if(variable.defs[0].type==="FunctionName")return true;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&(init.type==="FunctionExpression"||init.type==="ArrowFunctionExpression")}return false}function isOpaquePredicateOverTarget(test,target,sourceCode){const targetText=sourceCode.getText(target);const visit=(node,depth)=>{if(depth>6)return false;if(node.type==="LogicalExpression"){return visit(node.left,depth+1)||visit(node.right,depth+1)}if(node.type!=="CallExpression")return false;const receivesTarget=node.arguments.some(argument=>argument.type!=="SpreadElement"&&sourceCode.getText(argument)===targetText);if(!receivesTarget)return false;return!resolvesToKnowableFunction(node.callee,sourceCode)};return visit(test,0)}function isGuardedDestination(node,target,sourceCode,provesSafe){const guards=test=>provesSafe(test)||isOpaquePredicateOverTarget(test,target,sourceCode);if(target.type==="ConditionalExpression"&&provesSafe(target.test)){return true}const guardedByEarlyExit=(block,child2)=>block.body.some(statement=>{if(statement.range[0]>=child2.range[0])return false;if(statement.type!=="IfStatement")return false;if(statement.test.type!=="UnaryExpression"||statement.test.operator!=="!"||!guards(statement.test.argument)){return false}const branch=statement.consequent;return branch.type==="ReturnStatement"||branch.type==="ThrowStatement"||branch.type==="BlockStatement"&&branch.body.some(s=>s.type==="ReturnStatement"||s.type==="ThrowStatement")});let child=node;let current=node.parent;let depth=0;while(current&&depth<20){if(current.type==="IfStatement"&&guards(current.test))return true;if((current.type==="BlockStatement"||current.type==="Program")&&guardedByEarlyExit(current,child)){return true}child=current;current=current.parent;depth++}return false}function isRouterObject(node,sourceCode){if(node.type!=="Identifier")return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isHookCallFrom(init,sourceCode,"useRouter",ROUTER_MODULES)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isLocationTarget=isLocationTarget;exports.isLocationNavigationWrite=isLocationNavigationWrite;exports.isLocationNavigationCall=isLocationNavigationCall;exports.identityArgumentIndex=identityArgumentIndex;exports.isSteerableUrlValue=isSteerableUrlValue;exports.isRelativePathGuard=isRelativePathGuard;exports.isOriginEqualityGuard=isOriginEqualityGuard;exports.isOpaquePredicateOverTarget=isOpaquePredicateOverTarget;exports.isGuardedDestination=isGuardedDestination;exports.isRouterObject=isRouterObject;const eslint_devkit_1=require("@interlace/eslint-devkit");const url_taint_1=require("./url-taint");const resolve_binding_1=require("./resolve-binding");const LOCATION_HOLDERS=new Set(["window","document","self","top","parent","globalThis"]);const STEERABLE_LOCATION_PROPS=new Set(["href","search","hash","pathname"]);function staticKey(node){if(!node.computed){return node.property.type==="Identifier"?node.property.name:null}return node.property.type==="Literal"&&typeof node.property.value==="string"?node.property.value:null}function isLocationTarget(node){if(node.type==="Identifier"){return node.name==="location"}return node.type==="MemberExpression"&&staticKey(node)==="location"&&node.object.type==="Identifier"&&LOCATION_HOLDERS.has(node.object.name)}function isLocationNavigationWrite(node){if(node.type!=="MemberExpression")return false;if(isLocationTarget(node)&&node.object.type==="Identifier")return true;return staticKey(node)==="href"&&isLocationTarget(node.object)}function isLocationNavigationCall(node){const callee=node.callee;if(callee.type!=="MemberExpression")return false;const method=staticKey(callee);return(method==="assign"||method==="replace")&&isLocationTarget(callee.object)}function isSteerableLocationRead(node){if(node.type!=="MemberExpression")return false;const key=staticKey(node);return key!==null&&STEERABLE_LOCATION_PROPS.has(key)&&isLocationTarget(node.object)}const ROUTER_MODULES=["next/navigation","next/router","vue-router","react-router","react-router-dom","@tanstack/react-router"];const SEARCH_PARAM_MODULES=["next/navigation","react-router","react-router-dom"];function isHookCallFrom(node,sourceCode,hook,modules){if(node.type!=="CallExpression"||node.callee.type!=="Identifier"){return false}if(node.callee.name!==hook)return false;const scope=sourceCode.getScope(node.callee);return modules.some(module=>(0,eslint_devkit_1.isModuleBinding)(node.callee,scope,module,[hook]))}function urlContainerKind(node,sourceCode,seen){switch(node.type){case"NewExpression":{if(node.callee.type!=="Identifier")return null;const first=node.arguments[0];if(first===void 0||first.type==="SpreadElement")return null;if(node.callee.name==="URLSearchParams"){return isSteerableUrlValue(first,sourceCode,seen)?"params":null}if(node.callee.name==="URL"){return isSteerableUrlValue(first,sourceCode,seen)?"url":null}return null}case"MemberExpression":{if(staticKey(node)==="searchParams"&&urlContainerKind(node.object,sourceCode,seen)==="url"){return"params"}return null}case"CallExpression":{if(isHookCallFrom(node,sourceCode,"useSearchParams",SEARCH_PARAM_MODULES)){return"params"}return null}case"Identifier":{if(seen.has(node.name))return null;seen.add(node.name);const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:urlContainerKind(init,sourceCode,seen)}default:return null}}const PARAM_READERS=new Set(["get","getAll"]);function resolveFunctionNode(identifier,sourceCode){for(let scope=sourceCode.getScope(identifier);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===identifier.name);if(variable===void 0)continue;if(variable.defs.length!==1)return void 0;const def=variable.defs[0];if(def.type==="FunctionName"){return def.node.type==="FunctionDeclaration"?def.node:void 0}const init=(0,resolve_binding_1.resolveInitializer)(identifier,sourceCode);if(init!==void 0&&(init.type==="FunctionExpression"||init.type==="ArrowFunctionExpression")){return init}return void 0}return void 0}function identityArgumentIndex(node,sourceCode){if(node.callee.type!=="Identifier")return null;const fn=resolveFunctionNode(node.callee,sourceCode);if(fn===void 0)return null;const returned=fn.body.type==="BlockStatement"?fn.body.body.length===1&&fn.body.body[0].type==="ReturnStatement"?fn.body.body[0].argument:null:fn.body;if(returned===null||returned===void 0)return null;if(returned.type!=="Identifier")return null;const index=fn.params.findIndex(param=>param.type==="Identifier"&&param.name===returned.name);return index===-1?null:index}function isSteerableUrlValue(node,sourceCode,seen=new Set){if((0,url_taint_1.isAttackerSteerableUrl)(node,sourceCode))return true;if(isSteerableLocationRead(node))return true;switch(node.type){case"CallExpression":{const callee=node.callee;if(callee.type==="MemberExpression"&&PARAM_READERS.has(staticKey(callee)??"")&&urlContainerKind(callee.object,sourceCode,seen)==="params"){return true}const index=identityArgumentIndex(node,sourceCode);if(index!==null){const argument=node.arguments[index];return argument!==void 0&&argument.type!=="SpreadElement"&&isSteerableUrlValue(argument,sourceCode,seen)}return false}case"MemberExpression":{const key=staticKey(node);return key!==null&&STEERABLE_LOCATION_PROPS.has(key)&&urlContainerKind(node.object,sourceCode,seen)==="url"}case"Identifier":{if(seen.has(node.name))return false;seen.add(node.name);const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isSteerableUrlValue(init,sourceCode,seen)}case"BinaryExpression":return node.operator==="+"&&isSteerableUrlValue(node.left,sourceCode,seen);case"TemplateLiteral":return node.quasis[0].value.cooked===""&&node.expressions.length>0&&isSteerableUrlValue(node.expressions[0],sourceCode,seen);case"LogicalExpression":return isSteerableUrlValue(node.left,sourceCode,seen)||isSteerableUrlValue(node.right,sourceCode,seen);case"ConditionalExpression":return isSteerableUrlValue(node.consequent,sourceCode,seen)||isSteerableUrlValue(node.alternate,sourceCode,seen);default:return false}}function isRelativePathGuard(test,sourceCode){const conjuncts=[];const flatten=node=>{if(node.type==="LogicalExpression"&&node.operator==="&&"){flatten(node.left);flatten(node.right);return}conjuncts.push(node)};flatten(test);const startsWith=(node,negated)=>{let current=node;let seenNegation=false;while(current.type==="UnaryExpression"&&current.operator==="!"){seenNegation=!seenNegation;current=current.argument}if(seenNegation!==negated)return null;if(current.type!=="CallExpression"||current.callee.type!=="MemberExpression"||staticKey(current.callee)!=="startsWith"){return null}const argument=current.arguments[0];if(argument===void 0||argument.type!=="Literal"||typeof argument.value!=="string"){return null}return{receiver:sourceCode.getText(current.callee.object),prefix:argument.value}};const rejectsBothViaRegex=conjuncts.some(conjunct=>{if(conjunct.type!=="CallExpression"||conjunct.callee.type!=="MemberExpression"||conjunct.callee.computed||conjunct.callee.property.type!=="Identifier"||conjunct.callee.property.name!=="test"||conjunct.callee.object.type!=="Literal"||!("regex"in conjunct.callee.object)||conjunct.callee.object.regex===void 0){return false}const{pattern}=conjunct.callee.object.regex;return pattern.startsWith("^\\/[^/")||pattern.startsWith("^\\/(?!\\/)")});if(rejectsBothViaRegex)return true;const positives=conjuncts.map(conjunct=>startsWith(conjunct,false)).filter(hit=>hit!==null).filter(hit=>hit.prefix==="/");if(positives.length===0)return false;return conjuncts.some(conjunct=>{const hit=startsWith(conjunct,true);return hit!==null&&hit.prefix==="//"&&positives.some(positive=>positive.receiver===hit.receiver)})}const ORIGIN_COMPONENTS=new Set(["origin","host","hostname"]);function isOriginEqualityGuard(test,sourceCode){const isParsedOriginRead=node=>node.type==="MemberExpression"&&ORIGIN_COMPONENTS.has(staticKey(node)??"")&&urlContainerKind(node.object,sourceCode,new Set)==="url";const visit=(node,depth)=>{if(depth>6)return false;switch(node.type){case"LogicalExpression":return visit(node.left,depth+1)||visit(node.right,depth+1);case"BinaryExpression":if(node.operator!=="==="&&node.operator!=="==")return false;return isParsedOriginRead(node.left)||isParsedOriginRead(node.right);default:return false}};return visit(test,0)}function resolvesToKnowableFunction(node,sourceCode){if(node.type!=="Identifier")return false;for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;if(variable.defs.length!==1)return false;if(variable.defs[0].type==="FunctionName")return true;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&(init.type==="FunctionExpression"||init.type==="ArrowFunctionExpression")}return false}function isOpaquePredicateOverTarget(test,target,sourceCode){const targetText=sourceCode.getText(target);const visit=(node,depth)=>{if(depth>6)return false;if(node.type==="LogicalExpression"){return visit(node.left,depth+1)||visit(node.right,depth+1)}if(node.type!=="CallExpression")return false;const receivesTarget=node.arguments.some(argument=>argument.type!=="SpreadElement"&&sourceCode.getText(argument)===targetText);if(!receivesTarget)return false;return!resolvesToKnowableFunction(node.callee,sourceCode)};return visit(test,0)}function isGuardedDestination(node,target,sourceCode,provesSafe){const guards=test=>provesSafe(test)||isOpaquePredicateOverTarget(test,target,sourceCode);if(target.type==="ConditionalExpression"&&provesSafe(target.test)){return true}const guardedByEarlyExit=(block,child2)=>block.body.some(statement=>{if(statement.range[0]>=child2.range[0])return false;if(statement.type!=="IfStatement")return false;if(statement.test.type!=="UnaryExpression"||statement.test.operator!=="!"||!guards(statement.test.argument)){return false}const branch=statement.consequent;return branch.type==="ReturnStatement"||branch.type==="ThrowStatement"||branch.type==="BlockStatement"&&branch.body.some(s=>s.type==="ReturnStatement"||s.type==="ThrowStatement")});let child=node;let current=node.parent;let depth=0;while(current&&depth<20){if(current.type==="IfStatement"&&guards(current.test))return true;if((current.type==="BlockStatement"||current.type==="Program")&&guardedByEarlyExit(current,child)){return true}child=current;current=current.parent;depth++}return false}function isRouterObject(node,sourceCode){if(node.type!=="Identifier")return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isHookCallFrom(init,sourceCode,"useRouter",ROUTER_MODULES)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isProtocolInspection=isProtocolInspection;const eslint_devkit_1=require("@interlace/eslint-devkit");const WRITES_SECOND_ARGUMENT=new Set(["replace","replaceAll"]);const COMPARISON_OPERATORS=new Set(["===","!==","==","!=",">","<",">=","<="]);const INSPECTION_METHODS=new Set(["startsWith","endsWith","includes","indexOf","lastIndexOf","search","match","matchAll","test","split","replace","replaceAll"]);function isProtocolInspection(node,parent){if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&INSPECTION_METHODS.has(parent.callee.property.name)){if(WRITES_SECOND_ARGUMENT.has(parent.callee.property.name)){return parent.arguments[0]===node}return true}return parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&COMPARISON_OPERATORS.has(parent.operator)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isProtocolInspection=isProtocolInspection;const eslint_devkit_1=require("@interlace/eslint-devkit");const WRITES_SECOND_ARGUMENT=new Set(["replace","replaceAll"]);const COMPARISON_OPERATORS=new Set(["===","!==","==","!=",">","<",">=","<="]);const INSPECTION_METHODS=new Set(["startsWith","endsWith","includes","indexOf","lastIndexOf","search","match","matchAll","test","split","replace","replaceAll"]);function isProtocolInspection(node,parent){if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(parent.callee),INSPECTION_METHODS)){if((0,eslint_devkit_1.namesOneOf)((0,eslint_devkit_1.propertyName)(parent.callee),WRITES_SECOND_ARGUMENT)){return parent.arguments[0]===node}return true}return parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&COMPARISON_OPERATORS.has(parent.operator)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.NON_BEARER_SECRET_TERMS=exports.BEARER_CREDENTIAL_TERMS=void 0;exports.normalizeResourceKey=normalizeResourceKey;exports.namesMeasurementOnly=namesMeasurementOnly;exports.namesBearerCredential=namesBearerCredential;exports.namesNonBearerSecret=namesNonBearerSecret;exports.resolveStorageArea=resolveStorageArea;exports.memberName=memberName;exports.resolveKeyText=resolveKeyText;exports.isJwtLiteral=isJwtLiteral;exports.hasProvableJwtValue=hasProvableJwtValue;exports.isCacheStorageReceiver=isCacheStorageReceiver;exports.isIndexedDbStoreReceiver=isIndexedDbStoreReceiver;exports.isIdbWrapperDatabase=isIdbWrapperDatabase;exports.isDocumentCookieTarget=isDocumentCookieTarget;exports.staticCookieText=staticCookieText;exports.cookieNameFrom=cookieNameFrom;exports.isCookieDeletion=isCookieDeletion;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("./global-object");const resolve_binding_1=require("./resolve-binding");exports.BEARER_CREDENTIAL_TERMS=["jwt","token","bearer","auth","authorization","session","sid","credential","credentials"];exports.NON_BEARER_SECRET_TERMS=["password","passwd","pwd","passphrase","secret","api key","apikey","private key","secret key","encryption key","signing key","client secret","credit card","card number","cvv","cvc","ssn","social security","seed phrase","mnemonic","recovery code"];function normalizeResourceKey(key){return key.replace(/[/?&=:#%+*]+/g,"-")}const MEASUREMENT_TERMS=["count","length","size","limit","total","index","offset","expiry","expires","expiration","ttl","timeout","version","enabled","visible"];function singularizeWords(key){return(0,eslint_devkit_1.identifierWords)(normalizeResourceKey(key)).map(w=>w.length>3&&w.endsWith("s")&&!w.endsWith("ss")?w.slice(0,-1):w).join(" ")}function namesMeasurementOnly(key){return(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),MEASUREMENT_TERMS)}function namesBearerCredential(key,terms=exports.BEARER_CREDENTIAL_TERMS){return!namesMeasurementOnly(key)&&(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),terms)}function namesNonBearerSecret(key,terms=exports.NON_BEARER_SECRET_TERMS){return!namesMeasurementOnly(key)&&(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),terms)}function lookupVariable(name,scope){for(let s=scope;s!==null;s=s.upper){const found=s.variables.find(v=>v.name===name);if(found!==void 0)return found}return null}const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function destructuredGlobalName(variable,names){const def=variable.defs[0];if(def===void 0||def.type!=="Variable")return null;if(def.node.id.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectPattern)return null;const init=def.node.init;if(init===null||init.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!GLOBAL_ALIASES.has(init.name)){return null}for(const property of def.node.id.properties){if(property.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(property.key.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)continue;if(!names.has(property.key.name))continue;if(property.value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.value.name===variable.name){return property.key.name}}return null}function resolveStorageArea(node,sourceCode,names){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const variable=lookupVariable(node.name,sourceCode.getScope(node));if(variable===null||variable.defs.length===0){return names.has(node.name)?node.name:null}return destructuredGlobalName(variable,names)}return(0,global_object_1.resolveGlobalObject)(node,names)}function memberName(member,sourceCode){if(!member.computed){return member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?member.property.name:null}if(member.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof member.property.value==="string"){return member.property.value}if(member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&sourceCode){const init=(0,resolve_binding_1.resolveInitializer)(member.property,sourceCode);if(init!==void 0&&init.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof init.value==="string"){return init.value}}return null}const UNKNOWN="*";function resolveKeyText(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(q=>q.value.raw).join(UNKNOWN)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){const left=resolveKeyText(node.left,sourceCode,followBinding);const right=resolveKeyText(node.right,sourceCode,followBinding);if(left===null&&right===null)return null;return(left??UNKNOWN)+(right??UNKNOWN)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init!==void 0&&(init.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral||init.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression)){const composed=resolveKeyText(init,sourceCode,false);if(composed!==null)return composed}}return(0,resolve_binding_1.resolveStringKey)(node,sourceCode)}const BASE64URL_ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function decodeBase64Url(segment){let bits=0;let acc=0;let out="";for(const ch of segment){acc=acc<<6|BASE64URL_ALPHABET.indexOf(ch);bits+=6;if(bits>=8){bits-=8;out+=String.fromCharCode(acc>>bits&255)}}return out}const JWT_SHAPE=/^([A-Za-z0-9_-]{8,})\.([A-Za-z0-9_-]{2,})\.([A-Za-z0-9_-]*)$/;function isJwtLiteral(value){const shape=JWT_SHAPE.exec(value);if(shape===null)return false;let header;try{header=JSON.parse(decodeBase64Url(shape[1]))}catch{return false}return typeof header==="object"&&header!==null&&"alg"in header}const JWT_MINTING_MODULES=new Set(["jsonwebtoken","jose"]);function hasProvableJwtValue(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"){return isJwtLiteral(node.value)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){return isJwtLiteral(node.quasis[0].value.raw)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&JWT_MINTING_MODULES.has(binding.module)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&hasProvableJwtValue(init,sourceCode,false)}return false}const CACHE_STORAGE_GLOBAL=new Set(["caches"]);function unwrapAwait(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression?node.argument:node}function isCachesOpenCall(node){const call=unwrapAwait(node);return call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!call.callee.computed&&call.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&call.callee.property.name==="open"&&(0,global_object_1.resolveGlobalObject)(call.callee.object,CACHE_STORAGE_GLOBAL)!==null}function isCachesOpenThenParameter(node,sourceCode){for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;const def=variable.defs[0];if(def===void 0||def.type!=="Parameter")return false;const call=def.node.parent;return call!==void 0&&call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!call.callee.computed&&call.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&call.callee.property.name==="then"&&isCachesOpenCall(call.callee.object)}return false}function isCacheStorageReceiver(node,sourceCode){if(isCachesOpenCall(node))return true;if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init!==void 0&&isCachesOpenCall(init))return true;return isCachesOpenThenParameter(node,sourceCode)}function isObjectStoreCall(node){const call=unwrapAwait(node);return call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!call.callee.computed&&call.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(call.callee.property.name==="objectStore"||call.callee.property.name==="createObjectStore")}function isIndexedDbStoreReceiver(node,sourceCode,hops=3){if(isObjectStoreCall(node))return true;if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||hops===0)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isIndexedDbStoreReceiver(init,sourceCode,hops-1)}const IDB_WRAPPER_MODULES=new Set(["idb"]);function isIdbWrapperDatabase(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init===void 0)return false;const call=unwrapAwait(init);if(call.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;const binding=(0,eslint_devkit_1.resolveModuleBinding)(call.callee,sourceCode.getScope(node));return binding!==void 0&&IDB_WRAPPER_MODULES.has(binding.module)}const DOCUMENT_GLOBAL=new Set(["document"]);function isDocumentCookieTarget(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&memberName(node)==="cookie"&&(0,global_object_1.resolveGlobalObject)(node.object,DOCUMENT_GLOBAL)!==null}const OPAQUE="\0";function staticCookieText(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"){return node.value}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(q=>q.value.raw).join(OPAQUE)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){const left=staticCookieText(node.left,sourceCode,followBinding);const right=staticCookieText(node.right,sourceCode,followBinding);if(left===null&&right===null)return null;return(left??OPAQUE)+(right??OPAQUE)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:staticCookieText(init,sourceCode,false)}return null}function cookieNameFrom(text){const equals=text.indexOf("=");if(equals<=0)return null;const name=text.slice(0,equals).trim();return name.includes(OPAQUE)?null:name}function isCookieDeletion(text){const[pair]=text.split(";");const equals=pair.indexOf("=");if(equals<0||pair.slice(equals+1).trim().length>0)return false;return/;\s*(?:max-age\s*=\s*(?:0|-\d+)|expires\s*=)/i.test(text)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.NON_BEARER_SECRET_TERMS=exports.BEARER_CREDENTIAL_TERMS=void 0;exports.normalizeResourceKey=normalizeResourceKey;exports.namesMeasurementOnly=namesMeasurementOnly;exports.namesBearerCredential=namesBearerCredential;exports.namesNonBearerSecret=namesNonBearerSecret;exports.resolveStorageArea=resolveStorageArea;exports.memberName=memberName;exports.resolveKeyText=resolveKeyText;exports.isJwtLiteral=isJwtLiteral;exports.hasProvableJwtValue=hasProvableJwtValue;exports.isCacheStorageReceiver=isCacheStorageReceiver;exports.isIndexedDbStoreReceiver=isIndexedDbStoreReceiver;exports.isIdbWrapperDatabase=isIdbWrapperDatabase;exports.isDocumentCookieTarget=isDocumentCookieTarget;exports.staticCookieText=staticCookieText;exports.cookieNameFrom=cookieNameFrom;exports.isCookieDeletion=isCookieDeletion;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("./global-object");const resolve_binding_1=require("./resolve-binding");exports.BEARER_CREDENTIAL_TERMS=["jwt","token","bearer","auth","authorization","session","sid","credential","credentials"];exports.NON_BEARER_SECRET_TERMS=["password","passwd","pwd","passphrase","secret","api key","apikey","private key","secret key","encryption key","signing key","client secret","credit card","card number","cvv","cvc","ssn","social security","seed phrase","mnemonic","recovery code"];function normalizeResourceKey(key){return key.replace(/[/?&=:#%+*]+/g,"-")}const MEASUREMENT_TERMS=["count","length","size","limit","total","index","offset","expiry","expires","expiration","ttl","timeout","version","enabled","visible"];function singularizeWords(key){return(0,eslint_devkit_1.identifierWords)(normalizeResourceKey(key)).map(w=>w.length>3&&w.endsWith("s")&&!w.endsWith("ss")?w.slice(0,-1):w).join(" ")}function namesMeasurementOnly(key){return(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),MEASUREMENT_TERMS)}function namesBearerCredential(key,terms=exports.BEARER_CREDENTIAL_TERMS){return!namesMeasurementOnly(key)&&(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),terms)}function namesNonBearerSecret(key,terms=exports.NON_BEARER_SECRET_TERMS){return!namesMeasurementOnly(key)&&(0,eslint_devkit_1.nameHasAnyWord)(singularizeWords(key),terms)}function lookupVariable(name,scope){for(let s=scope;s!==null;s=s.upper){const found=s.variables.find(v=>v.name===name);if(found!==void 0)return found}return null}const GLOBAL_ALIASES=new Set(["window","self","globalThis"]);function destructuredGlobalName(variable,names){const def=variable.defs[0];if(def===void 0||def.type!=="Variable")return null;if(def.node.id.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectPattern)return null;const init=def.node.init;if(init===null||init.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!GLOBAL_ALIASES.has(init.name)){return null}for(const property of def.node.id.properties){if(property.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;if(property.key.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)continue;if(!names.has(property.key.name))continue;if(property.value.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&property.value.name===variable.name){return property.key.name}}return null}function resolveStorageArea(node,sourceCode,names){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const variable=lookupVariable(node.name,sourceCode.getScope(node));if(variable===null||variable.defs.length===0){return names.has(node.name)?node.name:null}return destructuredGlobalName(variable,names)}return(0,global_object_1.resolveGlobalObject)(node,names)}function memberName(member,sourceCode){if(!member.computed){return member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?member.property.name:null}if(member.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof member.property.value==="string"){return member.property.value}if(member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&sourceCode){const init=(0,resolve_binding_1.resolveInitializer)(member.property,sourceCode);if(init!==void 0&&init.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof init.value==="string"){return init.value}}return null}const UNKNOWN="*";function resolveKeyText(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(q=>q.value.raw).join(UNKNOWN)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){const left=resolveKeyText(node.left,sourceCode,followBinding);const right=resolveKeyText(node.right,sourceCode,followBinding);if(left===null&&right===null)return null;return(left??UNKNOWN)+(right??UNKNOWN)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init!==void 0&&(init.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral||init.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression)){const composed=resolveKeyText(init,sourceCode,false);if(composed!==null)return composed}}return(0,resolve_binding_1.resolveStringKey)(node,sourceCode)}const BASE64URL_ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function decodeBase64Url(segment){let bits=0;let acc=0;let out="";for(const ch of segment){acc=acc<<6|BASE64URL_ALPHABET.indexOf(ch);bits+=6;if(bits>=8){bits-=8;out+=String.fromCharCode(acc>>bits&255)}}return out}const JWT_SHAPE=/^([A-Za-z0-9_-]{8,})\.([A-Za-z0-9_-]{2,})\.([A-Za-z0-9_-]*)$/;function isJwtLiteral(value){const shape=JWT_SHAPE.exec(value);if(shape===null)return false;let header;try{header=JSON.parse(decodeBase64Url(shape[1]))}catch{return false}return typeof header==="object"&&header!==null&&"alg"in header}const JWT_MINTING_MODULES=new Set(["jsonwebtoken","jose"]);function hasProvableJwtValue(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"){return isJwtLiteral(node.value)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){return isJwtLiteral(node.quasis[0].value.raw)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const binding=(0,eslint_devkit_1.resolveModuleBinding)(node.callee,sourceCode.getScope(node));return binding!==void 0&&JWT_MINTING_MODULES.has(binding.module)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&hasProvableJwtValue(init,sourceCode,false)}return false}const CACHE_STORAGE_GLOBAL=new Set(["caches"]);function unwrapAwait(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.AwaitExpression?node.argument:node}function isCachesOpenCall(node){const call=unwrapAwait(node);return call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(call.callee)==="open"&&(0,global_object_1.resolveGlobalObject)(call.callee.object,CACHE_STORAGE_GLOBAL)!==null}function isCachesOpenThenParameter(node,sourceCode){for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable===void 0)continue;const def=variable.defs[0];if(def===void 0||def.type!=="Parameter")return false;const call=def.node.parent;return call!==void 0&&call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&(0,eslint_devkit_1.propertyName)(call.callee)==="then"&&isCachesOpenCall(call.callee.object)}return false}function isCacheStorageReceiver(node,sourceCode){if(isCachesOpenCall(node))return true;if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init!==void 0&&isCachesOpenCall(init))return true;return isCachesOpenThenParameter(node,sourceCode)}function isObjectStoreCall(node){const call=unwrapAwait(node);return call.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&((0,eslint_devkit_1.propertyName)(call.callee)==="objectStore"||(0,eslint_devkit_1.propertyName)(call.callee)==="createObjectStore")}function isIndexedDbStoreReceiver(node,sourceCode,hops=3){if(isObjectStoreCall(node))return true;if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||hops===0)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init!==void 0&&isIndexedDbStoreReceiver(init,sourceCode,hops-1)}const IDB_WRAPPER_MODULES=new Set(["idb"]);function isIdbWrapperDatabase(node,sourceCode){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);if(init===void 0)return false;const call=unwrapAwait(init);if(call.type!==eslint_devkit_1.AST_NODE_TYPES.CallExpression)return false;const binding=(0,eslint_devkit_1.resolveModuleBinding)(call.callee,sourceCode.getScope(node));return binding!==void 0&&IDB_WRAPPER_MODULES.has(binding.module)}const DOCUMENT_GLOBAL=new Set(["document"]);function isDocumentCookieTarget(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&memberName(node)==="cookie"&&(0,global_object_1.resolveGlobalObject)(node.object,DOCUMENT_GLOBAL)!==null}const OPAQUE="\0";function staticCookieText(node,sourceCode,followBinding=true){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.value==="string"){return node.value}if(node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){return node.quasis.map(q=>q.value.raw).join(OPAQUE)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.operator==="+"){const left=staticCookieText(node.left,sourceCode,followBinding);const right=staticCookieText(node.right,sourceCode,followBinding);if(left===null&&right===null)return null;return(left??OPAQUE)+(right??OPAQUE)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&followBinding){const init=(0,resolve_binding_1.resolveInitializer)(node,sourceCode);return init===void 0?null:staticCookieText(init,sourceCode,false)}return null}function cookieNameFrom(text){const equals=text.indexOf("=");if(equals<=0)return null;const name=text.slice(0,equals).trim();return name.includes(OPAQUE)?null:name}function isCookieDeletion(text){const[pair]=text.split(";");const equals=pair.indexOf("=");if(equals<0||pair.slice(equals+1).trim().length>0)return false;return/;\s*(?:max-age\s*=\s*(?:0|-\d+)|expires\s*=)/i.test(text)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isRequestCallSiteUrl=isRequestCallSiteUrl;exports.isRequestCall=isRequestCall;exports.isWebSocketConstructorUrl=isWebSocketConstructorUrl;exports.isSubresourcePosition=isSubresourcePosition;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("./global-object");const FETCH_NAMES=new Set(["fetch"]);const AXIOS_HTTP_METHODS=new Set(["get","post","put","delete","patch","head","options"]);function argumentAncestor(node){let current=node;let parent=current.parent;while(parent!==void 0&&(parent.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral||parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&parent.operator==="+")){current=parent;parent=current.parent}return current}function isRequestCallSiteUrl(node,scope){const argument=argumentAncestor(node);const call=argument.parent;return call?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.arguments[0]===argument&&isRequestCall(call,scope)}function isRequestCall(call,scope){const callee=call.callee;if((0,global_object_1.isGlobalObject)(callee,FETCH_NAMES)){return true}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||callee.computed||callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||!AXIOS_HTTP_METHODS.has(callee.property.name)){return false}return isAxiosClient(callee.object,scope)}function isAxiosClient(receiver,scope){if((0,eslint_devkit_1.isModuleBinding)(receiver,scope,"axios")){return true}return receiver.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&receiver.name==="axios"}function isWebSocketConstructorUrl(node){const argument=argumentAncestor(node);const call=argument.parent;return call?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&call.callee.name==="WebSocket"&&call.arguments[0]===argument}const SUBRESOURCE_ATTRIBUTES=new Map([["img",new Set(["src","srcSet","srcset"])],["image",new Set(["src","href","xlinkHref"])],["script",new Set(["src"])],["link",new Set(["href"])],["iframe",new Set(["src"])],["frame",new Set(["src"])],["embed",new Set(["src"])],["object",new Set(["data"])],["video",new Set(["src","poster"])],["audio",new Set(["src"])],["source",new Set(["src","srcSet","srcset"])],["track",new Set(["src"])],["input",new Set(["src"])],["form",new Set(["action"])]]);const SUBRESOURCE_PROPERTIES=new Set(["src","srcset","poster"]);const SUBRESOURCE_LOADERS=new Set(["importScripts"]);function isSubresourcePosition(node){const value=argumentAncestor(node);const parent=value.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&parent.value===value&&parent.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return isSubresourceJsxAttribute(parent,parent.name.name)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer&&parent.parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&parent.parent.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return isSubresourceJsxAttribute(parent.parent,parent.parent.name.name)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===value&&parent.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&SUBRESOURCE_PROPERTIES.has(propertyNameOf(parent.left)??"")){return true}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const callee=parent.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&SUBRESOURCE_LOADERS.has(callee.name)&&parent.arguments.includes(value)){return true}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!callee.computed&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(SUBRESOURCE_LOADERS.has(callee.property.name)&&parent.arguments.includes(value)){return true}if(callee.property.name==="setAttribute"&&parent.arguments[1]===value&&parent.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof parent.arguments[0].value==="string"&&SUBRESOURCE_PROPERTIES.has(parent.arguments[0].value.toLowerCase())){return true}}}return false}const FETCHING_LINK_RELS=new Set(["stylesheet","preload","modulepreload","prefetch","prerender","icon","apple-touch-icon","apple-touch-startup-image","mask-icon","manifest","preconnect","dns-prefetch"]);function isSubresourceJsxAttribute(attribute,attributeName){const element=attribute.parent;const name=element.name;if(name.type!==eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return false}const attributes=SUBRESOURCE_ATTRIBUTES.get(name.name);if(attributes===void 0||!attributes.has(attributeName)){return false}if(name.name==="link"){return hasFetchingRel(element)}return true}function hasFetchingRel(element){for(const attribute of element.attributes){if(attribute.type!==eslint_devkit_1.AST_NODE_TYPES.JSXAttribute||attribute.name.type!==eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier||attribute.name.name!=="rel"){continue}const value=attribute.value;const rel=value?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof value.value==="string"?value.value:void 0;if(rel===void 0){return false}return rel.toLowerCase().split(/\s+/).some(token=>FETCHING_LINK_RELS.has(token))}return false}function propertyNameOf(member){if(!member.computed&&member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return member.property.name}if(member.computed&&member.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof member.property.value==="string"){return member.property.value}return void 0}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isRequestCallSiteUrl=isRequestCallSiteUrl;exports.isRequestCall=isRequestCall;exports.isWebSocketConstructorUrl=isWebSocketConstructorUrl;exports.isSubresourcePosition=isSubresourcePosition;const eslint_devkit_1=require("@interlace/eslint-devkit");const global_object_1=require("./global-object");const FETCH_NAMES=new Set(["fetch"]);const AXIOS_HTTP_METHODS=new Set(["get","post","put","delete","patch","head","options"]);function argumentAncestor(node){let current=node;let parent=current.parent;while(parent!==void 0&&(parent.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral||parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&parent.operator==="+")){current=parent;parent=current.parent}return current}function isRequestCallSiteUrl(node,scope){const argument=argumentAncestor(node);const call=argument.parent;return call?.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&call.arguments[0]===argument&&isRequestCall(call,scope)}function isRequestCall(call,scope){const callee=call.callee;if((0,global_object_1.isGlobalObject)(callee,FETCH_NAMES)){return true}if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression||!AXIOS_HTTP_METHODS.has(propertyNameOf(callee)??"")){return false}return isAxiosClient(callee.object,scope)}function isAxiosClient(receiver,scope){if((0,eslint_devkit_1.isModuleBinding)(receiver,scope,"axios")){return true}return receiver.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&receiver.name==="axios"}function isWebSocketConstructorUrl(node){const argument=argumentAncestor(node);const call=argument.parent;return call?.type===eslint_devkit_1.AST_NODE_TYPES.NewExpression&&call.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&call.callee.name==="WebSocket"&&call.arguments[0]===argument}const SUBRESOURCE_ATTRIBUTES=new Map([["img",new Set(["src","srcSet","srcset"])],["image",new Set(["src","href","xlinkHref"])],["script",new Set(["src"])],["link",new Set(["href"])],["iframe",new Set(["src"])],["frame",new Set(["src"])],["embed",new Set(["src"])],["object",new Set(["data"])],["video",new Set(["src","poster"])],["audio",new Set(["src"])],["source",new Set(["src","srcSet","srcset"])],["track",new Set(["src"])],["input",new Set(["src"])],["form",new Set(["action"])]]);const SUBRESOURCE_PROPERTIES=new Set(["src","srcset","poster"]);const SUBRESOURCE_LOADERS=new Set(["importScripts"]);function isSubresourcePosition(node){const value=argumentAncestor(node);const parent=value.parent;if(parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&parent.value===value&&parent.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return isSubresourceJsxAttribute(parent,parent.name.name)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.JSXExpressionContainer&&parent.parent?.type===eslint_devkit_1.AST_NODE_TYPES.JSXAttribute&&parent.parent.name.type===eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return isSubresourceJsxAttribute(parent.parent,parent.parent.name.name)}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression&&parent.right===value&&parent.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&SUBRESOURCE_PROPERTIES.has(propertyNameOf(parent.left)??"")){return true}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const callee=parent.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&SUBRESOURCE_LOADERS.has(callee.name)&&parent.arguments.includes(value)){return true}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const method=propertyNameOf(callee);if(SUBRESOURCE_LOADERS.has(method??"")&&parent.arguments.includes(value)){return true}if(method==="setAttribute"&&parent.arguments[1]===value&&parent.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof parent.arguments[0].value==="string"&&SUBRESOURCE_PROPERTIES.has(parent.arguments[0].value.toLowerCase())){return true}}}return false}const FETCHING_LINK_RELS=new Set(["stylesheet","preload","modulepreload","prefetch","prerender","icon","apple-touch-icon","apple-touch-startup-image","mask-icon","manifest","preconnect","dns-prefetch"]);function isSubresourceJsxAttribute(attribute,attributeName){const element=attribute.parent;const name=element.name;if(name.type!==eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier){return false}const attributes=SUBRESOURCE_ATTRIBUTES.get(name.name);if(attributes===void 0||!attributes.has(attributeName)){return false}if(name.name==="link"){return hasFetchingRel(element)}return true}function hasFetchingRel(element){for(const attribute of element.attributes){if(attribute.type!==eslint_devkit_1.AST_NODE_TYPES.JSXAttribute||attribute.name.type!==eslint_devkit_1.AST_NODE_TYPES.JSXIdentifier||attribute.name.name!=="rel"){continue}const value=attribute.value;const rel=value?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof value.value==="string"?value.value:void 0;if(rel===void 0){return false}return rel.toLowerCase().split(/\s+/).some(token=>FETCHING_LINK_RELS.has(token))}return false}function propertyNameOf(member){if(!member.computed&&member.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return member.property.name}if(member.computed&&member.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof member.property.value==="string"){return member.property.value}return void 0}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.STEERABILITY_PRESERVING_FUNCTIONS=exports.STEERABILITY_PRESERVING_METHODS=void 0;exports.isLocationObject=isLocationObject;exports.resolveBoundInitializer=resolveBoundInitializer;exports.isAttackerSteerableUrl=isAttackerSteerableUrl;const resolve_binding_1=require("./resolve-binding");const STEERABLE_LOCATION_PROPS=new Set(["href","search","hash","pathname"]);const LOCATION_HOLDERS=new Set(["window","document","self","top","parent","globalThis"]);const REQUEST_INPUT_PROPS=new Set(["query","body","params"]);function isLocationObject(node){if(node.type==="Identifier"){return node.name==="location"}return node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"&&node.property.name==="location"&&node.object.type==="Identifier"&&LOCATION_HOLDERS.has(node.object.name)}function isRequestInput(node){let current=node;let sawInputProp=false;while(current.type==="MemberExpression"){const property=staticProperty(current);if(property!==null&&REQUEST_INPUT_PROPS.has(property)){sawInputProp=true}current=current.object}return sawInputProp&&current.type==="Identifier"&&(current.name==="req"||current.name==="request")}exports.STEERABILITY_PRESERVING_METHODS=new Set(["slice","substring","substr","trim","trimStart","trimEnd","toString","toLowerCase","toUpperCase","normalize","valueOf"]);exports.STEERABILITY_PRESERVING_FUNCTIONS=new Set(["decodeURI","decodeURIComponent","unescape","String"]);function staticProperty(node){if(!node.computed){return node.property.type==="Identifier"?node.property.name:null}return node.property.type==="Literal"&&typeof node.property.value==="string"?node.property.value:null}function resolveBoundInitializer(identifier,sourceCode){const init=(0,resolve_binding_1.resolveInitializer)(identifier,sourceCode);if(init===void 0)return void 0;const declarator=init.parent;if(declarator?.type==="VariableDeclarator"&&declarator.id.type!=="Identifier"){return void 0}return init}function isSteerableMember(node){const property=staticProperty(node);if(property===null){return isRequestInput(node)}if(STEERABLE_LOCATION_PROPS.has(property)&&isLocationObject(node.object)){return true}if((property==="URL"||property==="referrer")&&node.object.type==="Identifier"&&node.object.name==="document"){return true}return isRequestInput(node)}const URL_CONSTRUCTORS=new Set(["URL"]);const PARAMS_CONSTRUCTORS=new Set(["URLSearchParams"]);const PARAMS_READERS=new Set(["get","getAll"]);const URL_STRINGIFIERS=new Set(["toString","toJSON","valueOf"]);function isUnshadowedGlobal(node,names,sourceCode){if(node.type!=="Identifier"||!names.has(node.name))return false;for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function urlContainerKind(node,sourceCode,seen){switch(node.type){case"NewExpression":{const[argument]=node.arguments;if(argument===void 0||argument.type==="SpreadElement"){return null}if(!isAttackerSteerableUrl(argument,sourceCode,seen))return null;if(isUnshadowedGlobal(node.callee,PARAMS_CONSTRUCTORS,sourceCode)){return"params"}if(isUnshadowedGlobal(node.callee,URL_CONSTRUCTORS,sourceCode)){return"url"}return null}case"MemberExpression":{if(staticProperty(node)!=="searchParams"){return null}return urlContainerKind(node.object,sourceCode,seen)==="url"?"params":null}case"Identifier":{if(seen.has(node.name))return null;seen.add(node.name);const init=resolveBoundInitializer(node,sourceCode);return init===void 0?null:urlContainerKind(init,sourceCode,seen)}default:return null}}function isUrlContainerRead(node,sourceCode,seen){const probe=new Set(seen);if(node.type==="CallExpression"){const callee=node.callee;if(callee.type!=="MemberExpression")return false;const reader=staticProperty(callee);if(reader===null)return false;const kind=urlContainerKind(callee.object,sourceCode,probe);if(kind==="params")return PARAMS_READERS.has(reader);return kind==="url"&&URL_STRINGIFIERS.has(reader)}const property=staticProperty(node);return property!==null&&STEERABLE_LOCATION_PROPS.has(property)&&urlContainerKind(node.object,sourceCode,probe)==="url"}function isAttackerSteerableUrl(node,sourceCode,seen=new Set){switch(node.type){case"MemberExpression":return isSteerableMember(node)||isUrlContainerRead(node,sourceCode,seen);case"Identifier":{if(seen.has(node.name))return false;seen.add(node.name);const init=resolveBoundInitializer(node,sourceCode);return init!==void 0&&isAttackerSteerableUrl(init,sourceCode,seen)}case"BinaryExpression":return node.operator==="+"&&isAttackerSteerableUrl(node.left,sourceCode,seen);case"TemplateLiteral":return node.quasis[0].value.cooked===""&&node.expressions.length>0&&isAttackerSteerableUrl(node.expressions[0],sourceCode,seen);case"CallExpression":{if(isUrlContainerRead(node,sourceCode,seen))return true;const callee=node.callee;if(callee.type==="MemberExpression"&&!callee.computed&&callee.property.type==="Identifier"&&exports.STEERABILITY_PRESERVING_METHODS.has(callee.property.name)){return isAttackerSteerableUrl(callee.object,sourceCode,seen)}if(callee.type==="Identifier"&&exports.STEERABILITY_PRESERVING_FUNCTIONS.has(callee.name)&&node.arguments.length>0){return isAttackerSteerableUrl(node.arguments[0],sourceCode,seen)}return false}case"ConditionalExpression":return isAttackerSteerableUrl(node.consequent,sourceCode,seen)||isAttackerSteerableUrl(node.alternate,sourceCode,seen);case"LogicalExpression":return isAttackerSteerableUrl(node.left,sourceCode,seen)||isAttackerSteerableUrl(node.right,sourceCode,seen);default:return false}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.STEERABILITY_PRESERVING_FUNCTIONS=exports.STEERABILITY_PRESERVING_METHODS=void 0;exports.isLocationObject=isLocationObject;exports.resolveBoundInitializer=resolveBoundInitializer;exports.isAttackerSteerableUrl=isAttackerSteerableUrl;const resolve_binding_1=require("./resolve-binding");const STEERABLE_LOCATION_PROPS=new Set(["href","search","hash","pathname"]);const LOCATION_HOLDERS=new Set(["window","document","self","top","parent","globalThis"]);const REQUEST_INPUT_PROPS=new Set(["query","body","params"]);function isLocationObject(node){if(node.type==="Identifier"){return node.name==="location"}return node.type==="MemberExpression"&&!node.computed&&node.property.type==="Identifier"&&node.property.name==="location"&&node.object.type==="Identifier"&&LOCATION_HOLDERS.has(node.object.name)}function isRequestInput(node){let current=node;let sawInputProp=false;while(current.type==="MemberExpression"){const property=staticProperty(current);if(property!==null&&REQUEST_INPUT_PROPS.has(property)){sawInputProp=true}current=current.object}return sawInputProp&&current.type==="Identifier"&&(current.name==="req"||current.name==="request")}exports.STEERABILITY_PRESERVING_METHODS=new Set(["slice","substring","substr","trim","trimStart","trimEnd","toString","toLowerCase","toUpperCase","normalize","valueOf"]);exports.STEERABILITY_PRESERVING_FUNCTIONS=new Set(["decodeURI","decodeURIComponent","unescape","String"]);function staticProperty(node){if(!node.computed){return node.property.type==="Identifier"?node.property.name:null}return node.property.type==="Literal"&&typeof node.property.value==="string"?node.property.value:null}function resolveBoundInitializer(identifier,sourceCode){const init=(0,resolve_binding_1.resolveInitializer)(identifier,sourceCode);if(init===void 0)return void 0;const declarator=init.parent;if(declarator?.type==="VariableDeclarator"&&declarator.id.type!=="Identifier"){return void 0}return init}function isSteerableMember(node){const property=staticProperty(node);if(property===null){return isRequestInput(node)}if(STEERABLE_LOCATION_PROPS.has(property)&&isLocationObject(node.object)){return true}if((property==="URL"||property==="referrer")&&node.object.type==="Identifier"&&node.object.name==="document"){return true}return isRequestInput(node)}const URL_CONSTRUCTORS=new Set(["URL"]);const PARAMS_CONSTRUCTORS=new Set(["URLSearchParams"]);const PARAMS_READERS=new Set(["get","getAll"]);const URL_STRINGIFIERS=new Set(["toString","toJSON","valueOf"]);function isUnshadowedGlobal(node,names,sourceCode){if(node.type!=="Identifier"||!names.has(node.name))return false;for(let scope=sourceCode.getScope(node);scope!==null;scope=scope.upper){const variable=scope.variables.find(v=>v.name===node.name);if(variable!==void 0)return variable.defs.length===0}return true}function urlContainerKind(node,sourceCode,seen){switch(node.type){case"NewExpression":{const[argument]=node.arguments;if(argument===void 0||argument.type==="SpreadElement"){return null}if(!isAttackerSteerableUrl(argument,sourceCode,seen))return null;if(isUnshadowedGlobal(node.callee,PARAMS_CONSTRUCTORS,sourceCode)){return"params"}if(isUnshadowedGlobal(node.callee,URL_CONSTRUCTORS,sourceCode)){return"url"}return null}case"MemberExpression":{if(staticProperty(node)!=="searchParams"){return null}return urlContainerKind(node.object,sourceCode,seen)==="url"?"params":null}case"Identifier":{if(seen.has(node.name))return null;seen.add(node.name);const init=resolveBoundInitializer(node,sourceCode);return init===void 0?null:urlContainerKind(init,sourceCode,seen)}default:return null}}function isUrlContainerRead(node,sourceCode,seen){const probe=new Set(seen);if(node.type==="CallExpression"){const callee=node.callee;if(callee.type!=="MemberExpression")return false;const reader=staticProperty(callee);if(reader===null)return false;const kind=urlContainerKind(callee.object,sourceCode,probe);if(kind==="params")return PARAMS_READERS.has(reader);return kind==="url"&&URL_STRINGIFIERS.has(reader)}const property=staticProperty(node);return property!==null&&STEERABLE_LOCATION_PROPS.has(property)&&urlContainerKind(node.object,sourceCode,probe)==="url"}function isAttackerSteerableUrl(node,sourceCode,seen=new Set){switch(node.type){case"MemberExpression":return isSteerableMember(node)||isUrlContainerRead(node,sourceCode,seen);case"Identifier":{if(seen.has(node.name))return false;seen.add(node.name);const init=resolveBoundInitializer(node,sourceCode);return init!==void 0&&isAttackerSteerableUrl(init,sourceCode,seen)}case"BinaryExpression":return node.operator==="+"&&isAttackerSteerableUrl(node.left,sourceCode,seen);case"TemplateLiteral":return node.quasis[0].value.cooked===""&&node.expressions.length>0&&isAttackerSteerableUrl(node.expressions[0],sourceCode,seen);case"CallExpression":{if(isUrlContainerRead(node,sourceCode,seen))return true;const callee=node.callee;if(callee.type==="MemberExpression"&&exports.STEERABILITY_PRESERVING_METHODS.has(staticProperty(callee)??"")){return isAttackerSteerableUrl(callee.object,sourceCode,seen)}if(callee.type==="Identifier"&&exports.STEERABILITY_PRESERVING_FUNCTIONS.has(callee.name)&&node.arguments.length>0){return isAttackerSteerableUrl(node.arguments[0],sourceCode,seen)}return false}case"ConditionalExpression":return isAttackerSteerableUrl(node.consequent,sourceCode,seen)||isAttackerSteerableUrl(node.alternate,sourceCode,seen);case"LogicalExpression":return isAttackerSteerableUrl(node.left,sourceCode,seen)||isAttackerSteerableUrl(node.right,sourceCode,seen);default:return false}}