eslint-plugin-browser-security 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-browser-security",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "ESLint plugin for browser security — detects DOM XSS, postMessage abuse, tokens in localStorage, insecure cookies, clickjacking, mixed content, and CSP gaps.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -74,7 +74,7 @@
74
74
  "node": ">=18.0.0"
75
75
  },
76
76
  "dependencies": {
77
- "@interlace/eslint-devkit": "^1.19.0"
77
+ "@interlace/eslint-devkit": "^1.19.1"
78
78
  },
79
79
  "peerDependencies": {
80
80
  "eslint": "^8.40.0 || ^9.0.0 || ^10.0.0"
package/src/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.rules={get"no-innerhtml"(){return require("./rules/no-innerhtml").noInnerhtml},get"no-eval"(){return require("./rules/no-eval").noEval},get"require-postmessage-origin-check"(){return require("./rules/require-postmessage-origin-check").requirePostmessageOriginCheck},get"no-postmessage-wildcard-origin"(){return require("./rules/no-postmessage-wildcard-origin").noPostmessageWildcardOrigin},get"no-postmessage-innerhtml"(){return require("./rules/no-postmessage-innerhtml").noPostmessageInnerhtml},get"no-sensitive-localstorage"(){return require("./rules/no-sensitive-localstorage").noSensitiveLocalstorage},get"no-jwt-in-storage"(){return require("./rules/no-jwt-in-storage").noJwtInStorage},get"no-sensitive-sessionstorage"(){return require("./rules/no-sensitive-sessionstorage").noSensitiveSessionstorage},get"no-sensitive-indexeddb"(){return require("./rules/no-sensitive-indexeddb").noSensitiveIndexeddb},get"no-sensitive-cookie-js"(){return require("./rules/no-sensitive-cookie-js").noSensitiveCookieJs},get"no-cookie-auth-tokens"(){return require("./rules/no-cookie-auth-tokens").noCookieAuthTokens},get"require-cookie-secure-attrs"(){return require("./rules/require-cookie-secure-attrs").requireCookieSecureAttrs},get"require-websocket-wss"(){return require("./rules/require-websocket-wss").requireWebsocketWss},get"no-websocket-innerhtml"(){return require("./rules/no-websocket-innerhtml").noWebsocketInnerhtml},get"no-websocket-eval"(){return require("./rules/no-websocket-eval").noWebsocketEval},get"no-filereader-innerhtml"(){return require("./rules/no-filereader-innerhtml").noFilereaderInnerhtml},get"require-blob-url-revocation"(){return require("./rules/require-blob-url-revocation").requireBlobUrlRevocation},get"no-dynamic-service-worker-url"(){return require("./rules/no-dynamic-service-worker-url").noDynamicServiceWorkerUrl},get"no-worker-message-innerhtml"(){return require("./rules/no-worker-message-innerhtml").noWorkerMessageInnerhtml},get"no-unsafe-inline-csp"(){return require("./rules/no-unsafe-inline-csp").noUnsafeInlineCsp},get"no-unsafe-eval-csp"(){return require("./rules/no-unsafe-eval-csp").noUnsafeEvalCsp},get"detect-mixed-content"(){return require("./rules/detect-mixed-content").detectMixedContent},get"no-allow-arbitrary-loads"(){return require("./rules/no-allow-arbitrary-loads").noAllowArbitraryLoads},get"no-clickjacking"(){return require("./rules/no-clickjacking").noClickjacking},get"no-credentials-in-query-params"(){return require("./rules/no-credentials-in-query-params").noCredentialsInQueryParams},get"no-http-urls"(){return require("./rules/no-http-urls").noHttpUrls},get"no-incomplete-url-sanitization"(){return require("./rules/no-incomplete-url-sanitization").noIncompleteUrlSanitization},get"no-insecure-redirects"(){return require("./rules/no-insecure-redirects").noInsecureRedirects},get"no-insecure-websocket"(){return require("./rules/no-insecure-websocket").noInsecureWebsocket},get"no-missing-cors-check"(){return require("./rules/no-missing-cors-check").noMissingCorsCheck},get"no-missing-csrf-protection"(){return require("./rules/no-missing-csrf-protection").noMissingCsrfProtection},get"no-missing-security-headers"(){return require("./rules/no-missing-security-headers").noMissingSecurityHeaders},get"no-password-in-url"(){return require("./rules/no-password-in-url").noPasswordInUrl},get"no-permissive-cors"(){return require("./rules/no-permissive-cors").noPermissiveCors},get"no-sensitive-data-in-analytics"(){return require("./rules/no-sensitive-data-in-analytics").noSensitiveDataInAnalytics},get"no-sensitive-data-in-cache"(){return require("./rules/no-sensitive-data-in-cache").noSensitiveDataInCache},get"no-tracking-without-consent"(){return require("./rules/no-tracking-without-consent").noTrackingWithoutConsent},get"no-unencrypted-transmission"(){return require("./rules/no-unencrypted-transmission").noUnencryptedTransmission},get"no-unescaped-url-parameter"(){return require("./rules/no-unescaped-url-parameter").noUnescapedUrlParameter},get"no-unvalidated-deeplinks"(){return require("./rules/no-unvalidated-deeplinks").noUnvalidatedDeeplinks},get"require-csp-headers"(){return require("./rules/require-csp-headers").requireCspHeaders},get"require-https-only"(){return require("./rules/require-https-only").requireHttpsOnly},get"require-url-validation"(){return require("./rules/require-url-validation").requireUrlValidation},get"require-mime-type-validation"(){return require("./rules/require-mime-type-validation").requireMimeTypeValidation},get"no-disabled-certificate-validation"(){return require("./rules/no-disabled-certificate-validation").noDisabledCertificateValidation},get"no-client-side-auth-logic"(){return require("./rules/no-client-side-auth-logic").noClientSideAuthLogic}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-browser-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-browser-security",version:"2.1.2"},rules:exports.rules};const recommendedRules={"browser-security/no-innerhtml":"error","browser-security/no-eval":"error","browser-security/require-postmessage-origin-check":"error","browser-security/no-postmessage-wildcard-origin":"error","browser-security/no-postmessage-innerhtml":"error","browser-security/no-sensitive-localstorage":"error","browser-security/no-jwt-in-storage":"error","browser-security/no-sensitive-sessionstorage":"error","browser-security/no-sensitive-indexeddb":"error","browser-security/no-sensitive-cookie-js":"error","browser-security/no-cookie-auth-tokens":"error","browser-security/require-cookie-secure-attrs":"error","browser-security/require-websocket-wss":"error","browser-security/no-websocket-innerhtml":"error","browser-security/no-websocket-eval":"error","browser-security/no-filereader-innerhtml":"error","browser-security/require-blob-url-revocation":"warn","browser-security/no-dynamic-service-worker-url":"error","browser-security/no-worker-message-innerhtml":"error","browser-security/no-unsafe-inline-csp":"error","browser-security/no-unsafe-eval-csp":"error","browser-security/detect-mixed-content":"error","browser-security/no-unencrypted-transmission":"error","browser-security/no-allow-arbitrary-loads":"error","browser-security/no-credentials-in-query-params":"error","browser-security/no-http-urls":"error","browser-security/no-incomplete-url-sanitization":"error","browser-security/no-insecure-redirects":"error","browser-security/no-disabled-certificate-validation":"error","browser-security/require-https-only":"error","browser-security/no-insecure-websocket":"error","browser-security/no-unvalidated-deeplinks":"error","browser-security/no-client-side-auth-logic":"error"};exports.configs={flagship:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-postmessage-wildcard-origin":"error"}},recommended:{plugins:{"browser-security":exports.plugin},rules:recommendedRules},strict:{plugins:{"browser-security":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`browser-security/${ruleName}`,"error"]))},xss:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-innerhtml":"error","browser-security/no-eval":"error"}},storage:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-sensitive-localstorage":"error"}},postmessage:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/require-postmessage-origin-check":"error","browser-security/no-postmessage-wildcard-origin":"error"}},websocket:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/require-websocket-wss":"error"}},cookies:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-sensitive-cookie-js":"error"}}};exports.default=exports.plugin;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.rules={get"no-innerhtml"(){return require("./rules/no-innerhtml").noInnerhtml},get"no-eval"(){return require("./rules/no-eval").noEval},get"require-postmessage-origin-check"(){return require("./rules/require-postmessage-origin-check").requirePostmessageOriginCheck},get"no-postmessage-wildcard-origin"(){return require("./rules/no-postmessage-wildcard-origin").noPostmessageWildcardOrigin},get"no-postmessage-innerhtml"(){return require("./rules/no-postmessage-innerhtml").noPostmessageInnerhtml},get"no-sensitive-localstorage"(){return require("./rules/no-sensitive-localstorage").noSensitiveLocalstorage},get"no-jwt-in-storage"(){return require("./rules/no-jwt-in-storage").noJwtInStorage},get"no-sensitive-sessionstorage"(){return require("./rules/no-sensitive-sessionstorage").noSensitiveSessionstorage},get"no-sensitive-indexeddb"(){return require("./rules/no-sensitive-indexeddb").noSensitiveIndexeddb},get"no-sensitive-cookie-js"(){return require("./rules/no-sensitive-cookie-js").noSensitiveCookieJs},get"no-cookie-auth-tokens"(){return require("./rules/no-cookie-auth-tokens").noCookieAuthTokens},get"require-cookie-secure-attrs"(){return require("./rules/require-cookie-secure-attrs").requireCookieSecureAttrs},get"require-websocket-wss"(){return require("./rules/require-websocket-wss").requireWebsocketWss},get"no-websocket-innerhtml"(){return require("./rules/no-websocket-innerhtml").noWebsocketInnerhtml},get"no-websocket-eval"(){return require("./rules/no-websocket-eval").noWebsocketEval},get"no-filereader-innerhtml"(){return require("./rules/no-filereader-innerhtml").noFilereaderInnerhtml},get"require-blob-url-revocation"(){return require("./rules/require-blob-url-revocation").requireBlobUrlRevocation},get"no-dynamic-service-worker-url"(){return require("./rules/no-dynamic-service-worker-url").noDynamicServiceWorkerUrl},get"no-worker-message-innerhtml"(){return require("./rules/no-worker-message-innerhtml").noWorkerMessageInnerhtml},get"no-unsafe-inline-csp"(){return require("./rules/no-unsafe-inline-csp").noUnsafeInlineCsp},get"no-unsafe-eval-csp"(){return require("./rules/no-unsafe-eval-csp").noUnsafeEvalCsp},get"detect-mixed-content"(){return require("./rules/detect-mixed-content").detectMixedContent},get"no-allow-arbitrary-loads"(){return require("./rules/no-allow-arbitrary-loads").noAllowArbitraryLoads},get"no-clickjacking"(){return require("./rules/no-clickjacking").noClickjacking},get"no-credentials-in-query-params"(){return require("./rules/no-credentials-in-query-params").noCredentialsInQueryParams},get"no-http-urls"(){return require("./rules/no-http-urls").noHttpUrls},get"no-incomplete-url-sanitization"(){return require("./rules/no-incomplete-url-sanitization").noIncompleteUrlSanitization},get"no-insecure-redirects"(){return require("./rules/no-insecure-redirects").noInsecureRedirects},get"no-insecure-websocket"(){return require("./rules/no-insecure-websocket").noInsecureWebsocket},get"no-missing-cors-check"(){return require("./rules/no-missing-cors-check").noMissingCorsCheck},get"no-missing-csrf-protection"(){return require("./rules/no-missing-csrf-protection").noMissingCsrfProtection},get"no-missing-security-headers"(){return require("./rules/no-missing-security-headers").noMissingSecurityHeaders},get"no-password-in-url"(){return require("./rules/no-password-in-url").noPasswordInUrl},get"no-permissive-cors"(){return require("./rules/no-permissive-cors").noPermissiveCors},get"no-sensitive-data-in-analytics"(){return require("./rules/no-sensitive-data-in-analytics").noSensitiveDataInAnalytics},get"no-sensitive-data-in-cache"(){return require("./rules/no-sensitive-data-in-cache").noSensitiveDataInCache},get"no-tracking-without-consent"(){return require("./rules/no-tracking-without-consent").noTrackingWithoutConsent},get"no-unencrypted-transmission"(){return require("./rules/no-unencrypted-transmission").noUnencryptedTransmission},get"no-unescaped-url-parameter"(){return require("./rules/no-unescaped-url-parameter").noUnescapedUrlParameter},get"no-unvalidated-deeplinks"(){return require("./rules/no-unvalidated-deeplinks").noUnvalidatedDeeplinks},get"require-csp-headers"(){return require("./rules/require-csp-headers").requireCspHeaders},get"require-https-only"(){return require("./rules/require-https-only").requireHttpsOnly},get"require-url-validation"(){return require("./rules/require-url-validation").requireUrlValidation},get"require-mime-type-validation"(){return require("./rules/require-mime-type-validation").requireMimeTypeValidation},get"no-disabled-certificate-validation"(){return require("./rules/no-disabled-certificate-validation").noDisabledCertificateValidation},get"no-client-side-auth-logic"(){return require("./rules/no-client-side-auth-logic").noClientSideAuthLogic}};(0,eslint_devkit_1.withCanonicalDocsUrls)("plugin-browser-security",exports.rules);exports.plugin={meta:{name:"eslint-plugin-browser-security",version:"2.1.3"},rules:exports.rules};const recommendedRules={"browser-security/no-innerhtml":"error","browser-security/no-eval":"error","browser-security/require-postmessage-origin-check":"error","browser-security/no-postmessage-wildcard-origin":"error","browser-security/no-postmessage-innerhtml":"error","browser-security/no-sensitive-localstorage":"error","browser-security/no-jwt-in-storage":"error","browser-security/no-sensitive-sessionstorage":"error","browser-security/no-sensitive-indexeddb":"error","browser-security/no-sensitive-cookie-js":"error","browser-security/no-cookie-auth-tokens":"error","browser-security/require-cookie-secure-attrs":"error","browser-security/require-websocket-wss":"error","browser-security/no-websocket-innerhtml":"error","browser-security/no-websocket-eval":"error","browser-security/no-filereader-innerhtml":"error","browser-security/require-blob-url-revocation":"warn","browser-security/no-dynamic-service-worker-url":"error","browser-security/no-worker-message-innerhtml":"error","browser-security/no-unsafe-inline-csp":"error","browser-security/no-unsafe-eval-csp":"error","browser-security/detect-mixed-content":"error","browser-security/no-unencrypted-transmission":"error","browser-security/no-allow-arbitrary-loads":"error","browser-security/no-credentials-in-query-params":"error","browser-security/no-http-urls":"error","browser-security/no-incomplete-url-sanitization":"error","browser-security/no-insecure-redirects":"error","browser-security/no-disabled-certificate-validation":"error","browser-security/require-https-only":"error","browser-security/no-insecure-websocket":"error","browser-security/no-unvalidated-deeplinks":"error","browser-security/no-client-side-auth-logic":"error"};exports.configs={flagship:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-postmessage-wildcard-origin":"error"}},recommended:{plugins:{"browser-security":exports.plugin},rules:recommendedRules},strict:{plugins:{"browser-security":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`browser-security/${ruleName}`,"error"]))},xss:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-innerhtml":"error","browser-security/no-eval":"error"}},storage:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-sensitive-localstorage":"error"}},postmessage:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/require-postmessage-origin-check":"error","browser-security/no-postmessage-wildcard-origin":"error"}},websocket:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/require-websocket-wss":"error"}},cookies:{plugins:{"browser-security":exports.plugin},rules:{"browser-security/no-sensitive-cookie-js":"error"}}};exports.default=exports.plugin;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectMixedContent=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const namespace_uris_1=require("../../utils/namespace-uris");const transport_ownership_1=require("../../utils/transport-ownership");const CLEARTEXT_SCHEME=/^http:\/\//i;exports.detectMixedContent=(0,eslint_devkit_1.createRule)({name:"detect-mixed-content",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/detect-mixed-content.md",description:"Detect HTTP resources in HTTPS pages",cwe:"CWE-311",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-311",description:"Detect HTTP resources in HTTPS pages detected - Literal containing http:// in HTTPS context",severity:"MEDIUM",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/311.html"})},schema:[]},defaultOptions:[],create(context){return{TemplateLiteral(node){const cooked=node.quasis[0]?.value.cooked;if(cooked!==void 0&&CLEARTEXT_SCHEME.test(cooked)&&!(0,namespace_uris_1.isTrustworthyLocalUrl)(cooked)&&(0,transport_ownership_1.isSubresourcePosition)(node)){context.report({node,messageId:"violationDetected"})}},Literal(node){if(typeof node.value!=="string"||!CLEARTEXT_SCHEME.test(node.value)){return}if(!(0,transport_ownership_1.isSubresourcePosition)(node)){return}if((0,namespace_uris_1.isTrustworthyLocalUrl)(node.value)){return}context.report({node,messageId:"violationDetected"})}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectMixedContent=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const namespace_uris_1=require("../../utils/namespace-uris");const transport_ownership_1=require("../../utils/transport-ownership");const CLEARTEXT_SCHEME=/^http:\/\//i;exports.detectMixedContent=(0,eslint_devkit_1.createRule)({name:"detect-mixed-content",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/detect-mixed-content.md",description:"Detect HTTP resources in HTTPS pages",cwe:"CWE-311",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-311",description:"Detect HTTP resources in HTTPS pages detected - Literal containing http:// in HTTPS context",severity:"MEDIUM",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/311.html"})},schema:[]},defaultOptions:[],create(context){return{TemplateLiteral(node){const cooked=node.quasis[0]?.value.cooked;if(cooked!=null&&CLEARTEXT_SCHEME.test(cooked)&&!(0,namespace_uris_1.isTrustworthyLocalUrl)(cooked)&&(0,transport_ownership_1.isSubresourcePosition)(node)){context.report({node,messageId:"violationDetected"})}},Literal(node){if(typeof node.value!=="string"||!CLEARTEXT_SCHEME.test(node.value)){return}if(!(0,transport_ownership_1.isSubresourcePosition)(node)){return}if((0,namespace_uris_1.isTrustworthyLocalUrl)(node.value)){return}context.report({node,messageId:"violationDetected"})}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHttpUrls=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const namespace_uris_1=require("../../utils/namespace-uris");const loopback_hosts_1=require("../../utils/loopback-hosts");const protocol_inspection_1=require("../../utils/protocol-inspection");const transport_ownership_1=require("../../utils/transport-ownership");const DEFAULT_ALLOWED_HOSTS=["localhost","127.0.0.1"];exports.noHttpUrls=(0,eslint_devkit_1.createRule)({name:"no-http-urls",skipTestFiles:true,meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-http-urls.md",description:"Disallow hardcoded HTTP URLs (require HTTPS)",cwe:"CWE-319",cvss:7.5},messages:{insecureHttp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:7.5,description:'Hardcoded HTTP URL detected: "{{url}}"',severity:"HIGH",compliance:["SOC2","PCI-DSS","HIPAA"],fix:'Use HTTPS instead: const url = "https://..."',documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),insecureHttpWithException:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:5.3,description:'HTTP URL detected: "{{url}}"',severity:"MEDIUM",fix:"Use HTTPS or add to allowedHosts config",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"})},schema:[{type:"object",properties:{allowedHosts:{type:"array",items:{type:"string"},default:DEFAULT_ALLOWED_HOSTS,description:"List of hostnames allowed to use HTTP (e.g., localhost, 127.0.0.1)"},allowedPorts:{type:"array",items:{type:"number"},default:[],description:"List of ports allowed for HTTP (e.g., 3000, 8080 for development)"}},additionalProperties:false}]},defaultOptions:[{allowedHosts:DEFAULT_ALLOWED_HOSTS,allowedPorts:[]}],create(context){const[options={}]=context.options;const allowedHosts=options.allowedHosts??DEFAULT_ALLOWED_HOSTS;const allowedPorts=options.allowedPorts??[];function isAllowedException(url){try{const parsedUrl=new URL(url);if(allowedHosts.includes(parsedUrl.hostname)){return true}if(parsedUrl.port&&allowedPorts.includes(parseInt(parsedUrl.port,10))){return true}return false}catch{return allowedHosts.some(host=>url.includes(host))}}function declarationName(node){const parent=node.parent;if(parent.type==="JSXAttribute"){const name=parent.name;return name.type==="JSXIdentifier"?name.name:`${name.namespace.name}:${name.name.name}`}if(parent.type==="Property"&&parent.value===node&&!parent.computed){if(parent.key.type==="Identifier")return parent.key.name;const staticText=(0,eslint_devkit_1.staticString)(parent.key);if(staticText!==null){return staticText}}return void 0}function hasInterpolatedAuthority(node,cooked){const rest=/^http:\/\/(.*)$/is.exec(cooked)?.[1];if(rest===void 0)return false;const authority=rest.split(/[/?#]/)[0];if(authority!=="")return false;return!node.tail}function checkStringValue(node,value){const httpPattern=/^http:\/\//i;if((0,namespace_uris_1.isXmlNamespaceUri)(value,declarationName(node))){return}if((0,namespace_uris_1.isTrustworthyLocalUrl)(value)){return}{const parent=node.parent;if(parent!==void 0&&(0,protocol_inspection_1.isProtocolInspection)(node,parent)){return}}if((0,loopback_hosts_1.isReservedExampleUrl)(value)){return}if((0,namespace_uris_1.isDiscardedUrlBase)(node)){return}if((0,transport_ownership_1.isRequestCallSiteUrl)(node,context.sourceCode.getScope(node))||(0,transport_ownership_1.isSubresourcePosition)(node)){return}if(httpPattern.test(value)&&!/^http:\/\/[^/?#]/i.test(value)){return}if(httpPattern.test(value)&&!isAllowedException(value)){context.report({node,messageId:allowedHosts.length>0||allowedPorts.length>0?"insecureHttpWithException":"insecureHttp",data:{url:value}})}}return{Literal(node){if(typeof node.value==="string"){checkStringValue(node,node.value)}},TemplateElement(node){const cooked=node.value.cooked;if(cooked&&!hasInterpolatedAuthority(node,cooked)){checkStringValue(node,cooked)}}}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHttpUrls=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const namespace_uris_1=require("../../utils/namespace-uris");const loopback_hosts_1=require("../../utils/loopback-hosts");const protocol_inspection_1=require("../../utils/protocol-inspection");const transport_ownership_1=require("../../utils/transport-ownership");const DEFAULT_ALLOWED_HOSTS=["localhost","127.0.0.1"];exports.noHttpUrls=(0,eslint_devkit_1.createRule)({name:"no-http-urls",skipTestFiles:true,meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-http-urls.md",description:"Disallow hardcoded HTTP URLs (require HTTPS)",cwe:"CWE-319",cvss:7.5},messages:{insecureHttp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:7.5,description:'Hardcoded HTTP URL detected: "{{url}}"',severity:"HIGH",compliance:["SOC2","PCI-DSS","HIPAA"],fix:'Use HTTPS instead: const url = "https://..."',documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),insecureHttpWithException:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:5.3,description:'HTTP URL detected: "{{url}}"',severity:"MEDIUM",fix:"Use HTTPS or add to allowedHosts config",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"})},schema:[{type:"object",properties:{allowedHosts:{type:"array",items:{type:"string"},default:DEFAULT_ALLOWED_HOSTS,description:"List of hostnames allowed to use HTTP (e.g., localhost, 127.0.0.1)"},allowedPorts:{type:"array",items:{type:"number"},default:[],description:"List of ports allowed for HTTP (e.g., 3000, 8080 for development)"}},additionalProperties:false}]},defaultOptions:[{allowedHosts:DEFAULT_ALLOWED_HOSTS,allowedPorts:[]}],create(context){const[options={}]=context.options;const allowedHosts=options.allowedHosts??DEFAULT_ALLOWED_HOSTS;const allowedPorts=options.allowedPorts??[];function isAllowedException(url){try{const parsedUrl=new URL(url);if(allowedHosts.includes(parsedUrl.hostname)){return true}if(parsedUrl.port&&allowedPorts.includes(parseInt(parsedUrl.port,10))){return true}return false}catch{return allowedHosts.some(host=>url.includes(host))}}function declarationName(node){const parent=node.parent;if(parent.type==="JSXAttribute"){const name=parent.name;return name.type==="JSXIdentifier"?name.name:`${name.namespace.name}:${name.name.name}`}if(parent.type===eslint_devkit_1.AST_NODE_TYPES.Property&&parent.value===node){const name=(0,eslint_devkit_1.objectKeyName)(parent);if(name!==null)return name}return void 0}function hasInterpolatedAuthority(node,cooked){const rest=/^http:\/\/(.*)$/is.exec(cooked)?.[1];if(rest===void 0)return false;const authority=rest.split(/[/?#]/)[0];if(authority!=="")return false;return!node.tail}function checkStringValue(node,value){const httpPattern=/^http:\/\//i;if((0,namespace_uris_1.isXmlNamespaceUri)(value,declarationName(node))){return}if((0,namespace_uris_1.isTrustworthyLocalUrl)(value)){return}{const parent=node.parent;if(parent!==void 0&&(0,protocol_inspection_1.isProtocolInspection)(node,parent)){return}}if((0,loopback_hosts_1.isReservedExampleUrl)(value)){return}if((0,namespace_uris_1.isDiscardedUrlBase)(node)){return}if((0,transport_ownership_1.isRequestCallSiteUrl)(node,context.sourceCode.getScope(node))||(0,transport_ownership_1.isSubresourcePosition)(node)){return}if(httpPattern.test(value)&&!/^http:\/\/[^/?#]/i.test(value)){return}if(httpPattern.test(value)&&!isAllowedException(value)){context.report({node,messageId:allowedHosts.length>0||allowedPorts.length>0?"insecureHttpWithException":"insecureHttp",data:{url:value}})}}return{Literal(node){if(typeof node.value==="string"){checkStringValue(node,node.value)}},TemplateElement(node){const cooked=node.value.cooked??node.value.raw;if(cooked&&!hasInterpolatedAuthority(node,cooked)){checkStringValue(node,cooked)}}}}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPasswordInUrl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_URL=/https?:\/\/([^/?#\s'"`<>]*)/gi;const OPAQUE="";function foldUrlText(node,depth=0){if(depth>8)return null;switch(node.type){case"Literal":return typeof node.value==="string"?node.value:null;case"TemplateLiteral":{let text="";node.quasis.forEach((quasi,index)=>{text+=quasi.value.cooked;if(index<node.expressions.length){text+=foldUrlText(node.expressions[index],depth+1)??OPAQUE}});return text}case"BinaryExpression":{if(node.operator!=="+")return null;const left=foldUrlText(node.left,depth+1);const right=foldUrlText(node.right,depth+1);if(left===null&&right===null)return null;return(left??OPAQUE)+(right??OPAQUE)}default:return null}}function hasUserinfoPassword(value){for(const match of value.matchAll(HTTP_URL)){const authority=match[1];const at=authority.lastIndexOf("@");if(at<=0)continue;const userinfo=authority.slice(0,at);const colon=userinfo.indexOf(":");if(colon>0&&colon<userinfo.length-1)return true}return false}exports.noPasswordInUrl=(0,eslint_devkit_1.createRule)({name:"no-password-in-url",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-password-in-url.md",description:"Prevent passwords in URLs",cwe:"CWE-521",cvss:5.3},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-521",description:"Prevent passwords in URLs detected - this is a security risk",severity:"CRITICAL",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/521.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}function isNestedStringPart(node){const parent=node.parent;return parent!==void 0&&(parent.type==="BinaryExpression"&&parent.operator==="+"||parent.type==="TemplateLiteral")}function check(node){if(isNestedStringPart(node))return;const text=foldUrlText(node);if(text!==null&&hasUserinfoPassword(text)){report(node)}}return{Literal:check,TemplateLiteral:check,BinaryExpression:check}}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPasswordInUrl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_URL=/https?:\/\/([^/?#\s'"`<>]*)/gi;const OPAQUE="";function foldUrlText(node,depth=0){if(depth>8)return null;switch(node.type){case"Literal":return typeof node.value==="string"?node.value:null;case"TemplateLiteral":{let text="";node.quasis.forEach((quasi,index)=>{text+=quasi.value.cooked??quasi.value.raw;if(index<node.expressions.length){text+=foldUrlText(node.expressions[index],depth+1)??OPAQUE}});return text}case"BinaryExpression":{if(node.operator!=="+")return null;const left=foldUrlText(node.left,depth+1);const right=foldUrlText(node.right,depth+1);if(left===null&&right===null)return null;return(left??OPAQUE)+(right??OPAQUE)}default:return null}}function hasUserinfoPassword(value){for(const match of value.matchAll(HTTP_URL)){const authority=match[1];const at=authority.lastIndexOf("@");if(at<=0)continue;const userinfo=authority.slice(0,at);const colon=userinfo.indexOf(":");if(colon>0&&colon<userinfo.length-1)return true}return false}exports.noPasswordInUrl=(0,eslint_devkit_1.createRule)({name:"no-password-in-url",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-password-in-url.md",description:"Prevent passwords in URLs",cwe:"CWE-521",cvss:5.3},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-521",description:"Prevent passwords in URLs detected - this is a security risk",severity:"CRITICAL",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/521.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}function isNestedStringPart(node){const parent=node.parent;return parent!==void 0&&(parent.type==="BinaryExpression"&&parent.operator==="+"||parent.type==="TemplateLiteral")}function check(node){if(isNestedStringPart(node))return;const text=foldUrlText(node);if(text!==null&&hasUserinfoPassword(text)){report(node)}}return{Literal:check,TemplateLiteral:check,BinaryExpression:check}}});
@@ -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"&&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
+ "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.raw===""&&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.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}}
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.raw===""&&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}}