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.
Files changed (48) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -159
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/detect-mixed-content/index.js +1 -38
  5. package/src/rules/no-allow-arbitrary-loads/index.js +1 -41
  6. package/src/rules/no-clickjacking/index.js +1 -361
  7. package/src/rules/no-client-side-auth-logic/index.js +1 -67
  8. package/src/rules/no-cookie-auth-tokens/index.js +1 -109
  9. package/src/rules/no-credentials-in-query-params/index.js +1 -55
  10. package/src/rules/no-disabled-certificate-validation/index.js +1 -59
  11. package/src/rules/no-dynamic-service-worker-url/index.js +1 -78
  12. package/src/rules/no-eval/index.js +1 -160
  13. package/src/rules/no-filereader-innerhtml/index.js +1 -196
  14. package/src/rules/no-http-urls/index.js +1 -109
  15. package/src/rules/no-innerhtml/index.js +1 -150
  16. package/src/rules/no-insecure-redirects/index.js +1 -238
  17. package/src/rules/no-insecure-websocket/index.js +1 -57
  18. package/src/rules/no-jwt-in-storage/index.js +1 -178
  19. package/src/rules/no-missing-cors-check/index.js +1 -351
  20. package/src/rules/no-missing-csrf-protection/index.js +1 -165
  21. package/src/rules/no-missing-security-headers/index.js +1 -197
  22. package/src/rules/no-password-in-url/index.js +1 -47
  23. package/src/rules/no-permissive-cors/index.js +1 -65
  24. package/src/rules/no-postmessage-innerhtml/index.js +1 -161
  25. package/src/rules/no-postmessage-wildcard-origin/index.js +1 -112
  26. package/src/rules/no-sensitive-cookie-js/index.js +1 -151
  27. package/src/rules/no-sensitive-data-in-analytics/index.js +1 -58
  28. package/src/rules/no-sensitive-data-in-cache/index.js +1 -47
  29. package/src/rules/no-sensitive-indexeddb/index.js +1 -110
  30. package/src/rules/no-sensitive-localstorage/index.js +1 -173
  31. package/src/rules/no-sensitive-sessionstorage/index.js +1 -144
  32. package/src/rules/no-tracking-without-consent/index.js +1 -65
  33. package/src/rules/no-unencrypted-transmission/index.js +1 -208
  34. package/src/rules/no-unescaped-url-parameter/index.js +1 -319
  35. package/src/rules/no-unsafe-eval-csp/index.js +1 -75
  36. package/src/rules/no-unsafe-inline-csp/index.js +1 -75
  37. package/src/rules/no-unvalidated-deeplinks/index.js +1 -59
  38. package/src/rules/no-websocket-eval/index.js +1 -197
  39. package/src/rules/no-websocket-innerhtml/index.js +1 -185
  40. package/src/rules/no-worker-message-innerhtml/index.js +1 -181
  41. package/src/rules/require-blob-url-revocation/index.js +1 -93
  42. package/src/rules/require-cookie-secure-attrs/index.js +1 -101
  43. package/src/rules/require-csp-headers/index.js +1 -59
  44. package/src/rules/require-https-only/index.js +1 -57
  45. package/src/rules/require-mime-type-validation/index.js +1 -61
  46. package/src/rules/require-postmessage-origin-check/index.js +1 -132
  47. package/src/rules/require-url-validation/index.js +1 -68
  48. package/src/rules/require-websocket-wss/index.js +1 -125
