eslint-plugin-browser-security 0.0.1
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/AGENTS.md +97 -0
- package/CHANGELOG.md +75 -0
- package/README.md +205 -0
- package/package.json +92 -0
- package/src/index.d.ts +59 -0
- package/src/index.js +216 -0
- package/src/index.js.map +1 -0
- package/src/rules/no-cookie-auth-tokens/index.d.ts +5 -0
- package/src/rules/no-cookie-auth-tokens/index.js +115 -0
- package/src/rules/no-cookie-auth-tokens/index.js.map +1 -0
- package/src/rules/no-dynamic-service-worker-url/index.d.ts +5 -0
- package/src/rules/no-dynamic-service-worker-url/index.js +80 -0
- package/src/rules/no-dynamic-service-worker-url/index.js.map +1 -0
- package/src/rules/no-eval/index.d.ts +7 -0
- package/src/rules/no-eval/index.js +150 -0
- package/src/rules/no-eval/index.js.map +1 -0
- package/src/rules/no-filereader-innerhtml/index.d.ts +5 -0
- package/src/rules/no-filereader-innerhtml/index.js +217 -0
- package/src/rules/no-filereader-innerhtml/index.js.map +1 -0
- package/src/rules/no-innerhtml/index.d.ts +9 -0
- package/src/rules/no-innerhtml/index.js +148 -0
- package/src/rules/no-innerhtml/index.js.map +1 -0
- package/src/rules/no-jwt-in-storage/index.d.ts +5 -0
- package/src/rules/no-jwt-in-storage/index.js +197 -0
- package/src/rules/no-jwt-in-storage/index.js.map +1 -0
- package/src/rules/no-postmessage-innerhtml/index.d.ts +5 -0
- package/src/rules/no-postmessage-innerhtml/index.js +174 -0
- package/src/rules/no-postmessage-innerhtml/index.js.map +1 -0
- package/src/rules/no-postmessage-wildcard-origin/index.d.ts +5 -0
- package/src/rules/no-postmessage-wildcard-origin/index.js +115 -0
- package/src/rules/no-postmessage-wildcard-origin/index.js.map +1 -0
- package/src/rules/no-sensitive-cookie-js/index.d.ts +7 -0
- package/src/rules/no-sensitive-cookie-js/index.js +163 -0
- package/src/rules/no-sensitive-cookie-js/index.js.map +1 -0
- package/src/rules/no-sensitive-indexeddb/index.d.ts +5 -0
- package/src/rules/no-sensitive-indexeddb/index.js +111 -0
- package/src/rules/no-sensitive-indexeddb/index.js.map +1 -0
- package/src/rules/no-sensitive-localstorage/index.d.ts +9 -0
- package/src/rules/no-sensitive-localstorage/index.js +179 -0
- package/src/rules/no-sensitive-localstorage/index.js.map +1 -0
- package/src/rules/no-sensitive-sessionstorage/index.d.ts +7 -0
- package/src/rules/no-sensitive-sessionstorage/index.js +148 -0
- package/src/rules/no-sensitive-sessionstorage/index.js.map +1 -0
- package/src/rules/no-unsafe-eval-csp/index.d.ts +5 -0
- package/src/rules/no-unsafe-eval-csp/index.js +78 -0
- package/src/rules/no-unsafe-eval-csp/index.js.map +1 -0
- package/src/rules/no-unsafe-inline-csp/index.d.ts +5 -0
- package/src/rules/no-unsafe-inline-csp/index.js +78 -0
- package/src/rules/no-unsafe-inline-csp/index.js.map +1 -0
- package/src/rules/no-websocket-eval/index.d.ts +5 -0
- package/src/rules/no-websocket-eval/index.js +223 -0
- package/src/rules/no-websocket-eval/index.js.map +1 -0
- package/src/rules/no-websocket-innerhtml/index.d.ts +5 -0
- package/src/rules/no-websocket-innerhtml/index.js +198 -0
- package/src/rules/no-websocket-innerhtml/index.js.map +1 -0
- package/src/rules/no-worker-message-innerhtml/index.d.ts +5 -0
- package/src/rules/no-worker-message-innerhtml/index.js +198 -0
- package/src/rules/no-worker-message-innerhtml/index.js.map +1 -0
- package/src/rules/require-blob-url-revocation/index.d.ts +5 -0
- package/src/rules/require-blob-url-revocation/index.js +96 -0
- package/src/rules/require-blob-url-revocation/index.js.map +1 -0
- package/src/rules/require-cookie-secure-attrs/index.d.ts +5 -0
- package/src/rules/require-cookie-secure-attrs/index.js +101 -0
- package/src/rules/require-cookie-secure-attrs/index.js.map +1 -0
- package/src/rules/require-postmessage-origin-check/index.d.ts +7 -0
- package/src/rules/require-postmessage-origin-check/index.js +142 -0
- package/src/rules/require-postmessage-origin-check/index.js.map +1 -0
- package/src/rules/require-websocket-wss/index.d.ts +7 -0
- package/src/rules/require-websocket-wss/index.js +134 -0
- package/src/rules/require-websocket-wss/index.js.map +1 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* eslint-plugin-browser-security
|
|
4
|
+
*
|
|
5
|
+
* Security-focused ESLint plugin for browser applications.
|
|
6
|
+
* Detects XSS vulnerabilities, postMessage abuse, localStorage/sessionStorage/IndexedDB
|
|
7
|
+
* token exposure, cookie security issues, WebSocket vulnerabilities, and more.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - LLM-optimized error messages with CWE references
|
|
11
|
+
* - XSS prevention rules (innerHTML, eval)
|
|
12
|
+
* - postMessage security
|
|
13
|
+
* - Storage security (localStorage, sessionStorage, IndexedDB)
|
|
14
|
+
* - Cookie security
|
|
15
|
+
* - WebSocket security
|
|
16
|
+
* - Browser API security
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/ofri-peretz/eslint#readme
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.configs = exports.plugin = exports.rules = void 0;
|
|
22
|
+
// XSS Prevention Rules
|
|
23
|
+
const no_innerhtml_1 = require("./rules/no-innerhtml");
|
|
24
|
+
const no_eval_1 = require("./rules/no-eval");
|
|
25
|
+
// postMessage Security
|
|
26
|
+
const require_postmessage_origin_check_1 = require("./rules/require-postmessage-origin-check");
|
|
27
|
+
const no_postmessage_wildcard_origin_1 = require("./rules/no-postmessage-wildcard-origin");
|
|
28
|
+
const no_postmessage_innerhtml_1 = require("./rules/no-postmessage-innerhtml");
|
|
29
|
+
// Storage Security
|
|
30
|
+
const no_sensitive_localstorage_1 = require("./rules/no-sensitive-localstorage");
|
|
31
|
+
const no_jwt_in_storage_1 = require("./rules/no-jwt-in-storage");
|
|
32
|
+
const no_sensitive_sessionstorage_1 = require("./rules/no-sensitive-sessionstorage");
|
|
33
|
+
const no_sensitive_indexeddb_1 = require("./rules/no-sensitive-indexeddb");
|
|
34
|
+
// Cookie Security
|
|
35
|
+
const no_sensitive_cookie_js_1 = require("./rules/no-sensitive-cookie-js");
|
|
36
|
+
const no_cookie_auth_tokens_1 = require("./rules/no-cookie-auth-tokens");
|
|
37
|
+
const require_cookie_secure_attrs_1 = require("./rules/require-cookie-secure-attrs");
|
|
38
|
+
// WebSocket Security
|
|
39
|
+
const require_websocket_wss_1 = require("./rules/require-websocket-wss");
|
|
40
|
+
const no_websocket_innerhtml_1 = require("./rules/no-websocket-innerhtml");
|
|
41
|
+
const no_websocket_eval_1 = require("./rules/no-websocket-eval");
|
|
42
|
+
// File API Security
|
|
43
|
+
const no_filereader_innerhtml_1 = require("./rules/no-filereader-innerhtml");
|
|
44
|
+
const require_blob_url_revocation_1 = require("./rules/require-blob-url-revocation");
|
|
45
|
+
// Workers Security
|
|
46
|
+
const no_dynamic_service_worker_url_1 = require("./rules/no-dynamic-service-worker-url");
|
|
47
|
+
const no_worker_message_innerhtml_1 = require("./rules/no-worker-message-innerhtml");
|
|
48
|
+
// CSP Security
|
|
49
|
+
const no_unsafe_inline_csp_1 = require("./rules/no-unsafe-inline-csp");
|
|
50
|
+
const no_unsafe_eval_csp_1 = require("./rules/no-unsafe-eval-csp");
|
|
51
|
+
/**
|
|
52
|
+
* Collection of all browser security ESLint rules
|
|
53
|
+
*/
|
|
54
|
+
exports.rules = {
|
|
55
|
+
// XSS Prevention
|
|
56
|
+
'no-innerhtml': no_innerhtml_1.noInnerhtml,
|
|
57
|
+
'no-eval': no_eval_1.noEval,
|
|
58
|
+
// postMessage Security
|
|
59
|
+
'require-postmessage-origin-check': require_postmessage_origin_check_1.requirePostmessageOriginCheck,
|
|
60
|
+
'no-postmessage-wildcard-origin': no_postmessage_wildcard_origin_1.noPostmessageWildcardOrigin,
|
|
61
|
+
'no-postmessage-innerhtml': no_postmessage_innerhtml_1.noPostmessageInnerhtml,
|
|
62
|
+
// Storage Security
|
|
63
|
+
'no-sensitive-localstorage': no_sensitive_localstorage_1.noSensitiveLocalstorage,
|
|
64
|
+
'no-jwt-in-storage': no_jwt_in_storage_1.noJwtInStorage,
|
|
65
|
+
'no-sensitive-sessionstorage': no_sensitive_sessionstorage_1.noSensitiveSessionstorage,
|
|
66
|
+
'no-sensitive-indexeddb': no_sensitive_indexeddb_1.noSensitiveIndexeddb,
|
|
67
|
+
// Cookie Security
|
|
68
|
+
'no-sensitive-cookie-js': no_sensitive_cookie_js_1.noSensitiveCookieJs,
|
|
69
|
+
'no-cookie-auth-tokens': no_cookie_auth_tokens_1.noCookieAuthTokens,
|
|
70
|
+
'require-cookie-secure-attrs': require_cookie_secure_attrs_1.requireCookieSecureAttrs,
|
|
71
|
+
// WebSocket Security
|
|
72
|
+
'require-websocket-wss': require_websocket_wss_1.requireWebsocketWss,
|
|
73
|
+
'no-websocket-innerhtml': no_websocket_innerhtml_1.noWebsocketInnerhtml,
|
|
74
|
+
'no-websocket-eval': no_websocket_eval_1.noWebsocketEval,
|
|
75
|
+
// File API Security
|
|
76
|
+
'no-filereader-innerhtml': no_filereader_innerhtml_1.noFilereaderInnerhtml,
|
|
77
|
+
'require-blob-url-revocation': require_blob_url_revocation_1.requireBlobUrlRevocation,
|
|
78
|
+
// Workers Security
|
|
79
|
+
'no-dynamic-service-worker-url': no_dynamic_service_worker_url_1.noDynamicServiceWorkerUrl,
|
|
80
|
+
'no-worker-message-innerhtml': no_worker_message_innerhtml_1.noWorkerMessageInnerhtml,
|
|
81
|
+
// CSP Security
|
|
82
|
+
'no-unsafe-inline-csp': no_unsafe_inline_csp_1.noUnsafeInlineCsp,
|
|
83
|
+
'no-unsafe-eval-csp': no_unsafe_eval_csp_1.noUnsafeEvalCsp,
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* ESLint Plugin object
|
|
87
|
+
*/
|
|
88
|
+
exports.plugin = {
|
|
89
|
+
meta: {
|
|
90
|
+
name: 'eslint-plugin-browser-security',
|
|
91
|
+
version: '0.0.1',
|
|
92
|
+
},
|
|
93
|
+
rules: exports.rules,
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Recommended configuration - balanced security enforcement
|
|
97
|
+
*/
|
|
98
|
+
const recommendedRules = {
|
|
99
|
+
// Critical - XSS Prevention
|
|
100
|
+
'browser-security/no-innerhtml': 'error',
|
|
101
|
+
'browser-security/no-eval': 'error',
|
|
102
|
+
// High - postMessage Security
|
|
103
|
+
'browser-security/require-postmessage-origin-check': 'error',
|
|
104
|
+
'browser-security/no-postmessage-wildcard-origin': 'error',
|
|
105
|
+
'browser-security/no-postmessage-innerhtml': 'error',
|
|
106
|
+
// High - Storage Security
|
|
107
|
+
'browser-security/no-sensitive-localstorage': 'error',
|
|
108
|
+
'browser-security/no-jwt-in-storage': 'error',
|
|
109
|
+
'browser-security/no-sensitive-sessionstorage': 'error',
|
|
110
|
+
'browser-security/no-sensitive-indexeddb': 'error',
|
|
111
|
+
// High - Cookie Security
|
|
112
|
+
'browser-security/no-sensitive-cookie-js': 'error',
|
|
113
|
+
'browser-security/no-cookie-auth-tokens': 'error',
|
|
114
|
+
'browser-security/require-cookie-secure-attrs': 'error',
|
|
115
|
+
// High - WebSocket Security
|
|
116
|
+
'browser-security/require-websocket-wss': 'error',
|
|
117
|
+
'browser-security/no-websocket-innerhtml': 'error',
|
|
118
|
+
'browser-security/no-websocket-eval': 'error',
|
|
119
|
+
// High - File API Security
|
|
120
|
+
'browser-security/no-filereader-innerhtml': 'error',
|
|
121
|
+
'browser-security/require-blob-url-revocation': 'warn',
|
|
122
|
+
// Medium - Workers Security
|
|
123
|
+
'browser-security/no-dynamic-service-worker-url': 'error',
|
|
124
|
+
'browser-security/no-worker-message-innerhtml': 'error',
|
|
125
|
+
// Medium - CSP Security
|
|
126
|
+
'browser-security/no-unsafe-inline-csp': 'error',
|
|
127
|
+
'browser-security/no-unsafe-eval-csp': 'error',
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Preset configurations for browser security rules
|
|
131
|
+
*/
|
|
132
|
+
exports.configs = {
|
|
133
|
+
/**
|
|
134
|
+
* Recommended security configuration
|
|
135
|
+
*/
|
|
136
|
+
recommended: {
|
|
137
|
+
plugins: {
|
|
138
|
+
'browser-security': exports.plugin,
|
|
139
|
+
},
|
|
140
|
+
rules: recommendedRules,
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Strict security configuration - all rules as errors
|
|
144
|
+
*/
|
|
145
|
+
strict: {
|
|
146
|
+
plugins: {
|
|
147
|
+
'browser-security': exports.plugin,
|
|
148
|
+
},
|
|
149
|
+
rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [
|
|
150
|
+
`browser-security/${ruleName}`,
|
|
151
|
+
'error',
|
|
152
|
+
])),
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* XSS-focused configuration
|
|
156
|
+
*/
|
|
157
|
+
xss: {
|
|
158
|
+
plugins: {
|
|
159
|
+
'browser-security': exports.plugin,
|
|
160
|
+
},
|
|
161
|
+
rules: {
|
|
162
|
+
'browser-security/no-innerhtml': 'error',
|
|
163
|
+
'browser-security/no-eval': 'error',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Storage security configuration
|
|
168
|
+
*/
|
|
169
|
+
storage: {
|
|
170
|
+
plugins: {
|
|
171
|
+
'browser-security': exports.plugin,
|
|
172
|
+
},
|
|
173
|
+
rules: {
|
|
174
|
+
'browser-security/no-sensitive-localstorage': 'error',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* postMessage security configuration
|
|
179
|
+
*/
|
|
180
|
+
postmessage: {
|
|
181
|
+
plugins: {
|
|
182
|
+
'browser-security': exports.plugin,
|
|
183
|
+
},
|
|
184
|
+
rules: {
|
|
185
|
+
'browser-security/require-postmessage-origin-check': 'error',
|
|
186
|
+
'browser-security/no-postmessage-wildcard-origin': 'error',
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* WebSocket security configuration
|
|
191
|
+
*/
|
|
192
|
+
websocket: {
|
|
193
|
+
plugins: {
|
|
194
|
+
'browser-security': exports.plugin,
|
|
195
|
+
},
|
|
196
|
+
rules: {
|
|
197
|
+
'browser-security/require-websocket-wss': 'error',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
/**
|
|
201
|
+
* Cookie security configuration
|
|
202
|
+
*/
|
|
203
|
+
cookies: {
|
|
204
|
+
plugins: {
|
|
205
|
+
'browser-security': exports.plugin,
|
|
206
|
+
},
|
|
207
|
+
rules: {
|
|
208
|
+
'browser-security/no-sensitive-cookie-js': 'error',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Default export for ESLint plugin
|
|
214
|
+
*/
|
|
215
|
+
exports.default = exports.plugin;
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/eslint-plugin-browser-security/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAIH,uBAAuB;AACvB,uDAAmD;AACnD,6CAAyC;AAEzC,uBAAuB;AACvB,+FAAyF;AACzF,2FAAqF;AACrF,+EAA0E;AAE1E,mBAAmB;AACnB,iFAA4E;AAC5E,iEAA2D;AAC3D,qFAAgF;AAChF,2EAAsE;AAEtE,kBAAkB;AAClB,2EAAqE;AACrE,yEAAmE;AACnE,qFAA+E;AAE/E,qBAAqB;AACrB,yEAAoE;AACpE,2EAAsE;AACtE,iEAA4D;AAE5D,oBAAoB;AACpB,6EAAwE;AACxE,qFAA+E;AAE/E,mBAAmB;AACnB,yFAAkF;AAClF,qFAA+E;AAE/E,eAAe;AACf,uEAAiE;AACjE,mEAA6D;AAE7D;;GAEG;AACU,QAAA,KAAK,GAGd;IACF,iBAAiB;IAC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AE,OAAO;SAC3D;KACmC;IAEtC;;OAEG;IACH,SAAS,EAAE;QACT,OAAO,EAAE;YACP,kBAAkB,EAAE,cAAM;SAC3B;QACD,KAAK,EAAE;YACL,wCAAwC,EAAE,OAAO;SAClD;KACmC;IAEtC;;OAEG;IACH,OAAO,EAAE;QACP,OAAO,EAAE;YACP,kBAAkB,EAAE,cAAM;SAC3B;QACD,KAAK,EAAE;YACL,yCAAyC,EAAE,OAAO;SACnD;KACmC;CACvC,CAAC;AAEF;;GAEG;AACH,kBAAe,cAAM,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noCookieAuthTokens = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
// Auth token patterns
|
|
6
|
+
const AUTH_PATTERNS = [
|
|
7
|
+
/token/i,
|
|
8
|
+
/jwt/i,
|
|
9
|
+
/auth/i,
|
|
10
|
+
/session/i,
|
|
11
|
+
/bearer/i,
|
|
12
|
+
/access/i,
|
|
13
|
+
/refresh/i,
|
|
14
|
+
/credential/i,
|
|
15
|
+
];
|
|
16
|
+
function isAuthToken(cookieString) {
|
|
17
|
+
return AUTH_PATTERNS.some((p) => p.test(cookieString));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extract string parts from a binary expression (concatenation)
|
|
21
|
+
* e.g., 'accessToken=' + token => 'accessToken='
|
|
22
|
+
*/
|
|
23
|
+
function extractStringParts(node) {
|
|
24
|
+
const parts = [];
|
|
25
|
+
function traverse(n) {
|
|
26
|
+
if (n.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof n.value === 'string') {
|
|
27
|
+
parts.push(n.value);
|
|
28
|
+
}
|
|
29
|
+
else if (n.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && n.operator === '+') {
|
|
30
|
+
traverse(n.left);
|
|
31
|
+
traverse(n.right);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
traverse(node);
|
|
35
|
+
return parts.join('');
|
|
36
|
+
}
|
|
37
|
+
exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
38
|
+
name: 'no-cookie-auth-tokens',
|
|
39
|
+
meta: {
|
|
40
|
+
type: 'problem',
|
|
41
|
+
docs: {
|
|
42
|
+
description: 'Disallow storing auth tokens in cookies via JavaScript',
|
|
43
|
+
},
|
|
44
|
+
hasSuggestions: true,
|
|
45
|
+
messages: {
|
|
46
|
+
authTokenInCookie: (0, eslint_devkit_1.formatLLMMessage)({
|
|
47
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
48
|
+
issueName: 'Auth Token in JS-Accessible Cookie',
|
|
49
|
+
cwe: 'CWE-1004',
|
|
50
|
+
owasp: 'A02:2021',
|
|
51
|
+
cvss: 8.5,
|
|
52
|
+
description: 'Setting auth token in document.cookie makes it accessible to XSS attacks. Use HttpOnly cookies set by the server.',
|
|
53
|
+
severity: 'HIGH',
|
|
54
|
+
fix: 'Set auth cookies from server with HttpOnly flag.',
|
|
55
|
+
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#httponly-attribute',
|
|
56
|
+
}),
|
|
57
|
+
useHttpOnlyCookie: (0, eslint_devkit_1.formatLLMMessage)({
|
|
58
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
59
|
+
issueName: 'Use HttpOnly Cookie',
|
|
60
|
+
description: 'Set cookies from server with HttpOnly flag',
|
|
61
|
+
severity: 'LOW',
|
|
62
|
+
fix: 'res.cookie("token", value, { httpOnly: true, secure: true });',
|
|
63
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
schema: [
|
|
67
|
+
{
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: { allowInTests: { type: 'boolean', default: true } },
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
defaultOptions: [{ allowInTests: true }],
|
|
75
|
+
create(context, [options = {}]) {
|
|
76
|
+
const { allowInTests = true } = options;
|
|
77
|
+
const filename = context.filename || context.getFilename();
|
|
78
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
79
|
+
if (allowInTests && isTestFile) {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
AssignmentExpression(node) {
|
|
84
|
+
// Check for document.cookie = ...
|
|
85
|
+
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
86
|
+
node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
87
|
+
node.left.object.name === 'document' &&
|
|
88
|
+
node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
89
|
+
node.left.property.name === 'cookie') {
|
|
90
|
+
let cookieValue = '';
|
|
91
|
+
if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
92
|
+
typeof node.right.value === 'string') {
|
|
93
|
+
cookieValue = node.right.value;
|
|
94
|
+
}
|
|
95
|
+
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
96
|
+
// Check template literal quasis
|
|
97
|
+
cookieValue = node.right.quasis.map((q) => q.value.raw).join('');
|
|
98
|
+
}
|
|
99
|
+
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
100
|
+
// Handle string concatenation: 'accessToken=' + token
|
|
101
|
+
cookieValue = extractStringParts(node.right);
|
|
102
|
+
}
|
|
103
|
+
if (cookieValue && isAuthToken(cookieValue)) {
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
messageId: 'authTokenInCookie',
|
|
107
|
+
suggest: [{ messageId: 'useHttpOnlyCookie', fix: /* c8 ignore next */ () => null }],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-browser-security/src/rules/no-cookie-auth-tokens/index.ts"],"names":[],"mappings":";;;AAQA,4DAKkC;AAWlC,sBAAsB;AACtB,MAAM,aAAa,GAAG;IACpB,QAAQ;IACR,MAAM;IACN,OAAO;IACP,UAAU;IACV,SAAS;IACT,SAAS;IACT,UAAU;IACV,aAAa;CACd,CAAC;AAEF,SAAS,WAAW,CAAC,YAAoB;IACvC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAA+B;IACzD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,SAAS,QAAQ,CAAC,CAAgB;QAChC,IAAI,CAAC,CAAC,IAAI,KAAK,8BAAc,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,8BAAc,CAAC,gBAAgB,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;YAC5E,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACjB,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAEY,QAAA,kBAAkB,GA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CAAC,WAAW,CAAC,EAAE,CAAC;wBAC5C,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,mBAAmB;4BAC9B,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,mBAAmB,EAAE,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;yBACpF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noDynamicServiceWorkerUrl = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
exports.noDynamicServiceWorkerUrl = (0, eslint_devkit_1.createRule)({
|
|
6
|
+
name: 'no-dynamic-service-worker-url',
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Disallow dynamic URLs in service worker registration',
|
|
11
|
+
},
|
|
12
|
+
hasSuggestions: true,
|
|
13
|
+
messages: {
|
|
14
|
+
dynamicSwUrl: (0, eslint_devkit_1.formatLLMMessage)({
|
|
15
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
16
|
+
issueName: 'Dynamic Service Worker URL',
|
|
17
|
+
cwe: 'CWE-829',
|
|
18
|
+
owasp: 'A08:2021',
|
|
19
|
+
cvss: 8.1,
|
|
20
|
+
description: 'Using dynamic URL for service worker registration. A compromised URL could give attacker persistent control over the page.',
|
|
21
|
+
severity: 'HIGH',
|
|
22
|
+
fix: 'Use a static, hardcoded path for service worker registration.',
|
|
23
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register',
|
|
24
|
+
}),
|
|
25
|
+
useStaticUrl: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
27
|
+
issueName: 'Use Static URL',
|
|
28
|
+
description: 'Use a static path for service worker',
|
|
29
|
+
severity: 'LOW',
|
|
30
|
+
fix: "navigator.serviceWorker.register('/sw.js');",
|
|
31
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register',
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
schema: [
|
|
35
|
+
{
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: { allowInTests: { type: 'boolean', default: true } },
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
defaultOptions: [{ allowInTests: true }],
|
|
43
|
+
create(context, [options = {}]) {
|
|
44
|
+
const { allowInTests = true } = options;
|
|
45
|
+
const filename = context.filename || context.getFilename();
|
|
46
|
+
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
47
|
+
if (allowInTests && isTestFile) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
CallExpression(node) {
|
|
52
|
+
// Check for navigator.serviceWorker.register(url)
|
|
53
|
+
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
54
|
+
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
55
|
+
node.callee.property.name === 'register') {
|
|
56
|
+
const obj = node.callee.object;
|
|
57
|
+
// Check if it's navigator.serviceWorker.register
|
|
58
|
+
if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
59
|
+
obj.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
60
|
+
obj.property.name === 'serviceWorker') {
|
|
61
|
+
const urlArg = node.arguments[0];
|
|
62
|
+
if (!urlArg)
|
|
63
|
+
return;
|
|
64
|
+
// Allow string literals (static URLs)
|
|
65
|
+
if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// Flag any non-literal URL
|
|
69
|
+
context.report({
|
|
70
|
+
node,
|
|
71
|
+
messageId: 'dynamicSwUrl',
|
|
72
|
+
suggest: [{ messageId: 'useStaticUrl', fix: () => null }],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-browser-security/src/rules/no-dynamic-service-worker-url/index.ts"],"names":[],"mappings":";;;AAQA,4DAKkC;AAWrB,QAAA,yBAAyB,GAAG,IAAA,0BAAU,EAA0B;IAC3E,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sDAAsD;SACpE;QACD,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE;YACR,YAAY,EAAE,IAAA,gCAAgB,EAAC;gBAC7B,IAAI,EAAE,4BAAY,CAAC,QAAQ;gBAC3B,SAAS,EAAE,4BAA4B;gBACvC,GAAG,EAAE,SAAS;gBACd,KAAK,EAAE,UAAU;gBACjB,IAAI,EAAE,GAAG;gBACT,WAAW,EACT,4HAA4H;gBAC9H,QAAQ,EAAE,MAAM;gBAChB,GAAG,EAAE,+DAA+D;gBACpE,iBAAiB,EACf,kFAAkF;aACrF,CAAC;YACF,YAAY,EAAE,IAAA,gCAAgB,EAAC;gBAC7B,IAAI,EAAE,4BAAY,CAAC,IAAI;gBACvB,SAAS,EAAE,gBAAgB;gBAC3B,WAAW,EAAE,sCAAsC;gBACnD,QAAQ,EAAE,KAAK;gBACf,GAAG,EAAE,6CAA6C;gBAClD,iBAAiB,EACf,kFAAkF;aACrF,CAAC;SACH;QACD,MAAM,E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AEpB,sCAAsC;wBACtC,IAAI,MAAM,CAAC,IAAI,KAAK,8BAAc,CAAC,OAAO,EAAE,CAAC;4BAC3C,OAAO;wBACT,CAAC;wBAED,2BAA2B;wBAC3B,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,cAAc;4BACzB,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;yBAC1D,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow in test files. Default: false */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Allow Function constructor. Default: false */
|
|
5
|
+
allowFunctionConstructor?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const noEval: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noEval = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
const DANGEROUS_FUNCTIONS = new Set([
|
|
6
|
+
'eval',
|
|
7
|
+
'execScript', // IE legacy
|
|
8
|
+
]);
|
|
9
|
+
const DANGEROUS_METHODS_WITH_STRING_ARG = new Set([
|
|
10
|
+
'setTimeout',
|
|
11
|
+
'setInterval',
|
|
12
|
+
'setImmediate',
|
|
13
|
+
]);
|
|
14
|
+
exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
15
|
+
name: 'no-eval',
|
|
16
|
+
meta: {
|
|
17
|
+
type: 'problem',
|
|
18
|
+
docs: {
|
|
19
|
+
description: 'Disallow eval(), Function(), and other code execution patterns',
|
|
20
|
+
},
|
|
21
|
+
hasSuggestions: true,
|
|
22
|
+
messages: {
|
|
23
|
+
dangerousEval: (0, eslint_devkit_1.formatLLMMessage)({
|
|
24
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
25
|
+
issueName: 'Code Injection via {{function}}',
|
|
26
|
+
cwe: 'CWE-95',
|
|
27
|
+
description: 'Using {{function}} with dynamic input can execute arbitrary code. This is a critical security vulnerability.',
|
|
28
|
+
severity: 'CRITICAL',
|
|
29
|
+
fix: 'Use safe alternatives like JSON.parse() for data, or refactor to avoid dynamic code execution.',
|
|
30
|
+
documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
|
|
31
|
+
}),
|
|
32
|
+
useSafeAlternative: (0, eslint_devkit_1.formatLLMMessage)({
|
|
33
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
34
|
+
issueName: 'Use Safe Alternative',
|
|
35
|
+
description: 'Replace with a safe alternative',
|
|
36
|
+
severity: 'LOW',
|
|
37
|
+
fix: 'Use JSON.parse() for JSON, or define functions statically.',
|
|
38
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!',
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
schema: [
|
|
42
|
+
{
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
allowInTests: {
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
default: false,
|
|
48
|
+
},
|
|
49
|
+
allowFunctionConstructor: {
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
default: false,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
defaultOptions: [
|
|
59
|
+
{
|
|
60
|
+
allowInTests: false,
|
|
61
|
+
allowFunctionConstructor: false,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
create(context, [options = {}]) {
|
|
65
|
+
const { allowInTests = false, allowFunctionConstructor = false } = options;
|
|
66
|
+
const filename = context.filename;
|
|
67
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
68
|
+
if (isTestFile) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
CallExpression(node) {
|
|
73
|
+
const callee = node.callee;
|
|
74
|
+
// Check for eval(), execScript()
|
|
75
|
+
if (callee.type === 'Identifier') {
|
|
76
|
+
if (DANGEROUS_FUNCTIONS.has(callee.name)) {
|
|
77
|
+
context.report({
|
|
78
|
+
node,
|
|
79
|
+
messageId: 'dangerousEval',
|
|
80
|
+
data: { function: callee.name },
|
|
81
|
+
suggest: [
|
|
82
|
+
{
|
|
83
|
+
messageId: 'useSafeAlternative',
|
|
84
|
+
fix: () => null,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Check for setTimeout/setInterval with string argument
|
|
91
|
+
if (DANGEROUS_METHODS_WITH_STRING_ARG.has(callee.name)) {
|
|
92
|
+
const firstArg = node.arguments[0];
|
|
93
|
+
if (firstArg &&
|
|
94
|
+
firstArg.type === 'Literal' &&
|
|
95
|
+
typeof firstArg.value === 'string') {
|
|
96
|
+
context.report({
|
|
97
|
+
node,
|
|
98
|
+
messageId: 'dangerousEval',
|
|
99
|
+
data: { function: `${callee.name} with string` },
|
|
100
|
+
suggest: [
|
|
101
|
+
{
|
|
102
|
+
messageId: 'useSafeAlternative',
|
|
103
|
+
fix: () => null,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Check for window.eval, global.eval
|
|
111
|
+
if (callee.type === 'MemberExpression' &&
|
|
112
|
+
callee.property.type === 'Identifier' &&
|
|
113
|
+
DANGEROUS_FUNCTIONS.has(callee.property.name)) {
|
|
114
|
+
context.report({
|
|
115
|
+
node,
|
|
116
|
+
messageId: 'dangerousEval',
|
|
117
|
+
data: { function: callee.property.name },
|
|
118
|
+
suggest: [
|
|
119
|
+
{
|
|
120
|
+
messageId: 'useSafeAlternative',
|
|
121
|
+
fix: () => null,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
// Check for new Function()
|
|
128
|
+
NewExpression(node) {
|
|
129
|
+
if (allowFunctionConstructor) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const callee = node.callee;
|
|
133
|
+
if (callee.type === 'Identifier' && callee.name === 'Function') {
|
|
134
|
+
context.report({
|
|
135
|
+
node,
|
|
136
|
+
messageId: 'dangerousEval',
|
|
137
|
+
data: { function: 'Function constructor' },
|
|
138
|
+
suggest: [
|
|
139
|
+
{
|
|
140
|
+
messageId: 'useSafeAlternative',
|
|
141
|
+
fix: () => null,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-browser-security/src/rules/no-eval/index.ts"],"names":[],"mappings":";;;AASA,4DAIkC;AAclC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,MAAM;IACN,YAAY,EAAE,YAAY;CAC3B,CAAC,CAAC;AAEH,MAAM,iCAAiC,GAAG,IAAI,GAAG,CAAC;IAChD,YAAY;IACZ,aAAa;IACb,cAAc;CACf,CAAC,CAAC;AAEU,QAAA,MAAM,GAAG,IAAA,0BAAU,EAA0B;IACxD,IAAI,EAAE,SAAS;IACf,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,gEAAgE;SACnE;QACD,cAAc,EAA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