eslint-plugin-browser-security 1.2.12 → 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 -3
- package/src/index.js +1 -203
- 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,361 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noClickjacking = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const eslint_devkit_3 = require("@interlace/eslint-devkit");
|
|
7
|
-
exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
8
|
-
name: 'no-clickjacking',
|
|
9
|
-
meta: {
|
|
10
|
-
type: 'problem',
|
|
11
|
-
deprecated: true,
|
|
12
|
-
replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
|
|
13
|
-
docs: {
|
|
14
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-clickjacking.md',
|
|
15
|
-
description: 'Detects clickjacking vulnerabilities and missing frame protections',
|
|
16
|
-
cwe: 'CWE-1021',
|
|
17
|
-
},
|
|
18
|
-
hasSuggestions: true,
|
|
19
|
-
messages: {
|
|
20
|
-
clickjackingVulnerability: (0, eslint_devkit_2.formatLLMMessage)({
|
|
21
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
22
|
-
issueName: 'Clickjacking Vulnerability',
|
|
23
|
-
cwe: 'CWE-1021',
|
|
24
|
-
description: 'Clickjacking protection missing',
|
|
25
|
-
severity: '{{severity}}',
|
|
26
|
-
fix: '{{safeAlternative}}',
|
|
27
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
28
|
-
}),
|
|
29
|
-
missingFrameBusting: (0, eslint_devkit_2.formatLLMMessage)({
|
|
30
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
31
|
-
issueName: 'Missing Frame Busting',
|
|
32
|
-
cwe: 'CWE-1021',
|
|
33
|
-
description: 'No frame-busting code to prevent clickjacking',
|
|
34
|
-
severity: 'HIGH',
|
|
35
|
-
fix: 'Add frame-busting JavaScript to prevent framing',
|
|
36
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
37
|
-
}),
|
|
38
|
-
unsafeIframeUsage: (0, eslint_devkit_2.formatLLMMessage)({
|
|
39
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
40
|
-
issueName: 'Unsafe iframe Usage',
|
|
41
|
-
cwe: 'CWE-1021',
|
|
42
|
-
description: 'iframe may enable clickjacking attacks',
|
|
43
|
-
severity: 'MEDIUM',
|
|
44
|
-
fix: 'Add X-Frame-Options or CSP frame-ancestors protection',
|
|
45
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
46
|
-
}),
|
|
47
|
-
missingXFrameOptions: (0, eslint_devkit_2.formatLLMMessage)({
|
|
48
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
49
|
-
issueName: 'Missing X-Frame-Options',
|
|
50
|
-
cwe: 'CWE-1021',
|
|
51
|
-
description: 'X-Frame-Options header not set',
|
|
52
|
-
severity: 'HIGH',
|
|
53
|
-
fix: 'Set X-Frame-Options: DENY or SAMEORIGIN',
|
|
54
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options',
|
|
55
|
-
}),
|
|
56
|
-
missingCspFrameAncestors: (0, eslint_devkit_2.formatLLMMessage)({
|
|
57
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
58
|
-
issueName: 'Missing CSP frame-ancestors',
|
|
59
|
-
cwe: 'CWE-1021',
|
|
60
|
-
description: 'CSP frame-ancestors directive not configured',
|
|
61
|
-
severity: 'HIGH',
|
|
62
|
-
fix: 'Add frame-ancestors to Content-Security-Policy',
|
|
63
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors',
|
|
64
|
-
}),
|
|
65
|
-
transparentFrameOverlay: (0, eslint_devkit_2.formatLLMMessage)({
|
|
66
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
67
|
-
issueName: 'Transparent Frame Overlay',
|
|
68
|
-
cwe: 'CWE-1021',
|
|
69
|
-
description: 'Transparent elements may hide clickjacking attacks',
|
|
70
|
-
severity: 'MEDIUM',
|
|
71
|
-
fix: 'Use frame-busting or CSP protections',
|
|
72
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
73
|
-
}),
|
|
74
|
-
frameManipulation: (0, eslint_devkit_2.formatLLMMessage)({
|
|
75
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
76
|
-
issueName: 'Frame Manipulation',
|
|
77
|
-
cwe: 'CWE-1021',
|
|
78
|
-
description: 'Code attempts to manipulate parent frames',
|
|
79
|
-
severity: 'LOW',
|
|
80
|
-
fix: 'Implement proper frame communication or prevent framing',
|
|
81
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
82
|
-
}),
|
|
83
|
-
implementFrameBusting: (0, eslint_devkit_2.formatLLMMessage)({
|
|
84
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
85
|
-
issueName: 'Implement Frame Busting',
|
|
86
|
-
description: 'Add JavaScript to prevent framing',
|
|
87
|
-
severity: 'LOW',
|
|
88
|
-
fix: 'if (top != self) top.location = location;',
|
|
89
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
90
|
-
}),
|
|
91
|
-
useXFrameOptions: (0, eslint_devkit_2.formatLLMMessage)({
|
|
92
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
93
|
-
issueName: 'Use X-Frame-Options',
|
|
94
|
-
description: 'Set X-Frame-Options HTTP header',
|
|
95
|
-
severity: 'LOW',
|
|
96
|
-
fix: 'X-Frame-Options: DENY',
|
|
97
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options',
|
|
98
|
-
}),
|
|
99
|
-
setCspFrameAncestors: (0, eslint_devkit_2.formatLLMMessage)({
|
|
100
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
101
|
-
issueName: 'Set CSP frame-ancestors',
|
|
102
|
-
description: 'Configure CSP frame-ancestors directive',
|
|
103
|
-
severity: 'LOW',
|
|
104
|
-
fix: 'frame-ancestors \'self\' https://trusted.com',
|
|
105
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors',
|
|
106
|
-
}),
|
|
107
|
-
strategyFrameProtection: (0, eslint_devkit_2.formatLLMMessage)({
|
|
108
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
109
|
-
issueName: 'Frame Protection Strategy',
|
|
110
|
-
description: 'Implement multiple layers of frame protection',
|
|
111
|
-
severity: 'LOW',
|
|
112
|
-
fix: 'Use X-Frame-Options, CSP, and frame-busting together',
|
|
113
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
114
|
-
}),
|
|
115
|
-
strategyContentSecurity: (0, eslint_devkit_2.formatLLMMessage)({
|
|
116
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
117
|
-
issueName: 'Content Security Strategy',
|
|
118
|
-
description: 'Use CSP for comprehensive frame control',
|
|
119
|
-
severity: 'LOW',
|
|
120
|
-
fix: 'Implement strict CSP with frame-ancestors',
|
|
121
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP',
|
|
122
|
-
}),
|
|
123
|
-
strategyUserInteraction: (0, eslint_devkit_2.formatLLMMessage)({
|
|
124
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
125
|
-
issueName: 'User Interaction Strategy',
|
|
126
|
-
description: 'Protect user interactions from framing attacks',
|
|
127
|
-
severity: 'LOW',
|
|
128
|
-
fix: 'Validate user intent for sensitive actions',
|
|
129
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
|
|
130
|
-
})
|
|
131
|
-
},
|
|
132
|
-
schema: [
|
|
133
|
-
{
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: {
|
|
136
|
-
trustedSources: {
|
|
137
|
-
type: 'array',
|
|
138
|
-
items: { type: 'string' },
|
|
139
|
-
default: ['self', 'same-origin'],
|
|
140
|
-
},
|
|
141
|
-
requireFrameBusting: {
|
|
142
|
-
type: 'boolean',
|
|
143
|
-
default: true,
|
|
144
|
-
},
|
|
145
|
-
detectTransparentOverlays: {
|
|
146
|
-
type: 'boolean',
|
|
147
|
-
default: true,
|
|
148
|
-
},
|
|
149
|
-
trustedSanitizers: {
|
|
150
|
-
type: 'array',
|
|
151
|
-
items: { type: 'string' },
|
|
152
|
-
default: [],
|
|
153
|
-
description: 'Additional function names to consider as frame protectors',
|
|
154
|
-
},
|
|
155
|
-
trustedAnnotations: {
|
|
156
|
-
type: 'array',
|
|
157
|
-
items: { type: 'string' },
|
|
158
|
-
default: [],
|
|
159
|
-
description: 'Additional JSDoc annotations to consider as safe markers',
|
|
160
|
-
},
|
|
161
|
-
strictMode: {
|
|
162
|
-
type: 'boolean',
|
|
163
|
-
default: false,
|
|
164
|
-
description: 'Disable all false positive detection (strict mode)',
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
additionalProperties: false,
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
},
|
|
171
|
-
defaultOptions: [
|
|
172
|
-
{
|
|
173
|
-
trustedSources: ['self', 'same-origin'],
|
|
174
|
-
requireFrameBusting: true,
|
|
175
|
-
detectTransparentOverlays: true,
|
|
176
|
-
trustedSanitizers: [],
|
|
177
|
-
trustedAnnotations: [],
|
|
178
|
-
strictMode: false,
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
create(context) {
|
|
182
|
-
const options = context.options[0] || {};
|
|
183
|
-
const { trustedSources = ['self', 'same-origin'], requireFrameBusting = true, detectTransparentOverlays = true, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
|
|
184
|
-
const sourceCode = context.sourceCode;
|
|
185
|
-
const filename = context.filename;
|
|
186
|
-
const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
|
|
187
|
-
trustedSanitizers,
|
|
188
|
-
trustedAnnotations,
|
|
189
|
-
trustedOrmPatterns: [],
|
|
190
|
-
strictMode,
|
|
191
|
-
});
|
|
192
|
-
let hasFrameBusting = false;
|
|
193
|
-
const isTrustedSource = (source) => {
|
|
194
|
-
return trustedSources.some(trusted => source.includes(trusted) ||
|
|
195
|
-
(trusted === 'self' && (source === 'self' || source.startsWith('/'))) ||
|
|
196
|
-
(trusted === 'same-origin' && source === 'same-origin'));
|
|
197
|
-
};
|
|
198
|
-
const isFrameBustingCode = (node) => {
|
|
199
|
-
const test = node.test;
|
|
200
|
-
const testText = sourceCode.getText(test).toLowerCase();
|
|
201
|
-
return testText.includes('top != self') ||
|
|
202
|
-
testText.includes('top !== self') ||
|
|
203
|
-
testText.includes('window.top !== window.self') ||
|
|
204
|
-
testText.includes('parent != self') ||
|
|
205
|
-
testText.includes('top.location') ||
|
|
206
|
-
testText.includes('self.location');
|
|
207
|
-
};
|
|
208
|
-
const hasTransparentStyles = (styleText) => {
|
|
209
|
-
const styles = styleText.toLowerCase();
|
|
210
|
-
return styles.includes('opacity: 0') ||
|
|
211
|
-
styles.includes('opacity:0') ||
|
|
212
|
-
styles.includes('visibility: hidden') ||
|
|
213
|
-
styles.includes('display: none') ||
|
|
214
|
-
styles.includes('z-index: -1') ||
|
|
215
|
-
styles.includes('position: absolute') && styles.includes('top: 0') && styles.includes('left: 0');
|
|
216
|
-
};
|
|
217
|
-
return {
|
|
218
|
-
IfStatement(node) {
|
|
219
|
-
if (isFrameBustingCode(node)) {
|
|
220
|
-
hasFrameBusting = true;
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
JSXElement(node) {
|
|
224
|
-
if (node.openingElement.name.type === 'JSXIdentifier' &&
|
|
225
|
-
node.openingElement.name.name === 'iframe') {
|
|
226
|
-
const attributes = node.openingElement.attributes;
|
|
227
|
-
let hasSrc = false;
|
|
228
|
-
let srcValue = '';
|
|
229
|
-
for (const attr of attributes) {
|
|
230
|
-
if (attr.type === 'JSXAttribute' &&
|
|
231
|
-
attr.name.type === 'JSXIdentifier' &&
|
|
232
|
-
attr.name.name === 'src' &&
|
|
233
|
-
attr.value) {
|
|
234
|
-
hasSrc = true;
|
|
235
|
-
if (attr.value.type === 'Literal' && typeof attr.value.value === 'string') {
|
|
236
|
-
srcValue = attr.value.value;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (hasSrc && srcValue && !isTrustedSource(srcValue)) {
|
|
241
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
context.report({
|
|
245
|
-
node: node.openingElement,
|
|
246
|
-
messageId: 'unsafeIframeUsage',
|
|
247
|
-
data: {
|
|
248
|
-
filePath: filename,
|
|
249
|
-
line: String(node.loc?.start.line ?? 0),
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
MemberExpression(node) {
|
|
256
|
-
if (node.object.type === 'Identifier' &&
|
|
257
|
-
(node.object.name === 'top' || node.object.name === 'window')) {
|
|
258
|
-
if (node.property.type === 'Identifier' &&
|
|
259
|
-
(node.property.name === 'location' || node.property.name === 'top')) {
|
|
260
|
-
let current = node;
|
|
261
|
-
let isFrameManipulation = false;
|
|
262
|
-
while (current) {
|
|
263
|
-
if (current.type === 'AssignmentExpression' &&
|
|
264
|
-
current.left === node) {
|
|
265
|
-
isFrameManipulation = true;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
if (current.type === 'BinaryExpression' &&
|
|
269
|
-
(current.left === node || current.right === node)) {
|
|
270
|
-
const operator = current.operator;
|
|
271
|
-
if (operator === '!=' || operator === '!==' ||
|
|
272
|
-
operator === '==' || operator === '===') {
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
isFrameManipulation = true;
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
current = current.parent;
|
|
279
|
-
}
|
|
280
|
-
if (isFrameManipulation) {
|
|
281
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
context.report({
|
|
285
|
-
node,
|
|
286
|
-
messageId: 'frameManipulation',
|
|
287
|
-
data: {
|
|
288
|
-
filePath: filename,
|
|
289
|
-
line: String(node.loc?.start.line ?? 0),
|
|
290
|
-
},
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
Literal(node) {
|
|
297
|
-
if (typeof node.value === 'string' && detectTransparentOverlays) {
|
|
298
|
-
const text = node.value.toLowerCase();
|
|
299
|
-
if ((text.includes('style=') || text.includes('css')) &&
|
|
300
|
-
hasTransparentStyles(text)) {
|
|
301
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
context.report({
|
|
305
|
-
node,
|
|
306
|
-
messageId: 'transparentFrameOverlay',
|
|
307
|
-
data: {
|
|
308
|
-
filePath: filename,
|
|
309
|
-
line: String(node.loc?.start.line ?? 0),
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
TemplateLiteral(node) {
|
|
316
|
-
if (detectTransparentOverlays) {
|
|
317
|
-
const text = sourceCode.getText(node).toLowerCase();
|
|
318
|
-
if (text.includes('style') && hasTransparentStyles(text)) {
|
|
319
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
context.report({
|
|
323
|
-
node,
|
|
324
|
-
messageId: 'transparentFrameOverlay',
|
|
325
|
-
data: {
|
|
326
|
-
filePath: filename,
|
|
327
|
-
line: String(node.loc?.start.line ?? 0),
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
'Program:exit'() {
|
|
334
|
-
if (requireFrameBusting && !hasFrameBusting) {
|
|
335
|
-
const isEntryPoint = /\.(html|htm)$/.test(filename) ||
|
|
336
|
-
/(index|app|main|page)\.(tsx|jsx)$/i.test(filename) ||
|
|
337
|
-
/pages?\/.*\.(tsx|jsx)$/i.test(filename) ||
|
|
338
|
-
/layout\.(tsx|jsx)$/i.test(filename);
|
|
339
|
-
if (!isEntryPoint) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
const fileContent = sourceCode.getText();
|
|
343
|
-
const hasUIElements = fileContent.includes('<button') ||
|
|
344
|
-
fileContent.includes('<form') ||
|
|
345
|
-
fileContent.includes('<input') ||
|
|
346
|
-
(fileContent.includes('onClick') && fileContent.includes('<'));
|
|
347
|
-
if (hasUIElements) {
|
|
348
|
-
context.report({
|
|
349
|
-
node: context.sourceCode.ast,
|
|
350
|
-
messageId: 'missingFrameBusting',
|
|
351
|
-
data: {
|
|
352
|
-
filePath: filename,
|
|
353
|
-
line: '1',
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
},
|
|
361
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noClickjacking=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const eslint_devkit_3=require("@interlace/eslint-devkit");exports.noClickjacking=(0,eslint_devkit_1.createRule)({name:"no-clickjacking",meta:{type:"problem",deprecated:true,replacedBy:["@see eslint-plugin-express-security/require-helmet"],docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-clickjacking.md",description:"Detects clickjacking vulnerabilities and missing frame protections",cwe:"CWE-1021"},hasSuggestions:true,messages:{clickjackingVulnerability:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Clickjacking Vulnerability",cwe:"CWE-1021",description:"Clickjacking protection missing",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),missingFrameBusting:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing Frame Busting",cwe:"CWE-1021",description:"No frame-busting code to prevent clickjacking",severity:"HIGH",fix:"Add frame-busting JavaScript to prevent framing",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),unsafeIframeUsage:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe iframe Usage",cwe:"CWE-1021",description:"iframe may enable clickjacking attacks",severity:"MEDIUM",fix:"Add X-Frame-Options or CSP frame-ancestors protection",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),missingXFrameOptions:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing X-Frame-Options",cwe:"CWE-1021",description:"X-Frame-Options header not set",severity:"HIGH",fix:"Set X-Frame-Options: DENY or SAMEORIGIN",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options"}),missingCspFrameAncestors:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing CSP frame-ancestors",cwe:"CWE-1021",description:"CSP frame-ancestors directive not configured",severity:"HIGH",fix:"Add frame-ancestors to Content-Security-Policy",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors"}),transparentFrameOverlay:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Transparent Frame Overlay",cwe:"CWE-1021",description:"Transparent elements may hide clickjacking attacks",severity:"MEDIUM",fix:"Use frame-busting or CSP protections",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),frameManipulation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Frame Manipulation",cwe:"CWE-1021",description:"Code attempts to manipulate parent frames",severity:"LOW",fix:"Implement proper frame communication or prevent framing",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),implementFrameBusting:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Implement Frame Busting",description:"Add JavaScript to prevent framing",severity:"LOW",fix:"if (top != self) top.location = location;",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),useXFrameOptions:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use X-Frame-Options",description:"Set X-Frame-Options HTTP header",severity:"LOW",fix:"X-Frame-Options: DENY",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options"}),setCspFrameAncestors:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Set CSP frame-ancestors",description:"Configure CSP frame-ancestors directive",severity:"LOW",fix:"frame-ancestors 'self' https://trusted.com",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors"}),strategyFrameProtection:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Frame Protection Strategy",description:"Implement multiple layers of frame protection",severity:"LOW",fix:"Use X-Frame-Options, CSP, and frame-busting together",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"}),strategyContentSecurity:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Content Security Strategy",description:"Use CSP for comprehensive frame control",severity:"LOW",fix:"Implement strict CSP with frame-ancestors",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP"}),strategyUserInteraction:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"User Interaction Strategy",description:"Protect user interactions from framing attacks",severity:"LOW",fix:"Validate user intent for sensitive actions",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html"})},schema:[{type:"object",properties:{trustedSources:{type:"array",items:{type:"string"},default:["self","same-origin"],description:"Frame-ancestor sources treated as safe"},requireFrameBusting:{type:"boolean",default:true,description:"Require frame-busting code in addition to headers"},detectTransparentOverlays:{type:"boolean",default:true,description:"Report transparent overlays positioned over clickable elements"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as frame protectors"},trustedAnnotations:{type:"array",items:{type:"string"},default:[],description:"Additional JSDoc annotations to consider as safe markers"},strictMode:{type:"boolean",default:false,description:"Disable all false positive detection (strict mode)"}},additionalProperties:false}]},defaultOptions:[{trustedSources:["self","same-origin"],requireFrameBusting:true,detectTransparentOverlays:true,trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{trustedSources=["self","same-origin"],requireFrameBusting=true,detectTransparentOverlays=true,trustedSanitizers=[],trustedAnnotations=[],strictMode=false}=options;const sourceCode=context.sourceCode;const filename=context.filename;const safetyChecker=(0,eslint_devkit_3.createSafetyChecker)({trustedSanitizers,trustedAnnotations,trustedOrmPatterns:[],strictMode});let hasFrameBusting=false;const isTrustedSource=source=>{return trustedSources.some(trusted=>source.includes(trusted)||trusted==="self"&&(source==="self"||source.startsWith("/"))||trusted==="same-origin"&&source==="same-origin")};const isFrameBustingCode=node=>{const test=node.test;const testText=sourceCode.getText(test).toLowerCase();return testText.includes("top != self")||testText.includes("top !== self")||testText.includes("window.top !== window.self")||testText.includes("parent != self")||testText.includes("top.location")||testText.includes("self.location")};const hasTransparentStyles=styleText=>{const styles=styleText.toLowerCase();return styles.includes("opacity: 0")||styles.includes("opacity:0")||styles.includes("visibility: hidden")||styles.includes("display: none")||styles.includes("z-index: -1")||styles.includes("position: absolute")&&styles.includes("top: 0")&&styles.includes("left: 0")};return{IfStatement(node){if(isFrameBustingCode(node)){hasFrameBusting=true}},JSXElement(node){if(node.openingElement.name.type==="JSXIdentifier"&&node.openingElement.name.name==="iframe"){const attributes=node.openingElement.attributes;let hasSrc=false;let srcValue="";for(const attr of attributes){if(attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="src"&&attr.value){hasSrc=true;if(attr.value.type==="Literal"&&typeof attr.value.value==="string"){srcValue=attr.value.value}}}if(hasSrc&&srcValue&&!isTrustedSource(srcValue)){if(safetyChecker.isSafe(node,context)){return}context.report({node:node.openingElement,messageId:"unsafeIframeUsage",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},MemberExpression(node){if(node.object.type==="Identifier"&&(node.object.name==="top"||node.object.name==="window")){if(node.property.type==="Identifier"&&(node.property.name==="location"||node.property.name==="top")){let current=node;let isFrameManipulation=false;while(current){if(current.type==="AssignmentExpression"&¤t.left===node){isFrameManipulation=true;break}if(current.type==="BinaryExpression"&&(current.left===node||current.right===node)){const operator=current.operator;if(operator==="!="||operator==="!=="||operator==="=="||operator==="==="){break}isFrameManipulation=true;break}current=current.parent}if(isFrameManipulation){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"frameManipulation",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}},Literal(node){if(typeof node.value==="string"&&detectTransparentOverlays){const text=node.value.toLowerCase();if((text.includes("style=")||text.includes("css"))&&hasTransparentStyles(text)){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"transparentFrameOverlay",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},TemplateLiteral(node){if(detectTransparentOverlays){const text=sourceCode.getText(node).toLowerCase();if(text.includes("style")&&hasTransparentStyles(text)){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"transparentFrameOverlay",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},"Program:exit"(){if(requireFrameBusting&&!hasFrameBusting){const isEntryPoint=/\.(html|htm)$/.test(filename)||/(index|app|main|page)\.(tsx|jsx)$/i.test(filename)||/pages?\/.*\.(tsx|jsx)$/i.test(filename)||/layout\.(tsx|jsx)$/i.test(filename);if(!isEntryPoint){return}const fileContent=sourceCode.getText();const hasUIElements=fileContent.includes("<button")||fileContent.includes("<form")||fileContent.includes("<input")||fileContent.includes("onClick")&&fileContent.includes("<");if(hasUIElements){context.report({node:context.sourceCode.ast,messageId:"missingFrameBusting",data:{filePath:filename,line:"1"}})}}}}}});
|
|
@@ -1,67 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noClientSideAuthLogic = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noClientSideAuthLogic = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-client-side-auth-logic',
|
|
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-client-side-auth-logic.md',
|
|
11
|
-
description: 'Prevent authentication logic in client code',
|
|
12
|
-
cwe: 'CWE-602',
|
|
13
|
-
cvss: 6.5,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
18
|
-
issueName: 'Client-Side Auth Logic',
|
|
19
|
-
cwe: 'CWE-602',
|
|
20
|
-
description: 'Authentication logic in client code - easily bypassed',
|
|
21
|
-
severity: 'CRITICAL',
|
|
22
|
-
fix: 'Move authentication checks to the server',
|
|
23
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/602.html',
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
schema: [],
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
function report(node) {
|
|
31
|
-
context.report({ node, messageId: 'violationDetected' });
|
|
32
|
-
}
|
|
33
|
-
const authKeywords = ['admin', 'authenticated', 'authorized', 'isAdmin', 'isAuthenticated', 'role'];
|
|
34
|
-
return {
|
|
35
|
-
IfStatement(node) {
|
|
36
|
-
if (node.test.type === 'CallExpression' &&
|
|
37
|
-
node.test.callee.type === 'MemberExpression' &&
|
|
38
|
-
node.test.callee.object.type === 'Identifier' &&
|
|
39
|
-
node.test.callee.object.name === 'localStorage' &&
|
|
40
|
-
node.test.callee.property.type === 'Identifier' &&
|
|
41
|
-
node.test.callee.property.name === 'getItem') {
|
|
42
|
-
const keyArg = node.test.arguments[0];
|
|
43
|
-
if (keyArg && keyArg.type === 'Literal') {
|
|
44
|
-
const key = String(keyArg.value).toLowerCase();
|
|
45
|
-
if (authKeywords.some(kw => key.includes(kw))) {
|
|
46
|
-
report(node);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (node.test.type === 'BinaryExpression') {
|
|
51
|
-
const checkMember = (expr) => {
|
|
52
|
-
if (expr.type === 'MemberExpression' &&
|
|
53
|
-
expr.property.type === 'Identifier' &&
|
|
54
|
-
['password', 'secret', 'token'].includes(expr.property.name)) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
};
|
|
59
|
-
if (checkMember(node.test.left) ||
|
|
60
|
-
checkMember(node.test.right)) {
|
|
61
|
-
report(node);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noClientSideAuthLogic=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noClientSideAuthLogic=(0,eslint_devkit_1.createRule)({name:"no-client-side-auth-logic",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-client-side-auth-logic.md",description:"Prevent authentication logic in client code",cwe:"CWE-602",cvss:6.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Client-Side Auth Logic",cwe:"CWE-602",description:"Authentication logic in client code - easily bypassed",severity:"CRITICAL",fix:"Move authentication checks to the server",documentationLink:"https://cwe.mitre.org/data/definitions/602.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}const authKeywords=["admin","authenticated","authorized","isAdmin","isAuthenticated","role"];return{IfStatement(node){if(node.test.type==="CallExpression"&&node.test.callee.type==="MemberExpression"&&node.test.callee.object.type==="Identifier"&&node.test.callee.object.name==="localStorage"&&node.test.callee.property.type==="Identifier"&&node.test.callee.property.name==="getItem"){const keyArg=node.test.arguments[0];if(keyArg&&keyArg.type==="Literal"){const key=String(keyArg.value).toLowerCase();if(authKeywords.some(kw=>key.includes(kw))){report(node)}}}if(node.test.type==="BinaryExpression"){const checkMember=expr=>{if(expr.type==="MemberExpression"&&expr.property.type==="Identifier"&&["password","secret","token"].includes(expr.property.name)){return true}return false};if(checkMember(node.test.left)||checkMember(node.test.right)){report(node)}}}}}});
|
|
@@ -1,109 +1 @@
|
|
|
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
|
-
const AUTH_PATTERNS = [
|
|
6
|
-
/token/i,
|
|
7
|
-
/jwt/i,
|
|
8
|
-
/auth/i,
|
|
9
|
-
/session/i,
|
|
10
|
-
/bearer/i,
|
|
11
|
-
/access/i,
|
|
12
|
-
/refresh/i,
|
|
13
|
-
/credential/i,
|
|
14
|
-
];
|
|
15
|
-
function isAuthToken(cookieString) {
|
|
16
|
-
return AUTH_PATTERNS.some((p) => p.test(cookieString));
|
|
17
|
-
}
|
|
18
|
-
function extractStringParts(node) {
|
|
19
|
-
const parts = [];
|
|
20
|
-
function traverse(n) {
|
|
21
|
-
if (n.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof n.value === 'string') {
|
|
22
|
-
parts.push(n.value);
|
|
23
|
-
}
|
|
24
|
-
else if (n.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression && n.operator === '+') {
|
|
25
|
-
traverse(n.left);
|
|
26
|
-
traverse(n.right);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
traverse(node);
|
|
30
|
-
return parts.join('');
|
|
31
|
-
}
|
|
32
|
-
exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
33
|
-
name: 'no-cookie-auth-tokens',
|
|
34
|
-
meta: {
|
|
35
|
-
type: 'problem',
|
|
36
|
-
docs: {
|
|
37
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-cookie-auth-tokens.md',
|
|
38
|
-
description: 'Disallow storing auth tokens in cookies via JavaScript',
|
|
39
|
-
cwe: 'CWE-1004',
|
|
40
|
-
cvss: 8.5,
|
|
41
|
-
},
|
|
42
|
-
hasSuggestions: true,
|
|
43
|
-
messages: {
|
|
44
|
-
authTokenInCookie: (0, eslint_devkit_1.formatLLMMessage)({
|
|
45
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
46
|
-
issueName: 'Auth Token in JS-Accessible Cookie',
|
|
47
|
-
cwe: 'CWE-1004',
|
|
48
|
-
owasp: 'A02:2021',
|
|
49
|
-
cvss: 8.5,
|
|
50
|
-
description: 'Setting auth token in document.cookie makes it accessible to XSS attacks. Use HttpOnly cookies set by the server.',
|
|
51
|
-
severity: 'HIGH',
|
|
52
|
-
fix: 'Set auth cookies from server with HttpOnly flag.',
|
|
53
|
-
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#httponly-attribute',
|
|
54
|
-
}),
|
|
55
|
-
useHttpOnlyCookie: (0, eslint_devkit_1.formatLLMMessage)({
|
|
56
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
57
|
-
issueName: 'Use HttpOnly Cookie',
|
|
58
|
-
description: 'Set cookies from server with HttpOnly flag',
|
|
59
|
-
severity: 'LOW',
|
|
60
|
-
fix: 'res.cookie("token", value, { httpOnly: true, secure: true });',
|
|
61
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
schema: [
|
|
65
|
-
{
|
|
66
|
-
type: 'object',
|
|
67
|
-
properties: { allowInTests: { type: 'boolean', default: true } },
|
|
68
|
-
additionalProperties: false,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
defaultOptions: [{ allowInTests: true }],
|
|
73
|
-
create(context, [options = {}]) {
|
|
74
|
-
const { allowInTests = true } = options;
|
|
75
|
-
const filename = context.filename;
|
|
76
|
-
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
77
|
-
if (allowInTests && isTestFile) {
|
|
78
|
-
return {};
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
AssignmentExpression(node) {
|
|
82
|
-
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
83
|
-
node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
84
|
-
node.left.object.name === 'document' &&
|
|
85
|
-
node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
86
|
-
node.left.property.name === 'cookie') {
|
|
87
|
-
let cookieValue = '';
|
|
88
|
-
if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
89
|
-
typeof node.right.value === 'string') {
|
|
90
|
-
cookieValue = node.right.value;
|
|
91
|
-
}
|
|
92
|
-
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
93
|
-
cookieValue = node.right.quasis.map((q) => q.value.raw).join('');
|
|
94
|
-
}
|
|
95
|
-
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
96
|
-
cookieValue = extractStringParts(node.right);
|
|
97
|
-
}
|
|
98
|
-
if (cookieValue && isAuthToken(cookieValue)) {
|
|
99
|
-
context.report({
|
|
100
|
-
node,
|
|
101
|
-
messageId: 'authTokenInCookie',
|
|
102
|
-
suggest: [{ messageId: 'useHttpOnlyCookie', fix: () => null }],
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCookieAuthTokens=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const AUTH_PATTERNS=[/token/i,/jwt/i,/auth/i,/session/i,/bearer/i,/access/i,/refresh/i,/credential/i];function isAuthToken(cookieString){return AUTH_PATTERNS.some(p=>p.test(cookieString))}function extractStringParts(node){const parts=[];function traverse(n){if(n.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof n.value==="string"){parts.push(n.value)}else if(n.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&n.operator==="+"){traverse(n.left);traverse(n.right)}}traverse(node);return parts.join("")}exports.noCookieAuthTokens=(0,eslint_devkit_1.createRule)({name:"no-cookie-auth-tokens",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-cookie-auth-tokens.md",description:"Disallow storing auth tokens in cookies via JavaScript",cwe:"CWE-1004",cvss:8.5},hasSuggestions:true,messages:{authTokenInCookie:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Auth Token in JS-Accessible Cookie",cwe:"CWE-1004",owasp:"A02:2021",cvss:8.5,description:"Setting auth token in document.cookie makes it accessible to XSS attacks. Use HttpOnly cookies set by the server.",severity:"HIGH",fix:"Set auth cookies from server with HttpOnly flag.",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#httponly-attribute"}),useHttpOnlyCookie:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use HttpOnly Cookie",description:"Set cookies from server with HttpOnly flag",severity:"LOW",fix:'res.cookie("token", 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}},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{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.name==="document"&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.property.name==="cookie"){let cookieValue="";if(node.right.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.right.value==="string"){cookieValue=node.right.value}else if(node.right.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){cookieValue=node.right.quasis.map(q=>q.value.raw).join("")}else if(node.right.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression){cookieValue=extractStringParts(node.right)}if(cookieValue&&isAuthToken(cookieValue)){context.report({node,messageId:"authTokenInCookie",suggest:[{messageId:"useHttpOnlyCookie",fix:()=>null}]})}}}}}});
|
|
@@ -1,55 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noCredentialsInQueryParams = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noCredentialsInQueryParams = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-credentials-in-query-params',
|
|
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-credentials-in-query-params.md',
|
|
11
|
-
description: 'Disallow credentials in URL query parameters',
|
|
12
|
-
cwe: 'CWE-798',
|
|
13
|
-
cvss: 9.8,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
18
|
-
issueName: 'Credentials in Query Parameters',
|
|
19
|
-
cwe: 'CWE-798',
|
|
20
|
-
description: 'Credentials detected in URL query parameters - this is a security risk',
|
|
21
|
-
severity: 'CRITICAL',
|
|
22
|
-
fix: 'Use secure methods: POST body, headers (Authorization), or secure cookies',
|
|
23
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/798.html',
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
schema: [],
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
const sourceCode = context.sourceCode;
|
|
31
|
-
const sensitiveParams = ['password=', 'token=', 'apikey=', 'secret=', 'auth='];
|
|
32
|
-
function report(node) {
|
|
33
|
-
context.report({
|
|
34
|
-
node,
|
|
35
|
-
messageId: 'violationDetected',
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
Literal(node) {
|
|
40
|
-
if (typeof node.value === 'string') {
|
|
41
|
-
const url = node.value.toLowerCase();
|
|
42
|
-
if (sensitiveParams.some(param => url.includes('?' + param) || url.includes('&' + param))) {
|
|
43
|
-
report(node);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
TemplateLiteral(node) {
|
|
48
|
-
const text = sourceCode.getText(node).toLowerCase();
|
|
49
|
-
if (sensitiveParams.some(param => text.includes(param))) {
|
|
50
|
-
report(node);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCredentialsInQueryParams=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noCredentialsInQueryParams=(0,eslint_devkit_1.createRule)({name:"no-credentials-in-query-params",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-credentials-in-query-params.md",description:"Disallow credentials in URL query parameters",cwe:"CWE-798",cvss:9.8},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Credentials in Query Parameters",cwe:"CWE-798",description:"Credentials detected in URL query parameters - this is a security risk",severity:"CRITICAL",fix:"Use secure methods: POST body, headers (Authorization), or secure cookies",documentationLink:"https://cwe.mitre.org/data/definitions/798.html"})},schema:[]},defaultOptions:[],create(context){const sourceCode=context.sourceCode;const sensitiveParams=["password=","token=","apikey=","secret=","auth="];function report(node){context.report({node,messageId:"violationDetected"})}return{Literal(node){if(typeof node.value==="string"){const url=node.value.toLowerCase();if(sensitiveParams.some(param=>url.includes("?"+param)||url.includes("&"+param))){report(node)}}},TemplateLiteral(node){const text=sourceCode.getText(node).toLowerCase();if(sensitiveParams.some(param=>text.includes(param))){report(node)}}}}});
|