@@ -1,151 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSensitiveCookieJs = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DEFAULT_SENSITIVE_PATTERNS = [
6
- 'token',
7
- 'jwt',
8
- 'access_token',
9
- 'accessToken',
10
- 'refresh_token',
11
- 'refreshToken',
12
- 'id_token',
13
- 'idToken',
14
- 'auth',
15
- 'session',
16
- 'sessionId',
17
- 'session_id',
18
- 'password',
19
- 'passwd',
20
- 'secret',
21
- 'api_key',
22
- 'apiKey',
23
- 'private_key',
24
- 'privateKey',
25
- 'credential',
26
- 'bearer',
27
- ];
28
- function isSensitiveKey(key, patterns) {
29
- const lowerKey = key.toLowerCase();
30
- return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
31
- }
32
- function extractCookieKey(cookieString) {
33
- const match = cookieString.match(/^([^=]+)=/);
34
- return match ? match[1].trim() : null;
35
- }
36
- exports.noSensitiveCookieJs = (0, eslint_devkit_1.createRule)({
37
- name: 'no-sensitive-cookie-js',
38
- meta: {
39
- type: 'problem',
40
- docs: {
41
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-cookie-js.md',
42
- description: 'Disallow storing sensitive data (tokens, passwords) in cookies via JavaScript',
43
- cwe: 'CWE-1004',
44
- cvss: 8.1,
45
- },
46
- hasSuggestions: true,
47
- messages: {
48
- sensitiveCookieJs: (0, eslint_devkit_1.formatLLMMessage)({
49
- icon: eslint_devkit_1.MessageIcons.SECURITY,
50
- issueName: 'Sensitive Cookie via JavaScript',
51
- cwe: 'CWE-1004',
52
- owasp: 'A02:2021',
53
- cvss: 8.1,
54
- description: 'Setting "{{key}}" cookie via document.cookie makes it accessible to XSS attacks. Sensitive cookies should be set server-side with HttpOnly flag.',
55
- severity: 'HIGH',
56
- fix: 'Set authentication cookies server-side with HttpOnly, Secure, and SameSite flags.',
57
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
58
- }),
59
- useHttpOnlyCookie: (0, eslint_devkit_1.formatLLMMessage)({
60
- icon: eslint_devkit_1.MessageIcons.INFO,
61
- issueName: 'Use HttpOnly Cookie',
62
- description: 'Set cookies via server response with Set-Cookie header and HttpOnly flag',
63
- severity: 'LOW',
64
- fix: 'Server: res.cookie(name, value, { httpOnly: true, secure: true, sameSite: "strict" })',
65
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie',
66
- }),
67
- },
68
- schema: [
69
- {
70
- type: 'object',
71
- properties: {
72
- allowInTests: {
73
- type: 'boolean',
74
- default: true,
75
- },
76
- sensitivePatterns: {
77
- type: 'array',
78
- items: { type: 'string' },
79
- default: DEFAULT_SENSITIVE_PATTERNS,
80
- },
81
- },
82
- additionalProperties: false,
83
- },
84
- ],
85
- },
86
- defaultOptions: [
87
- {
88
- allowInTests: true,
89
- sensitivePatterns: DEFAULT_SENSITIVE_PATTERNS,
90
- },
91
- ],
92
- create(context, [options = {}]) {
93
- const { allowInTests = true, sensitivePatterns = DEFAULT_SENSITIVE_PATTERNS, } = options;
94
- const filename = context.filename;
95
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
96
- if (allowInTests && isTestFile) {
97
- return {};
98
- }
99
- return {
100
- AssignmentExpression(node) {
101
- if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
102
- return;
103
- }
104
- const obj = node.left.object;
105
- const prop = node.left.property;
106
- if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
107
- obj.name !== 'document') {
108
- return;
109
- }
110
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
111
- prop.name !== 'cookie') {
112
- return;
113
- }
114
- const value = node.right;
115
- let cookieKey = null;
116
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
117
- typeof value.value === 'string') {
118
- cookieKey = extractCookieKey(value.value);
119
- }
120
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
121
- const firstQuasi = value.quasis[0];
122
- if (firstQuasi) {
123
- cookieKey = extractCookieKey(firstQuasi.value.raw);
124
- }
125
- }
126
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
127
- const left = value.left;
128
- if (left.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
129
- typeof left.value === 'string') {
130
- cookieKey = extractCookieKey(left.value);
131
- }
132
- }
133
- if (cookieKey && isSensitiveKey(cookieKey, sensitivePatterns)) {
134
- context.report({
135
- node,
136
- messageId: 'sensitiveCookieJs',
137
- data: {
138
- key: cookieKey,
139
- },
140
- suggest: [
141
- {
142
- messageId: 'useHttpOnlyCookie',
143
- fix: () => null,
144
- },
145
- ],
146
- });
147
- }
148
- },
149
- };
150
- },
151
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveCookieJs=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DEFAULT_SENSITIVE_PATTERNS=["token","jwt","access_token","accessToken","refresh_token","refreshToken","id_token","idToken","auth","session","sessionId","session_id","password","passwd","secret","api_key","apiKey","private_key","privateKey","credential","bearer"];function isSensitiveKey(key,patterns){const lowerKey=key.toLowerCase();return patterns.some(pattern=>lowerKey.includes(pattern.toLowerCase()))}function extractCookieKey(cookieString){const match=cookieString.match(/^([^=]+)=/);return match?match[1].trim():null}exports.noSensitiveCookieJs=(0,eslint_devkit_1.createRule)({name:"no-sensitive-cookie-js",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-cookie-js.md",description:"Disallow storing sensitive data (tokens, passwords) in cookies via JavaScript",cwe:"CWE-1004",cvss:8.1},hasSuggestions:true,messages:{sensitiveCookieJs:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Sensitive Cookie via JavaScript",cwe:"CWE-1004",owasp:"A02:2021",cvss:8.1,description:'Setting "{{key}}" cookie via document.cookie makes it accessible to XSS attacks. Sensitive cookies should be set server-side with HttpOnly flag.',severity:"HIGH",fix:"Set authentication cookies server-side with HttpOnly, Secure, and SameSite flags.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security"}),useHttpOnlyCookie:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use HttpOnly Cookie",description:"Set cookies via server response with Set-Cookie header and HttpOnly flag",severity:"LOW",fix:'Server: res.cookie(name, value, { httpOnly: true, secure: true, sameSite: "strict" })',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},sensitivePatterns:{type:"array",items:{type:"string"},default:DEFAULT_SENSITIVE_PATTERNS}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,sensitivePatterns:DEFAULT_SENSITIVE_PATTERNS}],create(context,[options={}]){const{allowInTests=true,sensitivePatterns=DEFAULT_SENSITIVE_PATTERNS}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}return{AssignmentExpression(node){if(node.left.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression){return}const obj=node.left.object;const prop=node.left.property;if(obj.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||obj.name!=="document"){return}if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||prop.name!=="cookie"){return}const value=node.right;let cookieKey=null;if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof value.value==="string"){cookieKey=extractCookieKey(value.value)}if(value.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){const firstQuasi=value.quasis[0];if(firstQuasi){cookieKey=extractCookieKey(firstQuasi.value.raw)}}if(value.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){const left=value.left;if(left.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof left.value==="string"){cookieKey=extractCookieKey(left.value)}}if(cookieKey&&isSensitiveKey(cookieKey,sensitivePatterns)){context.report({node,messageId:"sensitiveCookieJs",data:{key:cookieKey},suggest:[{messageId:"useHttpOnlyCookie",fix:()=>null}]})}}}}});
@@ -1,58 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSensitiveDataInAnalytics = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noSensitiveDataInAnalytics = (0, eslint_devkit_1.createRule)({
6
- name: 'no-sensitive-data-in-analytics',
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-sensitive-data-in-analytics.md',
11
- description: 'Prevent PII being sent to analytics services',
12
- cwe: 'CWE-359',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Sensitive Data in Analytics',
19
- cwe: 'CWE-359',
20
- description: 'Sensitive field sent to analytics - this is a privacy violation',
21
- severity: 'HIGH',
22
- fix: 'Remove PII from analytics tracking data',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/359.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- const sensitiveFields = ['email', 'ssn', 'creditcard', 'password', 'phone', 'address'];
31
- function report(node, field) {
32
- context.report({ node, messageId: 'violationDetected', data: { field } });
33
- }
34
- return {
35
- CallExpression(node) {
36
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
37
- node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
38
- node.callee.object.name === 'analytics' &&
39
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
40
- node.callee.property.name === 'track') {
41
- const dataArg = node.arguments[1];
42
- if (dataArg?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
43
- dataArg.properties.forEach(prop => {
44
- if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
45
- prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
46
- const key = prop.key.name.toLowerCase();
47
- const matchedField = sensitiveFields.find(f => key.includes(f));
48
- if (matchedField) {
49
- report(prop, matchedField);
50
- }
51
- }
52
- });
53
- }
54
- }
55
- },
56
- };
57
- },
58
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveDataInAnalytics=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noSensitiveDataInAnalytics=(0,eslint_devkit_1.createRule)({name:"no-sensitive-data-in-analytics",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-data-in-analytics.md",description:"Prevent PII being sent to analytics services",cwe:"CWE-359",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Sensitive Data in Analytics",cwe:"CWE-359",description:"Sensitive field sent to analytics - this is a privacy violation",severity:"HIGH",fix:"Remove PII from analytics tracking data",documentationLink:"https://cwe.mitre.org/data/definitions/359.html"})},schema:[]},defaultOptions:[],create(context){const sensitiveFields=["email","ssn","creditcard","password","phone","address"];function report(node,field){context.report({node,messageId:"violationDetected",data:{field}})}return{CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="analytics"&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="track"){const dataArg=node.arguments[1];if(dataArg?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){dataArg.properties.forEach(prop=>{if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){const key=prop.key.name.toLowerCase();const matchedField=sensitiveFields.find(f=>key.includes(f));if(matchedField){report(prop,matchedField)}}})}}}}}});
@@ -1,47 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSensitiveDataInCache = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noSensitiveDataInCache = (0, eslint_devkit_1.createRule)({
6
- name: 'no-sensitive-data-in-cache',
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-sensitive-data-in-cache.md',
11
- description: 'Prevent caching sensitive data without encryption',
12
- cwe: 'CWE-200',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'violation Detected',
19
- cwe: 'CWE-200',
20
- description: 'Prevent caching sensitive data without encryption detected - Sensitive data in cache',
21
- severity: 'HIGH',
22
- fix: 'Review and apply secure practices',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/200.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- return {
31
- CallExpression(node) {
32
- if (node.callee.type === 'MemberExpression' &&
33
- node.callee.property.type === 'Identifier' &&
34
- ['set', 'put', 'store'].includes(node.callee.property.name)) {
35
- const keyArg = node.arguments[0];
36
- if (keyArg && keyArg.type === 'Literal') {
37
- const rawValue = keyArg?.value;
38
- const key = (rawValue === undefined || rawValue === null) ? '' : String(rawValue).toLowerCase();
39
- if (['password', 'token', 'credit', 'ssn'].some(k => key.includes(k))) {
40
- context.report({ node, messageId: 'violationDetected' });
41
- }
42
- }
43
- }
44
- },
45
- };
46
- },
47
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveDataInCache=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noSensitiveDataInCache=(0,eslint_devkit_1.createRule)({name:"no-sensitive-data-in-cache",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-data-in-cache.md",description:"Prevent caching sensitive data without encryption",cwe:"CWE-200",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-200",description:"Prevent caching sensitive data without encryption detected - Sensitive data in cache",severity:"HIGH",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/200.html"})},schema:[]},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&["set","put","store"].includes(node.callee.property.name)){const keyArg=node.arguments[0];if(keyArg&&keyArg.type==="Literal"){const rawValue=keyArg?.value;const key=rawValue===void 0||rawValue===null?"":String(rawValue).toLowerCase();if(["password","token","credit","ssn"].some(k=>key.includes(k))){context.report({node,messageId:"violationDetected"})}}}}}}});
@@ -1,110 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSensitiveIndexeddb = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const SENSITIVE_PATTERNS = [
6
- /password/i,
7
- /secret/i,
8
- /apikey/i,
9
- /api[_-]?key/i,
10
- /private[_-]?key/i,
11
- /auth[_-]?token/i,
12
- /access[_-]?token/i,
13
- /credential/i,
14
- /ssn/i,
15
- /credit[_-]?card/i,
16
- /encryption[_-]?key/i,
17
- ];
18
- function isSensitive(name) {
19
- return SENSITIVE_PATTERNS.some((p) => p.test(name));
20
- }
21
- exports.noSensitiveIndexeddb = (0, eslint_devkit_1.createRule)({
22
- name: 'no-sensitive-indexeddb',
23
- meta: {
24
- type: 'problem',
25
- docs: {
26
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-indexeddb.md',
27
- description: 'Disallow storing sensitive data in IndexedDB',
28
- cwe: 'CWE-922',
29
- cvss: 7.5,
30
- },
31
- hasSuggestions: true,
32
- messages: {
33
- sensitiveInIndexedDB: (0, eslint_devkit_1.formatLLMMessage)({
34
- icon: eslint_devkit_1.MessageIcons.SECURITY,
35
- issueName: 'Sensitive Data in IndexedDB',
36
- cwe: 'CWE-922',
37
- owasp: 'A02:2021',
38
- cvss: 7.5,
39
- description: 'Creating IndexedDB store "{{name}}" for sensitive data. IndexedDB is accessible to XSS attacks.',
40
- severity: 'HIGH',
41
- fix: 'Encrypt sensitive data before storing or use server-side storage.',
42
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#local-storage',
43
- }),
44
- useEncryption: (0, eslint_devkit_1.formatLLMMessage)({
45
- icon: eslint_devkit_1.MessageIcons.INFO,
46
- issueName: 'Encrypt Sensitive Data',
47
- description: 'Use Web Crypto API to encrypt data before storing',
48
- severity: 'LOW',
49
- fix: 'const encrypted = await crypto.subtle.encrypt(algo, key, data);',
50
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt',
51
- }),
52
- },
53
- schema: [
54
- {
55
- type: 'object',
56
- properties: { allowInTests: { type: 'boolean', default: true } },
57
- additionalProperties: false,
58
- },
59
- ],
60
- },
61
- defaultOptions: [{ allowInTests: true }],
62
- create(context, [options = {}]) {
63
- const { allowInTests = true } = options;
64
- const filename = context.filename;
65
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
66
- if (allowInTests && isTestFile) {
67
- return {};
68
- }
69
- return {
70
- CallExpression(node) {
71
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
72
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
73
- node.callee.property.name === 'createObjectStore') {
74
- const storeNameArg = node.arguments[0];
75
- if (storeNameArg &&
76
- storeNameArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
77
- typeof storeNameArg.value === 'string') {
78
- if (isSensitive(storeNameArg.value)) {
79
- context.report({
80
- node,
81
- messageId: 'sensitiveInIndexedDB',
82
- data: { name: storeNameArg.value },
83
- suggest: [{ messageId: 'useEncryption', fix: () => null }],
84
- });
85
- }
86
- }
87
- }
88
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
89
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
90
- (node.callee.property.name === 'add' || node.callee.property.name === 'put')) {
91
- const dataArg = node.arguments[0];
92
- if (dataArg && dataArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
93
- for (const prop of dataArg.properties) {
94
- if (prop.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
95
- prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
96
- isSensitive(prop.key.name)) {
97
- context.report({
98
- node,
99
- messageId: 'sensitiveInIndexedDB',
100
- data: { name: prop.key.name },
101
- suggest: [{ messageId: 'useEncryption', fix: () => null }],
102
- });
103
- }
104
- }
105
- }
106
- }
107
- },
108
- };
109
- },
110
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveIndexeddb=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SENSITIVE_PATTERNS=[/password/i,/secret/i,/apikey/i,/api[_-]?key/i,/private[_-]?key/i,/auth[_-]?token/i,/access[_-]?token/i,/credential/i,/ssn/i,/credit[_-]?card/i,/encryption[_-]?key/i];function isSensitive(name){return SENSITIVE_PATTERNS.some(p=>p.test(name))}exports.noSensitiveIndexeddb=(0,eslint_devkit_1.createRule)({name:"no-sensitive-indexeddb",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-indexeddb.md",description:"Disallow storing sensitive data in IndexedDB",cwe:"CWE-922",cvss:7.5},hasSuggestions:true,messages:{sensitiveInIndexedDB:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Sensitive Data in IndexedDB",cwe:"CWE-922",owasp:"A02:2021",cvss:7.5,description:'Creating IndexedDB store "{{name}}" for sensitive data. IndexedDB is accessible to XSS attacks.',severity:"HIGH",fix:"Encrypt sensitive data before storing or use server-side storage.",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#local-storage"}),useEncryption:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Encrypt Sensitive Data",description:"Use Web Crypto API to encrypt data before storing",severity:"LOW",fix:"const encrypted = await crypto.subtle.encrypt(algo, key, data);",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}return{CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="createObjectStore"){const storeNameArg=node.arguments[0];if(storeNameArg&&storeNameArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof storeNameArg.value==="string"){if(isSensitive(storeNameArg.value)){context.report({node,messageId:"sensitiveInIndexedDB",data:{name:storeNameArg.value},suggest:[{messageId:"useEncryption",fix:()=>null}]})}}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(node.callee.property.name==="add"||node.callee.property.name==="put")){const dataArg=node.arguments[0];if(dataArg&&dataArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of dataArg.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.Property&&prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isSensitive(prop.key.name)){context.report({node,messageId:"sensitiveInIndexedDB",data:{name:prop.key.name},suggest:[{messageId:"useEncryption",fix:()=>null}]})}}}}}}}});
@@ -1,173 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSensitiveLocalstorage = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DEFAULT_SENSITIVE_PATTERNS = [
6
- 'token',
7
- 'jwt',
8
- 'access_token',
9
- 'accessToken',
10
- 'refresh_token',
11
- 'refreshToken',
12
- 'id_token',
13
- 'idToken',
14
- 'auth',
15
- 'password',
16
- 'passwd',
17
- 'secret',
18
- 'api_key',
19
- 'apiKey',
20
- 'private_key',
21
- 'privateKey',
22
- 'session',
23
- 'sessionId',
24
- 'credential',
25
- 'bearer',
26
- ];
27
- function isSensitiveKey(key, patterns) {
28
- const lowerKey = key.toLowerCase();
29
- return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
30
- }
31
- exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
32
- name: 'no-sensitive-localstorage',
33
- meta: {
34
- type: 'problem',
35
- docs: {
36
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-localstorage.md',
37
- description: 'Disallow storing sensitive data like tokens and passwords in localStorage',
38
- cwe: 'CWE-922',
39
- cvss: 7.5,
40
- },
41
- hasSuggestions: true,
42
- messages: {
43
- sensitiveLocalStorage: (0, eslint_devkit_1.formatLLMMessage)({
44
- icon: eslint_devkit_1.MessageIcons.SECURITY,
45
- issueName: 'Sensitive Data in localStorage',
46
- cwe: 'CWE-922',
47
- description: 'Storing "{{key}}" in {{storage}} is dangerous. localStorage is vulnerable to XSS attacks - any script on the page can access it.',
48
- severity: 'HIGH',
49
- fix: 'Use httpOnly cookies for tokens, or encrypt data before storage.',
50
- documentationLink: 'https://owasp.org/www-community/vulnerabilities/Insecure_Storage',
51
- }),
52
- useHttpOnlyCookie: (0, eslint_devkit_1.formatLLMMessage)({
53
- icon: eslint_devkit_1.MessageIcons.INFO,
54
- issueName: 'Use HttpOnly Cookie',
55
- description: 'Store authentication tokens in httpOnly cookies instead',
56
- severity: 'LOW',
57
- fix: 'Set tokens via Set-Cookie header with httpOnly and secure flags.',
58
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
59
- }),
60
- },
61
- schema: [
62
- {
63
- type: 'object',
64
- properties: {
65
- allowInTests: {
66
- type: 'boolean',
67
- default: false,
68
- },
69
- sensitivePatterns: {
70
- type: 'array',
71
- items: { type: 'string' },
72
- default: DEFAULT_SENSITIVE_PATTERNS,
73
- },
74
- checkSessionStorage: {
75
- type: 'boolean',
76
- default: true,
77
- },
78
- },
79
- additionalProperties: false,
80
- },
81
- ],
82
- },
83
- defaultOptions: [
84
- {
85
- allowInTests: false,
86
- sensitivePatterns: DEFAULT_SENSITIVE_PATTERNS,
87
- checkSessionStorage: true,
88
- },
89
- ],
90
- create(context, [options = {}]) {
91
- const { allowInTests = false, sensitivePatterns = DEFAULT_SENSITIVE_PATTERNS, checkSessionStorage = true, } = options;
92
- const filename = context.filename;
93
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
94
- if (isTestFile) {
95
- return {};
96
- }
97
- const storageObjects = ['localStorage'];
98
- if (checkSessionStorage) {
99
- storageObjects.push('sessionStorage');
100
- }
101
- return {
102
- CallExpression(node) {
103
- const callee = node.callee;
104
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
105
- callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
106
- storageObjects.includes(callee.object.name) &&
107
- callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
108
- callee.property.name === 'setItem') {
109
- const keyArg = node.arguments[0];
110
- if (!keyArg) {
111
- return;
112
- }
113
- let keyValue = null;
114
- if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof keyArg.value === 'string') {
115
- keyValue = keyArg.value;
116
- }
117
- else if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
118
- keyValue = keyArg.name;
119
- }
120
- if (keyValue && isSensitiveKey(keyValue, sensitivePatterns)) {
121
- context.report({
122
- node,
123
- messageId: 'sensitiveLocalStorage',
124
- data: {
125
- key: keyValue,
126
- storage: callee.object.name,
127
- },
128
- suggest: [
129
- {
130
- messageId: 'useHttpOnlyCookie',
131
- fix: () => null,
132
- },
133
- ],
134
- });
135
- }
136
- }
137
- },
138
- AssignmentExpression(node) {
139
- if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
140
- return;
141
- }
142
- const obj = node.left.object;
143
- if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || !storageObjects.includes(obj.name)) {
144
- return;
145
- }
146
- let keyValue = null;
147
- if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
148
- typeof node.left.property.value === 'string') {
149
- keyValue = node.left.property.value;
150
- }
151
- else if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
152
- keyValue = node.left.property.name;
153
- }
154
- if (keyValue && isSensitiveKey(keyValue, sensitivePatterns)) {
155
- context.report({
156
- node,
157
- messageId: 'sensitiveLocalStorage',
158
- data: {
159
- key: keyValue,
160
- storage: obj.name,
161
- },
162
- suggest: [
163
- {
164
- messageId: 'useHttpOnlyCookie',
165
- fix: () => null,
166
- },
167
- ],
168
- });
169
- }
170
- },
171
- };
172
- },
173
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noSensitiveLocalstorage=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DEFAULT_SENSITIVE_PATTERNS=["token","jwt","access_token","accessToken","refresh_token","refreshToken","id_token","idToken","auth","password","passwd","secret","api_key","apiKey","private_key","privateKey","session","sessionId","credential","bearer"];function isSensitiveKey(key,patterns){const lowerKey=key.toLowerCase();return patterns.some(pattern=>lowerKey.includes(pattern.toLowerCase()))}exports.noSensitiveLocalstorage=(0,eslint_devkit_1.createRule)({name:"no-sensitive-localstorage",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-sensitive-localstorage.md",description:"Disallow storing sensitive data like tokens and passwords in localStorage",cwe:"CWE-922",cvss:7.5},hasSuggestions:true,messages:{sensitiveLocalStorage:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Sensitive Data in localStorage",cwe:"CWE-922",description:'Storing "{{key}}" in {{storage}} is dangerous. localStorage is vulnerable to XSS attacks - any script on the page can access it.',severity:"HIGH",fix:"Use httpOnly cookies for tokens, or encrypt data before storage.",documentationLink:"https://owasp.org/www-community/vulnerabilities/Insecure_Storage"}),useHttpOnlyCookie:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use HttpOnly Cookie",description:"Store authentication tokens in httpOnly cookies instead",severity:"LOW",fix:"Set tokens via Set-Cookie header with httpOnly and secure flags.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false},sensitivePatterns:{type:"array",items:{type:"string"},default:DEFAULT_SENSITIVE_PATTERNS},checkSessionStorage:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,sensitivePatterns:DEFAULT_SENSITIVE_PATTERNS,checkSessionStorage:true}],create(context,[options={}]){const{allowInTests=false,sensitivePatterns=DEFAULT_SENSITIVE_PATTERNS,checkSessionStorage=true}=options;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const storageObjects=["localStorage"];if(checkSessionStorage){storageObjects.push("sessionStorage")}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&&storageObjects.includes(callee.object.name)&&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,sensitivePatterns)){context.report({node,messageId:"sensitiveLocalStorage",data:{key:keyValue,storage:callee.object.name},suggest:[{messageId:"useHttpOnlyCookie",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||!storageObjects.includes(obj.name)){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,sensitivePatterns)){context.report({node,messageId:"sensitiveLocalStorage",data:{key:keyValue,storage:obj.name},suggest:[{messageId:"useHttpOnlyCookie",fix:()=>null}]})}}}}});