eslint-plugin-browser-security 1.2.13 → 1.2.14
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 +2 -2
- package/src/index.js +1 -159
- package/src/oxlint.js +1 -3
- package/src/rules/detect-mixed-content/index.js +1 -38
- package/src/rules/no-allow-arbitrary-loads/index.js +1 -41
- package/src/rules/no-clickjacking/index.js +1 -361
- package/src/rules/no-client-side-auth-logic/index.js +1 -67
- package/src/rules/no-cookie-auth-tokens/index.js +1 -109
- package/src/rules/no-credentials-in-query-params/index.js +1 -55
- package/src/rules/no-disabled-certificate-validation/index.js +1 -59
- package/src/rules/no-dynamic-service-worker-url/index.js +1 -78
- package/src/rules/no-eval/index.js +1 -160
- package/src/rules/no-filereader-innerhtml/index.js +1 -196
- package/src/rules/no-http-urls/index.js +1 -109
- package/src/rules/no-innerhtml/index.js +1 -150
- package/src/rules/no-insecure-redirects/index.js +1 -238
- package/src/rules/no-insecure-websocket/index.js +1 -57
- package/src/rules/no-jwt-in-storage/index.js +1 -178
- package/src/rules/no-missing-cors-check/index.js +1 -351
- package/src/rules/no-missing-csrf-protection/index.js +1 -165
- package/src/rules/no-missing-security-headers/index.js +1 -197
- package/src/rules/no-password-in-url/index.js +1 -47
- package/src/rules/no-permissive-cors/index.js +1 -65
- package/src/rules/no-postmessage-innerhtml/index.js +1 -161
- package/src/rules/no-postmessage-wildcard-origin/index.js +1 -112
- package/src/rules/no-sensitive-cookie-js/index.js +1 -151
- package/src/rules/no-sensitive-data-in-analytics/index.js +1 -58
- package/src/rules/no-sensitive-data-in-cache/index.js +1 -47
- package/src/rules/no-sensitive-indexeddb/index.js +1 -110
- package/src/rules/no-sensitive-localstorage/index.js +1 -173
- package/src/rules/no-sensitive-sessionstorage/index.js +1 -144
- package/src/rules/no-tracking-without-consent/index.js +1 -65
- package/src/rules/no-unencrypted-transmission/index.js +1 -208
- package/src/rules/no-unescaped-url-parameter/index.js +1 -319
- package/src/rules/no-unsafe-eval-csp/index.js +1 -75
- package/src/rules/no-unsafe-inline-csp/index.js +1 -75
- package/src/rules/no-unvalidated-deeplinks/index.js +1 -59
- package/src/rules/no-websocket-eval/index.js +1 -197
- package/src/rules/no-websocket-innerhtml/index.js +1 -185
- package/src/rules/no-worker-message-innerhtml/index.js +1 -181
- package/src/rules/require-blob-url-revocation/index.js +1 -93
- package/src/rules/require-cookie-secure-attrs/index.js +1 -101
- package/src/rules/require-csp-headers/index.js +1 -59
- package/src/rules/require-https-only/index.js +1 -57
- package/src/rules/require-mime-type-validation/index.js +1 -61
- package/src/rules/require-postmessage-origin-check/index.js +1 -132
- package/src/rules/require-url-validation/index.js +1 -68
- package/src/rules/require-websocket-wss/index.js +1 -125
|
@@ -1,144 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noSensitiveSessionstorage = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const SENSITIVE_PATTERNS = [
|
|
6
|
-
/password/i,
|
|
7
|
-
/passwd/i,
|
|
8
|
-
/secret/i,
|
|
9
|
-
/apikey/i,
|
|
10
|
-
/api[_-]?key/i,
|
|
11
|
-
/private[_-]?key/i,
|
|
12
|
-
/auth[_-]?token/i,
|
|
13
|
-
/access[_-]?token/i,
|
|
14
|
-
/refresh[_-]?token/i,
|
|
15
|
-
/bearer/i,
|
|
16
|
-
/credential/i,
|
|
17
|
-
/ssn/i,
|
|
18
|
-
/social[_-]?security/i,
|
|
19
|
-
/credit[_-]?card/i,
|
|
20
|
-
/card[_-]?number/i,
|
|
21
|
-
/cvv/i,
|
|
22
|
-
/cvc/i,
|
|
23
|
-
/pin/i,
|
|
24
|
-
/encryption[_-]?key/i,
|
|
25
|
-
];
|
|
26
|
-
function isSensitiveKey(key, additionalPatterns = []) {
|
|
27
|
-
const allPatterns = [
|
|
28
|
-
...SENSITIVE_PATTERNS,
|
|
29
|
-
...additionalPatterns.map((p) => new RegExp(p, 'i')),
|
|
30
|
-
];
|
|
31
|
-
return allPatterns.some((pattern) => pattern.test(key));
|
|
32
|
-
}
|
|
33
|
-
exports.noSensitiveSessionstorage = (0, eslint_devkit_1.createRule)({
|
|
34
|
-
name: 'no-sensitive-sessionstorage',
|
|
35
|
-
meta: {
|
|
36
|
-
type: 'problem',
|
|
37
|
-
docs: {
|
|
38
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-sessionstorage.md',
|
|
39
|
-
description: 'Disallow storing sensitive data in sessionStorage',
|
|
40
|
-
cwe: 'CWE-922',
|
|
41
|
-
cvss: 7.5,
|
|
42
|
-
},
|
|
43
|
-
hasSuggestions: true,
|
|
44
|
-
messages: {
|
|
45
|
-
sensitiveInSessionStorage: (0, eslint_devkit_1.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
47
|
-
issueName: 'Sensitive Data in sessionStorage',
|
|
48
|
-
cwe: 'CWE-922',
|
|
49
|
-
owasp: 'A02:2021',
|
|
50
|
-
cvss: 7.5,
|
|
51
|
-
description: 'Storing sensitive data "{{key}}" in sessionStorage exposes it to XSS attacks. Any malicious script can read sessionStorage.',
|
|
52
|
-
severity: 'HIGH',
|
|
53
|
-
fix: 'Store sensitive data in HttpOnly cookies or use secure server-side sessions.',
|
|
54
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#local-storage',
|
|
55
|
-
}),
|
|
56
|
-
useSecureStorage: (0, eslint_devkit_1.formatLLMMessage)({
|
|
57
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
58
|
-
issueName: 'Use Secure Storage',
|
|
59
|
-
description: 'Use HttpOnly cookies or server-side sessions',
|
|
60
|
-
severity: 'LOW',
|
|
61
|
-
fix: 'Server: res.cookie("session", value, { httpOnly: true, secure: true })',
|
|
62
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
|
|
63
|
-
}),
|
|
64
|
-
},
|
|
65
|
-
schema: [
|
|
66
|
-
{
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
allowInTests: { type: 'boolean', default: true },
|
|
70
|
-
additionalPatterns: { type: 'array', items: { type: 'string' }, description: 'Extra key-name patterns to treat as sensitive' },
|
|
71
|
-
},
|
|
72
|
-
additionalProperties: false,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
defaultOptions: [{ allowInTests: true }],
|
|
77
|
-
create(context, [options = {}]) {
|
|
78
|
-
const { allowInTests = true, additionalPatterns = [] } = options;
|
|
79
|
-
const filename = context.filename;
|
|
80
|
-
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
81
|
-
if (allowInTests && isTestFile) {
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
CallExpression(node) {
|
|
86
|
-
const callee = node.callee;
|
|
87
|
-
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
88
|
-
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
89
|
-
callee.object.name === 'sessionStorage' &&
|
|
90
|
-
callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
91
|
-
callee.property.name === 'setItem') {
|
|
92
|
-
const keyArg = node.arguments[0];
|
|
93
|
-
if (!keyArg)
|
|
94
|
-
return;
|
|
95
|
-
let keyValue = null;
|
|
96
|
-
if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
97
|
-
typeof keyArg.value === 'string') {
|
|
98
|
-
keyValue = keyArg.value;
|
|
99
|
-
}
|
|
100
|
-
else if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
101
|
-
keyValue = keyArg.name;
|
|
102
|
-
}
|
|
103
|
-
if (keyValue && isSensitiveKey(keyValue, additionalPatterns)) {
|
|
104
|
-
context.report({
|
|
105
|
-
node,
|
|
106
|
-
messageId: 'sensitiveInSessionStorage',
|
|
107
|
-
data: { key: keyValue },
|
|
108
|
-
suggest: [
|
|
109
|
-
{ messageId: 'useSecureStorage', fix: () => null },
|
|
110
|
-
],
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
AssignmentExpression(node) {
|
|
116
|
-
if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
117
|
-
return;
|
|
118
|
-
const obj = node.left.object;
|
|
119
|
-
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
120
|
-
obj.name !== 'sessionStorage') {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
let keyValue = null;
|
|
124
|
-
if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
125
|
-
typeof node.left.property.value === 'string') {
|
|
126
|
-
keyValue = node.left.property.value;
|
|
127
|
-
}
|
|
128
|
-
else if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
129
|
-
keyValue = node.left.property.name;
|
|
130
|
-
}
|
|
131
|
-
if (keyValue && isSensitiveKey(keyValue, additionalPatterns)) {
|
|
132
|
-
context.report({
|
|
133
|
-
node,
|
|
134
|
-
messageId: 'sensitiveInSessionStorage',
|
|
135
|
-
data: { key: keyValue },
|
|
136
|
-
suggest: [
|
|
137
|
-
{ messageId: 'useSecureStorage', fix: () => null },
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveSessionstorage=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SENSITIVE_PATTERNS=[/password/i,/passwd/i,/secret/i,/apikey/i,/api[_-]?key/i,/private[_-]?key/i,/auth[_-]?token/i,/access[_-]?token/i,/refresh[_-]?token/i,/bearer/i,/credential/i,/ssn/i,/social[_-]?security/i,/credit[_-]?card/i,/card[_-]?number/i,/cvv/i,/cvc/i,/pin/i,/encryption[_-]?key/i];function isSensitiveKey(key,additionalPatterns=[]){const allPatterns=[...SENSITIVE_PATTERNS,...additionalPatterns.map(p=>new RegExp(p,"i"))];return allPatterns.some(pattern=>pattern.test(key))}exports.noSensitiveSessionstorage=(0,eslint_devkit_1.createRule)({name:"no-sensitive-sessionstorage",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-sessionstorage.md",description:"Disallow storing sensitive data in sessionStorage",cwe:"CWE-922",cvss:7.5},hasSuggestions:true,messages:{sensitiveInSessionStorage:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Sensitive Data in sessionStorage",cwe:"CWE-922",owasp:"A02:2021",cvss:7.5,description:'Storing sensitive data "{{key}}" in sessionStorage exposes it to XSS attacks. Any malicious script can read sessionStorage.',severity:"HIGH",fix:"Store sensitive data in HttpOnly cookies or use secure server-side sessions.",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#local-storage"}),useSecureStorage:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Secure Storage",description:"Use HttpOnly cookies or server-side sessions",severity:"LOW",fix:'Server: res.cookie("session", value, { httpOnly: true, secure: true })',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},additionalPatterns:{type:"array",items:{type:"string"},description:"Extra key-name patterns to treat as sensitive"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true,additionalPatterns=[]}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}return{CallExpression(node){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.object.name==="sessionStorage"&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.property.name==="setItem"){const keyArg=node.arguments[0];if(!keyArg)return;let keyValue=null;if(keyArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof keyArg.value==="string"){keyValue=keyArg.value}else if(keyArg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){keyValue=keyArg.name}if(keyValue&&isSensitiveKey(keyValue,additionalPatterns)){context.report({node,messageId:"sensitiveInSessionStorage",data:{key:keyValue},suggest:[{messageId:"useSecureStorage",fix:()=>null}]})}}},AssignmentExpression(node){if(node.left.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return;const obj=node.left.object;if(obj.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||obj.name!=="sessionStorage"){return}let keyValue=null;if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.left.property.value==="string"){keyValue=node.left.property.value}else if(node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){keyValue=node.left.property.name}if(keyValue&&isSensitiveKey(keyValue,additionalPatterns)){context.report({node,messageId:"sensitiveInSessionStorage",data:{key:keyValue},suggest:[{messageId:"useSecureStorage",fix:()=>null}]})}}}}});
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noTrackingWithoutConsent = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noTrackingWithoutConsent = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-tracking-without-consent',
|
|
7
|
-
meta: {
|
|
8
|
-
type: 'problem',
|
|
9
|
-
docs: {
|
|
10
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-tracking-without-consent.md',
|
|
11
|
-
description: 'Require consent before analytics tracking',
|
|
12
|
-
cwe: 'CWE-359',
|
|
13
|
-
cvss: 5,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
18
|
-
issueName: 'Tracking Without Consent',
|
|
19
|
-
cwe: 'CWE-359',
|
|
20
|
-
description: 'Analytics tracking without consent check - violates privacy regulations',
|
|
21
|
-
severity: 'MEDIUM',
|
|
22
|
-
fix: 'Wrap tracking calls in consent check: if (hasConsent) { analytics.track(...) }',
|
|
23
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/359.html',
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
schema: [],
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
function report(node) {
|
|
31
|
-
context.report({ node, messageId: 'violationDetected' });
|
|
32
|
-
}
|
|
33
|
-
function isInsideConsentCheck(node) {
|
|
34
|
-
let current = node.parent;
|
|
35
|
-
while (current) {
|
|
36
|
-
if (current.type === 'IfStatement') {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
if (current.type === 'ConditionalExpression') {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
current = current.parent;
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
CallExpression(node) {
|
|
48
|
-
if (node.callee.type === 'MemberExpression' &&
|
|
49
|
-
node.callee.object.type === 'Identifier' &&
|
|
50
|
-
node.callee.object.name === 'analytics' &&
|
|
51
|
-
node.callee.property.type === 'Identifier' &&
|
|
52
|
-
['track', 'identify', 'page'].includes(node.callee.property.name)) {
|
|
53
|
-
if (!isInsideConsentCheck(node)) {
|
|
54
|
-
report(node);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (node.callee.type === 'Identifier' && node.callee.name === 'gtag') {
|
|
58
|
-
if (!isInsideConsentCheck(node)) {
|
|
59
|
-
report(node);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noTrackingWithoutConsent=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noTrackingWithoutConsent=(0,eslint_devkit_1.createRule)({name:"no-tracking-without-consent",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-tracking-without-consent.md",description:"Require consent before analytics tracking",cwe:"CWE-359",cvss:5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Tracking Without Consent",cwe:"CWE-359",description:"Analytics tracking without consent check - violates privacy regulations",severity:"MEDIUM",fix:"Wrap tracking calls in consent check: if (hasConsent) { analytics.track(...) }",documentationLink:"https://cwe.mitre.org/data/definitions/359.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}function isInsideConsentCheck(node){let current=node.parent;while(current){if(current.type==="IfStatement"){return true}if(current.type==="ConditionalExpression"){return true}current=current.parent}return false}return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&node.callee.object.name==="analytics"&&node.callee.property.type==="Identifier"&&["track","identify","page"].includes(node.callee.property.name)){if(!isInsideConsentCheck(node)){report(node)}}if(node.callee.type==="Identifier"&&node.callee.name==="gtag"){if(!isInsideConsentCheck(node)){report(node)}}}}}});
|
|
@@ -1,208 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnencryptedTransmission = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const DEFAULT_INSECURE_PROTOCOLS = [
|
|
7
|
-
'http://',
|
|
8
|
-
'ws://',
|
|
9
|
-
'ftp://',
|
|
10
|
-
'tcp://',
|
|
11
|
-
'mongodb://',
|
|
12
|
-
'redis://',
|
|
13
|
-
'mysql://',
|
|
14
|
-
];
|
|
15
|
-
const SECURE_ALTERNATIVES = {
|
|
16
|
-
'http://': 'https://',
|
|
17
|
-
'ws://': 'wss://',
|
|
18
|
-
'ftp://': 'ftps://',
|
|
19
|
-
'tcp://': 'tls://',
|
|
20
|
-
'mongodb://': 'mongodb+srv://',
|
|
21
|
-
'redis://': 'rediss://',
|
|
22
|
-
'mysql://': 'mysqls://',
|
|
23
|
-
};
|
|
24
|
-
function containsInsecureProtocol(value, insecureProtocols, secureAlternatives) {
|
|
25
|
-
const lowerValue = value.toLowerCase();
|
|
26
|
-
for (const protocol of insecureProtocols) {
|
|
27
|
-
const lowerProtocol = protocol.toLowerCase();
|
|
28
|
-
if (lowerValue.includes(lowerProtocol)) {
|
|
29
|
-
const secureAlternative = secureAlternatives[lowerProtocol];
|
|
30
|
-
if (secureAlternative) {
|
|
31
|
-
if (!lowerValue.includes(secureAlternative.toLowerCase())) {
|
|
32
|
-
return { isInsecure: true, protocol };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return { isInsecure: true, protocol };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return { isInsecure: false, protocol: '' };
|
|
41
|
-
}
|
|
42
|
-
function matchesIgnorePattern(text, patterns) {
|
|
43
|
-
return patterns.some(pattern => {
|
|
44
|
-
try {
|
|
45
|
-
const regex = new RegExp(pattern, 'i');
|
|
46
|
-
return regex.test(text);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
54
|
-
name: 'no-unencrypted-transmission',
|
|
55
|
-
meta: {
|
|
56
|
-
type: 'problem',
|
|
57
|
-
docs: {
|
|
58
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unencrypted-transmission.md',
|
|
59
|
-
description: 'Detects unencrypted data transmission (HTTP vs HTTPS, plain text protocols)',
|
|
60
|
-
cwe: 'CWE-319',
|
|
61
|
-
cvss: 7.5,
|
|
62
|
-
},
|
|
63
|
-
hasSuggestions: true,
|
|
64
|
-
messages: {
|
|
65
|
-
unencryptedTransmission: (0, eslint_devkit_1.formatLLMMessage)({
|
|
66
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
67
|
-
issueName: 'Unencrypted Transmission',
|
|
68
|
-
cwe: 'CWE-319',
|
|
69
|
-
description: 'Unencrypted transmission detected: {{issue}}',
|
|
70
|
-
severity: 'HIGH',
|
|
71
|
-
fix: '{{safeAlternative}}',
|
|
72
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
|
|
73
|
-
}),
|
|
74
|
-
useHttps: (0, eslint_devkit_1.formatLLMMessage)({
|
|
75
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
76
|
-
issueName: 'Use HTTPS',
|
|
77
|
-
description: 'Use secure protocol',
|
|
78
|
-
severity: 'LOW',
|
|
79
|
-
fix: 'Replace http:// with https://',
|
|
80
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/Security/Transport_Layer_Security',
|
|
81
|
-
}),
|
|
82
|
-
},
|
|
83
|
-
schema: [
|
|
84
|
-
{
|
|
85
|
-
type: 'object',
|
|
86
|
-
properties: {
|
|
87
|
-
allowInTests: {
|
|
88
|
-
type: 'boolean',
|
|
89
|
-
default: false,
|
|
90
|
-
description: 'Allow unencrypted transmission in test files',
|
|
91
|
-
},
|
|
92
|
-
insecureProtocols: {
|
|
93
|
-
type: 'array',
|
|
94
|
-
items: { type: 'string' },
|
|
95
|
-
default: [],
|
|
96
|
-
description: 'Insecure protocol patterns to detect',
|
|
97
|
-
},
|
|
98
|
-
secureAlternatives: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
additionalProperties: { type: 'string' },
|
|
101
|
-
default: {},
|
|
102
|
-
description: 'Mapping of insecure protocols to their secure alternatives',
|
|
103
|
-
},
|
|
104
|
-
ignorePatterns: {
|
|
105
|
-
type: 'array',
|
|
106
|
-
items: { type: 'string' },
|
|
107
|
-
default: [],
|
|
108
|
-
description: 'Additional safe patterns to ignore',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
additionalProperties: false,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
defaultOptions: [
|
|
116
|
-
{
|
|
117
|
-
allowInTests: false,
|
|
118
|
-
insecureProtocols: [],
|
|
119
|
-
secureAlternatives: {},
|
|
120
|
-
ignorePatterns: [],
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
create(context, [options = {}]) {
|
|
124
|
-
const { allowInTests = false, insecureProtocols, secureAlternatives, ignorePatterns = [], } = options;
|
|
125
|
-
const protocolsToCheck = insecureProtocols && insecureProtocols.length > 0
|
|
126
|
-
? insecureProtocols
|
|
127
|
-
: DEFAULT_INSECURE_PROTOCOLS;
|
|
128
|
-
const secureAlternativesToUse = secureAlternatives && Object.keys(secureAlternatives).length > 0
|
|
129
|
-
? { ...SECURE_ALTERNATIVES, ...secureAlternatives }
|
|
130
|
-
: SECURE_ALTERNATIVES;
|
|
131
|
-
const filename = context.filename;
|
|
132
|
-
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
133
|
-
const sourceCode = context.sourceCode;
|
|
134
|
-
function checkLiteral(node) {
|
|
135
|
-
if (typeof node.value !== 'string') {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const value = node.value;
|
|
139
|
-
const text = sourceCode.getText(node);
|
|
140
|
-
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (isTestFile) {
|
|
144
|
-
if (text.includes('localhost')) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
|
|
149
|
-
if (isInsecure) {
|
|
150
|
-
const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
|
|
151
|
-
const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
|
|
152
|
-
context.report({
|
|
153
|
-
node,
|
|
154
|
-
messageId: 'unencryptedTransmission',
|
|
155
|
-
data: {
|
|
156
|
-
issue: `using insecure protocol ${protocol}`,
|
|
157
|
-
safeAlternative,
|
|
158
|
-
},
|
|
159
|
-
suggest: [
|
|
160
|
-
{
|
|
161
|
-
messageId: 'useHttps',
|
|
162
|
-
data: {
|
|
163
|
-
protocol,
|
|
164
|
-
secureProtocol,
|
|
165
|
-
},
|
|
166
|
-
fix(fixer) {
|
|
167
|
-
if (secureProtocol && secureProtocol !== 'secure protocol') {
|
|
168
|
-
const newValue = value.replace(new RegExp(protocol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), secureProtocol);
|
|
169
|
-
return fixer.replaceText(node, JSON.stringify(newValue));
|
|
170
|
-
}
|
|
171
|
-
return null;
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
function checkTemplateLiteral(node) {
|
|
179
|
-
if (isTestFile) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const text = sourceCode.getText(node);
|
|
183
|
-
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
for (const quasi of node.quasis) {
|
|
187
|
-
const value = quasi.value.raw;
|
|
188
|
-
const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
|
|
189
|
-
if (isInsecure) {
|
|
190
|
-
const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
|
|
191
|
-
const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
|
|
192
|
-
context.report({
|
|
193
|
-
node: quasi,
|
|
194
|
-
messageId: 'unencryptedTransmission',
|
|
195
|
-
data: {
|
|
196
|
-
issue: `using insecure protocol ${protocol} in template literal`,
|
|
197
|
-
safeAlternative,
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
Literal: checkLiteral,
|
|
205
|
-
TemplateLiteral: checkTemplateLiteral,
|
|
206
|
-
};
|
|
207
|
-
},
|
|
208
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnencryptedTransmission=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DEFAULT_INSECURE_PROTOCOLS=["http://","ws://","ftp://","tcp://","mongodb://","redis://","mysql://"];const SECURE_ALTERNATIVES={"http://":"https://","ws://":"wss://","ftp://":"ftps://","tcp://":"tls://","mongodb://":"mongodb+srv://","redis://":"rediss://","mysql://":"mysqls://"};function containsInsecureProtocol(value,insecureProtocols,secureAlternatives){const lowerValue=value.toLowerCase();for(const protocol of insecureProtocols){const lowerProtocol=protocol.toLowerCase();if(lowerValue.includes(lowerProtocol)){const secureAlternative=secureAlternatives[lowerProtocol];if(secureAlternative){if(!lowerValue.includes(secureAlternative.toLowerCase())){return{isInsecure:true,protocol}}}else{return{isInsecure:true,protocol}}}}return{isInsecure:false,protocol:""}}function matchesIgnorePattern(text,patterns){return patterns.some(pattern=>{try{const regex=new RegExp(pattern,"i");return regex.test(text)}catch{return false}})}exports.noUnencryptedTransmission=(0,eslint_devkit_2.createRule)({name:"no-unencrypted-transmission",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unencrypted-transmission.md",description:"Detects unencrypted data transmission (HTTP vs HTTPS, plain text protocols)",cwe:"CWE-319",cvss:7.5},hasSuggestions:true,messages:{unencryptedTransmission:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unencrypted Transmission",cwe:"CWE-319",description:"Unencrypted transmission detected: {{issue}}",severity:"HIGH",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),useHttps:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use HTTPS",description:"Use secure protocol",severity:"LOW",fix:"Replace http:// with https://",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/Security/Transport_Layer_Security"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow unencrypted transmission in test files"},insecureProtocols:{type:"array",items:{type:"string"},default:[],description:"Insecure protocol patterns to detect"},secureAlternatives:{type:"object",additionalProperties:{type:"string"},default:{},description:"Mapping of insecure protocols to their secure alternatives"},ignorePatterns:{type:"array",items:{type:"string"},default:[],description:"Additional safe patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,insecureProtocols:[],secureAlternatives:{},ignorePatterns:[]}],create(context,[options={}]){const{allowInTests=false,insecureProtocols,secureAlternatives,ignorePatterns=[]}=options;const protocolsToCheck=insecureProtocols&&insecureProtocols.length>0?insecureProtocols:DEFAULT_INSECURE_PROTOCOLS;const secureAlternativesToUse=secureAlternatives&&Object.keys(secureAlternatives).length>0?{...SECURE_ALTERNATIVES,...secureAlternatives}:SECURE_ALTERNATIVES;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);const sourceCode=context.sourceCode;function checkLiteral(node){if(typeof node.value!=="string"){return}const value=node.value;const text=sourceCode.getText(node);if(matchesIgnorePattern(text,ignorePatterns)){return}if(isTestFile){if(text.includes("localhost")){return}}const{isInsecure,protocol}=containsInsecureProtocol(value,protocolsToCheck,secureAlternativesToUse);if(isInsecure){const secureProtocol=secureAlternativesToUse[protocol.toLowerCase()]||"secure protocol";const safeAlternative=`Use ${secureProtocol} instead of ${protocol}`;context.report({node,messageId:"unencryptedTransmission",data:{issue:`using insecure protocol ${protocol}`,safeAlternative},suggest:[{messageId:"useHttps",data:{protocol,secureProtocol},fix(fixer){if(secureProtocol&&secureProtocol!=="secure protocol"){const newValue=value.replace(new RegExp(protocol.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"gi"),secureProtocol);return fixer.replaceText(node,JSON.stringify(newValue))}return null}}]})}}function checkTemplateLiteral(node){if(isTestFile){return}const text=sourceCode.getText(node);if(matchesIgnorePattern(text,ignorePatterns)){return}for(const quasi of node.quasis){const value=quasi.value.raw;const{isInsecure,protocol}=containsInsecureProtocol(value,protocolsToCheck,secureAlternativesToUse);if(isInsecure){const secureProtocol=secureAlternativesToUse[protocol.toLowerCase()]||"secure protocol";const safeAlternative=`Use ${secureProtocol} instead of ${protocol}`;context.report({node:quasi,messageId:"unencryptedTransmission",data:{issue:`using insecure protocol ${protocol} in template literal`,safeAlternative}})}}}return{Literal:checkLiteral,TemplateLiteral:checkTemplateLiteral}}});
|