eslint-plugin-browser-security 1.2.3 → 1.2.4
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 +125 -0
- package/README.md +111 -89
- package/package.json +21 -5
- package/src/index.js +14 -1
- package/src/oxlint.d.ts +20 -0
- package/src/oxlint.js +21 -0
- package/src/rules/detect-mixed-content/index.js +3 -0
- package/src/rules/no-allow-arbitrary-loads/index.js +3 -0
- package/src/rules/no-clickjacking/index.js +10 -5
- package/src/rules/no-client-side-auth-logic/index.js +4 -0
- package/src/rules/no-cookie-auth-tokens/index.js +4 -1
- package/src/rules/no-credentials-in-query-params/index.js +3 -0
- package/src/rules/no-disabled-certificate-validation/index.js +5 -2
- package/src/rules/no-dynamic-service-worker-url/index.js +4 -1
- package/src/rules/no-eval/index.js +34 -15
- package/src/rules/no-filereader-innerhtml/index.js +8 -5
- package/src/rules/no-http-urls/index.js +3 -0
- package/src/rules/no-innerhtml/index.js +58 -34
- package/src/rules/no-insecure-redirects/index.js +5 -2
- package/src/rules/no-insecure-websocket/index.js +3 -0
- package/src/rules/no-jwt-in-storage/index.js +7 -4
- package/src/rules/no-missing-cors-check/index.js +5 -2
- package/src/rules/no-missing-csrf-protection/index.js +3 -0
- package/src/rules/no-missing-security-headers/index.js +20 -17
- package/src/rules/no-password-in-url/index.js +3 -0
- package/src/rules/no-permissive-cors/index.js +4 -0
- package/src/rules/no-postmessage-innerhtml/index.js +8 -5
- package/src/rules/no-postmessage-wildcard-origin/index.js +4 -1
- package/src/rules/no-sensitive-cookie-js/index.js +4 -1
- package/src/rules/no-sensitive-data-in-analytics/index.js +3 -0
- package/src/rules/no-sensitive-data-in-cache/index.js +5 -1
- package/src/rules/no-sensitive-indexeddb/index.js +4 -1
- package/src/rules/no-sensitive-localstorage/index.js +3 -0
- package/src/rules/no-sensitive-sessionstorage/index.js +4 -1
- package/src/rules/no-tracking-without-consent/index.js +3 -0
- package/src/rules/no-unencrypted-transmission/index.js +5 -2
- package/src/rules/no-unescaped-url-parameter/index.js +6 -2
- package/src/rules/no-unsafe-eval-csp/index.js +4 -1
- package/src/rules/no-unsafe-inline-csp/index.js +4 -1
- package/src/rules/no-unvalidated-deeplinks/index.js +3 -0
- package/src/rules/no-websocket-eval/index.js +6 -3
- package/src/rules/no-websocket-innerhtml/index.js +8 -5
- package/src/rules/no-worker-message-innerhtml/index.js +8 -5
- package/src/rules/require-blob-url-revocation/index.js +4 -1
- package/src/rules/require-cookie-secure-attrs/index.js +4 -1
- package/src/rules/require-csp-headers/index.js +3 -0
- package/src/rules/require-https-only/index.js +3 -0
- package/src/rules/require-mime-type-validation/index.js +3 -0
- package/src/rules/require-postmessage-origin-check/index.js +3 -0
- package/src/rules/require-url-validation/index.js +3 -0
- package/src/rules/require-websocket-wss/index.js +6 -2
package/src/index.js
CHANGED
|
@@ -127,7 +127,7 @@ exports.rules = {
|
|
|
127
127
|
exports.plugin = {
|
|
128
128
|
meta: {
|
|
129
129
|
name: 'eslint-plugin-browser-security',
|
|
130
|
-
version: '
|
|
130
|
+
version: '1.2.4',
|
|
131
131
|
},
|
|
132
132
|
rules: exports.rules,
|
|
133
133
|
};
|
|
@@ -180,6 +180,19 @@ const recommendedRules = {
|
|
|
180
180
|
* Preset configurations for browser security rules
|
|
181
181
|
*/
|
|
182
182
|
exports.configs = {
|
|
183
|
+
/**
|
|
184
|
+
* Flagship preset — the rule from this plugin in the ecosystem-wide
|
|
185
|
+
* flagship list (`.agent/flagship-rules.md`). Narrow signature, no
|
|
186
|
+
* legitimate use case for `postMessage(data, '*')` — high-signal CI gate.
|
|
187
|
+
*/
|
|
188
|
+
flagship: {
|
|
189
|
+
plugins: {
|
|
190
|
+
'browser-security': exports.plugin,
|
|
191
|
+
},
|
|
192
|
+
rules: {
|
|
193
|
+
'browser-security/no-postmessage-wildcard-origin': 'error',
|
|
194
|
+
},
|
|
195
|
+
},
|
|
183
196
|
/**
|
|
184
197
|
* Recommended security configuration
|
|
185
198
|
*/
|
package/src/oxlint.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* oxlint sub-export.
|
|
8
|
+
*
|
|
9
|
+
* Consumers wire oxlint to this entry via:
|
|
10
|
+
* { "jsPlugins": ["eslint-plugin-browser-security/oxlint"] }
|
|
11
|
+
*
|
|
12
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-browser-security/oxlint')` and reads
|
|
13
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
14
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
15
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
16
|
+
*
|
|
17
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
18
|
+
*/
|
|
19
|
+
import { plugin } from './index';
|
|
20
|
+
export = plugin;
|
package/src/oxlint.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* oxlint sub-export.
|
|
9
|
+
*
|
|
10
|
+
* Consumers wire oxlint to this entry via:
|
|
11
|
+
* { "jsPlugins": ["eslint-plugin-browser-security/oxlint"] }
|
|
12
|
+
*
|
|
13
|
+
* oxlint's JS plugin loader does `require('eslint-plugin-browser-security/oxlint')` and reads
|
|
14
|
+
* `.rules` off the result. The compiled output of `export = plugin` is
|
|
15
|
+
* `module.exports = plugin`, which gives oxlint the plugin object directly
|
|
16
|
+
* (`{ meta, rules }`) — no wrapper, no `.default` indirection.
|
|
17
|
+
*
|
|
18
|
+
* Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
|
|
19
|
+
*/
|
|
20
|
+
const index_1 = require("./index");
|
|
21
|
+
module.exports = index_1.plugin;
|
|
@@ -17,7 +17,10 @@ exports.detectMixedContent = (0, eslint_devkit_1.createRule)({
|
|
|
17
17
|
meta: {
|
|
18
18
|
type: 'problem',
|
|
19
19
|
docs: {
|
|
20
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/detect-mixed-content.md',
|
|
20
21
|
description: 'Detect HTTP resources in HTTPS pages',
|
|
22
|
+
cwe: 'CWE-311',
|
|
23
|
+
cvss: 5,
|
|
21
24
|
},
|
|
22
25
|
messages: {
|
|
23
26
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -17,7 +17,10 @@ exports.noAllowArbitraryLoads = (0, eslint_devkit_1.createRule)({
|
|
|
17
17
|
meta: {
|
|
18
18
|
type: 'problem',
|
|
19
19
|
docs: {
|
|
20
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-allow-arbitrary-loads.md',
|
|
20
21
|
description: 'Prevent configuration allowing insecure loads',
|
|
22
|
+
cwe: 'CWE-295',
|
|
23
|
+
cvss: 7.5,
|
|
21
24
|
},
|
|
22
25
|
messages: {
|
|
23
26
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -16,9 +16,10 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
16
16
|
deprecated: true,
|
|
17
17
|
replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
|
|
18
18
|
docs: {
|
|
19
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-clickjacking.md',
|
|
19
20
|
description: 'Detects clickjacking vulnerabilities and missing frame protections',
|
|
21
|
+
cwe: 'CWE-1021',
|
|
20
22
|
},
|
|
21
|
-
fixable: 'code',
|
|
22
23
|
hasSuggestions: true,
|
|
23
24
|
messages: {
|
|
24
25
|
clickjackingVulnerability: (0, eslint_devkit_2.formatLLMMessage)({
|
|
@@ -185,8 +186,8 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
185
186
|
create(context) {
|
|
186
187
|
const options = context.options[0] || {};
|
|
187
188
|
const { trustedSources = ['self', 'same-origin'], requireFrameBusting = true, detectTransparentOverlays = true, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
|
|
188
|
-
const sourceCode = context.sourceCode
|
|
189
|
-
const filename = context.filename
|
|
189
|
+
const sourceCode = context.sourceCode;
|
|
190
|
+
const filename = context.filename;
|
|
190
191
|
// Create safety checker for false positive detection
|
|
191
192
|
const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
|
|
192
193
|
trustedSanitizers,
|
|
@@ -221,6 +222,7 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
221
222
|
/**
|
|
222
223
|
* Check for transparent/invisible elements that could hide clickjacking
|
|
223
224
|
*/
|
|
225
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
224
226
|
const hasTransparentStyles = (styleText) => {
|
|
225
227
|
const styles = styleText.toLowerCase();
|
|
226
228
|
return styles.includes('opacity: 0') ||
|
|
@@ -283,8 +285,11 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
283
285
|
// Check if this is being assigned or compared
|
|
284
286
|
let current = node;
|
|
285
287
|
let isFrameManipulation = false;
|
|
286
|
-
// Walk up to see if this is an assignment or comparison
|
|
287
|
-
|
|
288
|
+
// Walk up to see if this is an assignment or comparison. Every
|
|
289
|
+
// path that sets `isFrameManipulation = true` is followed by
|
|
290
|
+
// `break`, so the negation in the loop condition is redundant
|
|
291
|
+
// (CodeQL: `js/useless-conditional`).
|
|
292
|
+
while (current) {
|
|
288
293
|
if (current.type === 'AssignmentExpression' &&
|
|
289
294
|
current.left === node) {
|
|
290
295
|
isFrameManipulation = true;
|
|
@@ -15,7 +15,10 @@ exports.noClientSideAuthLogic = (0, eslint_devkit_1.createRule)({
|
|
|
15
15
|
meta: {
|
|
16
16
|
type: 'problem',
|
|
17
17
|
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-client-side-auth-logic.md',
|
|
18
19
|
description: 'Prevent authentication logic in client code',
|
|
20
|
+
cwe: 'CWE-602',
|
|
21
|
+
cvss: 9.5,
|
|
19
22
|
},
|
|
20
23
|
messages: {
|
|
21
24
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -55,6 +58,7 @@ exports.noClientSideAuthLogic = (0, eslint_devkit_1.createRule)({
|
|
|
55
58
|
}
|
|
56
59
|
// Detect password comparison
|
|
57
60
|
if (node.test.type === 'BinaryExpression') {
|
|
61
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
58
62
|
const checkMember = (expr) => {
|
|
59
63
|
if (expr.type === 'MemberExpression' &&
|
|
60
64
|
expr.property.type === 'Identifier' &&
|
|
@@ -44,7 +44,10 @@ exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
|
44
44
|
meta: {
|
|
45
45
|
type: 'problem',
|
|
46
46
|
docs: {
|
|
47
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-cookie-auth-tokens.md',
|
|
47
48
|
description: 'Disallow storing auth tokens in cookies via JavaScript',
|
|
49
|
+
cwe: 'CWE-1004',
|
|
50
|
+
cvss: 8.5,
|
|
48
51
|
},
|
|
49
52
|
hasSuggestions: true,
|
|
50
53
|
messages: {
|
|
@@ -79,7 +82,7 @@ exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
|
79
82
|
defaultOptions: [{ allowInTests: true }],
|
|
80
83
|
create(context, [options = {}]) {
|
|
81
84
|
const { allowInTests = true } = options;
|
|
82
|
-
const filename = context.filename
|
|
85
|
+
const filename = context.filename;
|
|
83
86
|
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
84
87
|
if (allowInTests && isTestFile) {
|
|
85
88
|
return {};
|
|
@@ -17,7 +17,10 @@ exports.noCredentialsInQueryParams = (0, eslint_devkit_1.createRule)({
|
|
|
17
17
|
meta: {
|
|
18
18
|
type: 'problem',
|
|
19
19
|
docs: {
|
|
20
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-credentials-in-query-params.md',
|
|
20
21
|
description: 'Disallow credentials in URL query parameters',
|
|
22
|
+
cwe: 'CWE-798',
|
|
23
|
+
cvss: 9.5,
|
|
21
24
|
},
|
|
22
25
|
messages: {
|
|
23
26
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -15,7 +15,10 @@ exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
|
|
|
15
15
|
meta: {
|
|
16
16
|
type: 'problem',
|
|
17
17
|
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-disabled-certificate-validation.md',
|
|
18
19
|
description: 'Prevent disabled SSL/TLS certificate validation',
|
|
20
|
+
cwe: 'CWE-295',
|
|
21
|
+
cvss: 9.5,
|
|
19
22
|
},
|
|
20
23
|
messages: {
|
|
21
24
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -35,12 +38,12 @@ exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
|
|
|
35
38
|
function report(node) {
|
|
36
39
|
context.report({ node, messageId: 'violationDetected' });
|
|
37
40
|
}
|
|
38
|
-
const dangerousProperties = ['rejectUnauthorized', 'strictSSL', 'verify'];
|
|
41
|
+
const dangerousProperties = new Set(['rejectUnauthorized', 'strictSSL', 'verify']);
|
|
39
42
|
return {
|
|
40
43
|
Property(node) {
|
|
41
44
|
// Check for dangerous SSL options set to false
|
|
42
45
|
if (node.key.type === 'Identifier' &&
|
|
43
|
-
dangerousProperties.
|
|
46
|
+
dangerousProperties.has(node.key.name) &&
|
|
44
47
|
node.value.type === 'Literal' &&
|
|
45
48
|
node.value.value === false) {
|
|
46
49
|
report(node);
|
|
@@ -12,7 +12,10 @@ exports.noDynamicServiceWorkerUrl = (0, eslint_devkit_1.createRule)({
|
|
|
12
12
|
meta: {
|
|
13
13
|
type: 'problem',
|
|
14
14
|
docs: {
|
|
15
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-dynamic-service-worker-url.md',
|
|
15
16
|
description: 'Disallow dynamic URLs in service worker registration',
|
|
17
|
+
cwe: 'CWE-829',
|
|
18
|
+
cvss: 8.1,
|
|
16
19
|
},
|
|
17
20
|
hasSuggestions: true,
|
|
18
21
|
messages: {
|
|
@@ -47,7 +50,7 @@ exports.noDynamicServiceWorkerUrl = (0, eslint_devkit_1.createRule)({
|
|
|
47
50
|
defaultOptions: [{ allowInTests: true }],
|
|
48
51
|
create(context, [options = {}]) {
|
|
49
52
|
const { allowInTests = true } = options;
|
|
50
|
-
const filename = context.filename
|
|
53
|
+
const filename = context.filename;
|
|
51
54
|
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
52
55
|
if (allowInTests && isTestFile) {
|
|
53
56
|
return {};
|
|
@@ -21,7 +21,10 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
21
21
|
meta: {
|
|
22
22
|
type: 'problem',
|
|
23
23
|
docs: {
|
|
24
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-eval.md',
|
|
24
25
|
description: 'Disallow eval(), Function(), and other code execution patterns',
|
|
26
|
+
cwe: 'CWE-95',
|
|
27
|
+
cvss: 9.5,
|
|
25
28
|
},
|
|
26
29
|
hasSuggestions: true,
|
|
27
30
|
messages: {
|
|
@@ -112,21 +115,37 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
// Check for window.eval
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
// Check for `window.eval`, `global.eval`, `globalThis.eval`, `self.eval`
|
|
119
|
+
// (member access — non-computed) AND `window['eval']`, `globalThis['Function']`
|
|
120
|
+
// (computed — Literal property). The second form was an audit FN
|
|
121
|
+
// surfaced by `npm run ilb:stress-test` (see benchmarks/AUDIT_PATTERNS.md
|
|
122
|
+
// §3.3 — "indirect access via bracket notation").
|
|
123
|
+
if (callee.type === 'MemberExpression') {
|
|
124
|
+
let propertyName = null;
|
|
125
|
+
if (!callee.computed &&
|
|
126
|
+
callee.property.type === 'Identifier' &&
|
|
127
|
+
DANGEROUS_FUNCTIONS.has(callee.property.name)) {
|
|
128
|
+
propertyName = callee.property.name;
|
|
129
|
+
}
|
|
130
|
+
else if (callee.computed &&
|
|
131
|
+
callee.property.type === 'Literal' &&
|
|
132
|
+
typeof callee.property.value === 'string' &&
|
|
133
|
+
DANGEROUS_FUNCTIONS.has(callee.property.value)) {
|
|
134
|
+
propertyName = callee.property.value;
|
|
135
|
+
}
|
|
136
|
+
if (propertyName) {
|
|
137
|
+
context.report({
|
|
138
|
+
node,
|
|
139
|
+
messageId: 'dangerousEval',
|
|
140
|
+
data: { function: propertyName },
|
|
141
|
+
suggest: [
|
|
142
|
+
{
|
|
143
|
+
messageId: 'useSafeAlternative',
|
|
144
|
+
fix: () => null,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
130
149
|
}
|
|
131
150
|
},
|
|
132
151
|
// Check for new Function()
|
|
@@ -8,14 +8,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.noFilereaderInnerhtml = void 0;
|
|
9
9
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
10
|
// Dangerous DOM properties and methods
|
|
11
|
-
const DANGEROUS_PROPERTIES = ['innerHTML', 'outerHTML'];
|
|
12
|
-
const DANGEROUS_METHODS = ['insertAdjacentHTML', 'write', 'writeln'];
|
|
11
|
+
const DANGEROUS_PROPERTIES = new Set(['innerHTML', 'outerHTML']);
|
|
12
|
+
const DANGEROUS_METHODS = new Set(['insertAdjacentHTML', 'write', 'writeln']);
|
|
13
13
|
exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
14
14
|
name: 'no-filereader-innerhtml',
|
|
15
15
|
meta: {
|
|
16
16
|
type: 'problem',
|
|
17
17
|
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-filereader-innerhtml.md',
|
|
18
19
|
description: 'Disallow using innerHTML or similar methods with FileReader data',
|
|
20
|
+
cwe: 'CWE-79',
|
|
21
|
+
cvss: 8.1,
|
|
19
22
|
},
|
|
20
23
|
hasSuggestions: true,
|
|
21
24
|
messages: {
|
|
@@ -55,7 +58,7 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
55
58
|
defaultOptions: [{ allowInTests: true }],
|
|
56
59
|
create(context, [options = {}]) {
|
|
57
60
|
const { allowInTests = true } = options;
|
|
58
|
-
const filename = context.filename
|
|
61
|
+
const filename = context.filename;
|
|
59
62
|
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
60
63
|
if (allowInTests && isTestFile) {
|
|
61
64
|
return {};
|
|
@@ -147,7 +150,7 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
147
150
|
return;
|
|
148
151
|
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
149
152
|
node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
150
|
-
DANGEROUS_PROPERTIES.
|
|
153
|
+
DANGEROUS_PROPERTIES.has(node.left.property.name)) {
|
|
151
154
|
if (referencesFileReaderResult(node.right, eventParamName)) {
|
|
152
155
|
context.report({
|
|
153
156
|
node,
|
|
@@ -186,7 +189,7 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
186
189
|
return;
|
|
187
190
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
188
191
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
189
|
-
DANGEROUS_METHODS.
|
|
192
|
+
DANGEROUS_METHODS.has(node.callee.property.name)) {
|
|
190
193
|
for (const arg of node.arguments) {
|
|
191
194
|
if (referencesFileReaderResult(arg, eventParamName)) {
|
|
192
195
|
context.report({
|
|
@@ -17,7 +17,10 @@ exports.noHttpUrls = (0, eslint_devkit_1.createRule)({
|
|
|
17
17
|
meta: {
|
|
18
18
|
type: 'problem',
|
|
19
19
|
docs: {
|
|
20
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-http-urls.md',
|
|
20
21
|
description: 'Disallow hardcoded HTTP URLs (require HTTPS)',
|
|
22
|
+
cwe: 'CWE-319',
|
|
23
|
+
cvss: 7.5,
|
|
21
24
|
},
|
|
22
25
|
messages: {
|
|
23
26
|
insecureHttp: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -38,7 +38,11 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
38
38
|
meta: {
|
|
39
39
|
type: 'problem',
|
|
40
40
|
docs: {
|
|
41
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-innerhtml.md',
|
|
41
42
|
description: 'Disallow dangerous innerHTML/outerHTML assignments that can lead to XSS',
|
|
43
|
+
cwe: 'CWE-79',
|
|
44
|
+
cvss: 9.5,
|
|
45
|
+
confidence: 'medium',
|
|
42
46
|
},
|
|
43
47
|
hasSuggestions: true,
|
|
44
48
|
messages: {
|
|
@@ -97,7 +101,41 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
97
101
|
return {};
|
|
98
102
|
}
|
|
99
103
|
const sourceCode = context.sourceCode;
|
|
100
|
-
const dangerousProperties = ['innerHTML', 'outerHTML'];
|
|
104
|
+
const dangerousProperties = new Set(['innerHTML', 'outerHTML']);
|
|
105
|
+
// Sibling DOM sinks that share the same XSS class — surfaced as
|
|
106
|
+
// FN by the hand-curated stress test. See benchmarks/AUDIT_PATTERNS.md
|
|
107
|
+
// §3.1 ("DOM XSS sink list"). Each takes user-controlled HTML and
|
|
108
|
+
// injects it into the live DOM exactly the same way innerHTML does.
|
|
109
|
+
const dangerousSinkMethods = new Set([
|
|
110
|
+
'insertAdjacentHTML',
|
|
111
|
+
'write',
|
|
112
|
+
'writeln',
|
|
113
|
+
]);
|
|
114
|
+
function reportSink(reportNode, sinkName, taintedNode) {
|
|
115
|
+
// Allow literal strings if configured.
|
|
116
|
+
if (allowLiteralStrings && isLiteralString(taintedNode))
|
|
117
|
+
return;
|
|
118
|
+
// Allow if sanitized via a trusted sanitiser call.
|
|
119
|
+
if (isSanitized(taintedNode, sourceCode, trustedSanitizers))
|
|
120
|
+
return;
|
|
121
|
+
// Determine source type for the diagnostic message.
|
|
122
|
+
let source = 'dynamic content';
|
|
123
|
+
if (taintedNode.type === 'Identifier') {
|
|
124
|
+
source = `variable "${taintedNode.name}"`;
|
|
125
|
+
}
|
|
126
|
+
else if (taintedNode.type === 'TemplateLiteral') {
|
|
127
|
+
source = 'template literal with expressions';
|
|
128
|
+
}
|
|
129
|
+
else if (taintedNode.type === 'CallExpression') {
|
|
130
|
+
source = 'function call result';
|
|
131
|
+
}
|
|
132
|
+
context.report({
|
|
133
|
+
node: reportNode,
|
|
134
|
+
messageId: 'dangerousInnerHTML',
|
|
135
|
+
data: { property: sinkName, source },
|
|
136
|
+
suggest: [{ messageId: 'useSanitizer', fix: () => null }],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
101
139
|
return {
|
|
102
140
|
AssignmentExpression(node) {
|
|
103
141
|
// Check for element.innerHTML = ... or element.outerHTML = ...
|
|
@@ -109,43 +147,29 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
109
147
|
if (property.type !== 'Identifier') {
|
|
110
148
|
return;
|
|
111
149
|
}
|
|
112
|
-
if (!dangerousProperties.
|
|
150
|
+
if (!dangerousProperties.has(property.name)) {
|
|
113
151
|
return;
|
|
114
152
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
153
|
+
reportSink(node, property.name, node.right);
|
|
154
|
+
},
|
|
155
|
+
// element.insertAdjacentHTML(position, htmlString) — same XSS class
|
|
156
|
+
// as innerHTML but a different sink shape. Also covers
|
|
157
|
+
// document.write(...) and document.writeln(...) which are the
|
|
158
|
+
// historic parent injection sinks.
|
|
159
|
+
CallExpression(node) {
|
|
160
|
+
if (node.callee.type !== 'MemberExpression')
|
|
118
161
|
return;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (isSanitized(rightSide, sourceCode, trustedSanitizers)) {
|
|
162
|
+
const property = node.callee.property;
|
|
163
|
+
if (property.type !== 'Identifier')
|
|
122
164
|
return;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
else if (rightSide.type === 'CallExpression') {
|
|
133
|
-
source = 'function call result';
|
|
134
|
-
}
|
|
135
|
-
context.report({
|
|
136
|
-
node,
|
|
137
|
-
messageId: 'dangerousInnerHTML',
|
|
138
|
-
data: {
|
|
139
|
-
property: property.name,
|
|
140
|
-
source,
|
|
141
|
-
},
|
|
142
|
-
suggest: [
|
|
143
|
-
{
|
|
144
|
-
messageId: 'useSanitizer',
|
|
145
|
-
fix: () => null,
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
});
|
|
165
|
+
if (!dangerousSinkMethods.has(property.name))
|
|
166
|
+
return;
|
|
167
|
+
// The HTML payload is the LAST argument for insertAdjacentHTML
|
|
168
|
+
// (`(position, html)`) and the only argument for write/writeln.
|
|
169
|
+
const tainted = node.arguments[node.arguments.length - 1];
|
|
170
|
+
if (!tainted)
|
|
171
|
+
return;
|
|
172
|
+
reportSink(node, property.name, tainted);
|
|
149
173
|
},
|
|
150
174
|
};
|
|
151
175
|
},
|
|
@@ -124,7 +124,10 @@ exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
|
124
124
|
meta: {
|
|
125
125
|
type: 'problem',
|
|
126
126
|
docs: {
|
|
127
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-insecure-redirects.md',
|
|
127
128
|
description: 'Detects open redirect vulnerabilities',
|
|
129
|
+
cwe: 'CWE-601',
|
|
130
|
+
cvss: 7.5,
|
|
128
131
|
},
|
|
129
132
|
hasSuggestions: true,
|
|
130
133
|
messages: {
|
|
@@ -188,12 +191,12 @@ exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
|
188
191
|
],
|
|
189
192
|
create(context, [options = {}]) {
|
|
190
193
|
const { ignoreInTests = true } = options || {};
|
|
191
|
-
const filename = context.
|
|
194
|
+
const filename = context.filename;
|
|
192
195
|
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
193
196
|
if (isTestFile) {
|
|
194
197
|
return {};
|
|
195
198
|
}
|
|
196
|
-
const sourceCode = context.sourceCode
|
|
199
|
+
const sourceCode = context.sourceCode;
|
|
197
200
|
/**
|
|
198
201
|
* Check redirect calls and assignments
|
|
199
202
|
*/
|
|
@@ -15,7 +15,10 @@ exports.noInsecureWebsocket = (0, eslint_devkit_1.createRule)({
|
|
|
15
15
|
meta: {
|
|
16
16
|
type: 'problem',
|
|
17
17
|
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-insecure-websocket.md',
|
|
18
19
|
description: 'Require secure WebSocket connections (wss://)',
|
|
20
|
+
cwe: 'CWE-319',
|
|
21
|
+
cvss: 7.5,
|
|
19
22
|
},
|
|
20
23
|
messages: {
|
|
21
24
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -56,7 +56,10 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
|
|
|
56
56
|
meta: {
|
|
57
57
|
type: 'problem',
|
|
58
58
|
docs: {
|
|
59
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-jwt-in-storage.md',
|
|
59
60
|
description: 'Disallow storing JWT tokens in localStorage or sessionStorage',
|
|
61
|
+
cwe: 'CWE-922',
|
|
62
|
+
cvss: 8.1,
|
|
60
63
|
},
|
|
61
64
|
hasSuggestions: true,
|
|
62
65
|
messages: {
|
|
@@ -96,19 +99,19 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
|
|
|
96
99
|
defaultOptions: [{ allowInTests: true }],
|
|
97
100
|
create(context, [options = {}]) {
|
|
98
101
|
const { allowInTests = true } = options;
|
|
99
|
-
const filename = context.filename
|
|
102
|
+
const filename = context.filename;
|
|
100
103
|
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
101
104
|
if (allowInTests && isTestFile) {
|
|
102
105
|
return {};
|
|
103
106
|
}
|
|
104
|
-
const storageObjects = ['localStorage', 'sessionStorage'];
|
|
107
|
+
const storageObjects = new Set(['localStorage', 'sessionStorage']);
|
|
105
108
|
return {
|
|
106
109
|
CallExpression(node) {
|
|
107
110
|
const callee = node.callee;
|
|
108
111
|
// Check for localStorage.setItem() or sessionStorage.setItem()
|
|
109
112
|
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
110
113
|
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
111
|
-
storageObjects.
|
|
114
|
+
storageObjects.has(callee.object.name) &&
|
|
112
115
|
callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
113
116
|
callee.property.name === 'setItem') {
|
|
114
117
|
const keyArg = node.arguments[0];
|
|
@@ -158,7 +161,7 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
|
|
|
158
161
|
}
|
|
159
162
|
const obj = node.left.object;
|
|
160
163
|
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
161
|
-
!storageObjects.
|
|
164
|
+
!storageObjects.has(obj.name)) {
|
|
162
165
|
/* c8 ignore next - Guard clause for non-storage objects */
|
|
163
166
|
return;
|
|
164
167
|
}
|
|
@@ -29,7 +29,10 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
|
|
|
29
29
|
deprecated: true,
|
|
30
30
|
replacedBy: ['@see eslint-plugin-express-security/no-permissive-cors'],
|
|
31
31
|
docs: {
|
|
32
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-cors-check.md',
|
|
32
33
|
description: 'Detects missing CORS validation (wildcard CORS, missing origin check)',
|
|
34
|
+
cwe: 'CWE-346',
|
|
35
|
+
cvss: 7.5,
|
|
33
36
|
},
|
|
34
37
|
hasSuggestions: true,
|
|
35
38
|
messages: {
|
|
@@ -95,9 +98,9 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
|
|
|
95
98
|
create(context, [options = {}]) {
|
|
96
99
|
const { allowInTests = false, trustedLibraries: corsTrustedLibraries = [], ignorePatterns = [], } = options;
|
|
97
100
|
const trustedLibraries = corsTrustedLibraries;
|
|
98
|
-
const filename = context.
|
|
101
|
+
const filename = context.filename;
|
|
99
102
|
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
100
|
-
const sourceCode = context.sourceCode
|
|
103
|
+
const sourceCode = context.sourceCode;
|
|
101
104
|
function checkLiteral(node) {
|
|
102
105
|
if (isTestFile) {
|
|
103
106
|
return;
|
|
@@ -46,7 +46,10 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
|
|
|
46
46
|
deprecated: true,
|
|
47
47
|
replacedBy: ['@see eslint-plugin-express-security/require-csrf-protection'],
|
|
48
48
|
docs: {
|
|
49
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-csrf-protection.md',
|
|
49
50
|
description: 'Detects missing CSRF token validation in POST/PUT/DELETE requests',
|
|
51
|
+
cwe: 'CWE-352',
|
|
52
|
+
cvss: 7.5,
|
|
50
53
|
},
|
|
51
54
|
hasSuggestions: true,
|
|
52
55
|
messages: {
|