eslint-plugin-browser-security 1.2.9 → 1.2.11
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 +5 -22
- package/src/index.d.ts +17 -64
- package/src/index.js +1 -76
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/detect-mixed-content/index.js +0 -10
- package/src/rules/no-allow-arbitrary-loads/index.js +0 -10
- package/src/rules/no-clickjacking/index.js +0 -37
- package/src/rules/no-client-side-auth-logic/index.js +0 -11
- package/src/rules/no-cookie-auth-tokens/index.js +0 -13
- package/src/rules/no-credentials-in-query-params/index.js +0 -10
- package/src/rules/no-disabled-certificate-validation/index.js +0 -10
- package/src/rules/no-dynamic-service-worker-url/index.js +0 -9
- package/src/rules/no-eval/index.js +1 -14
- package/src/rules/no-filereader-innerhtml/index.js +0 -23
- package/src/rules/no-http-urls/index.js +0 -13
- package/src/rules/no-innerhtml/index.js +0 -25
- package/src/rules/no-insecure-redirects/index.js +3 -39
- package/src/rules/no-insecure-websocket/index.js +0 -12
- package/src/rules/no-jwt-in-storage/index.js +19 -42
- package/src/rules/no-missing-cors-check/index.js +4 -57
- package/src/rules/no-missing-csrf-protection/index.js +0 -23
- package/src/rules/no-missing-security-headers/index.js +0 -29
- package/src/rules/no-password-in-url/index.js +0 -11
- package/src/rules/no-permissive-cors/index.js +0 -13
- package/src/rules/no-postmessage-innerhtml/index.js +0 -18
- package/src/rules/no-postmessage-wildcard-origin/index.js +0 -10
- package/src/rules/no-sensitive-cookie-js/index.js +0 -18
- package/src/rules/no-sensitive-data-in-analytics/index.js +0 -11
- package/src/rules/no-sensitive-data-in-cache/index.js +0 -10
- package/src/rules/no-sensitive-indexeddb/index.js +0 -8
- package/src/rules/no-sensitive-localstorage/index.js +0 -11
- package/src/rules/no-sensitive-sessionstorage/index.js +0 -9
- package/src/rules/no-tracking-without-consent/index.js +0 -10
- package/src/rules/no-unencrypted-transmission/index.js +0 -32
- package/src/rules/no-unescaped-url-parameter/index.js +5 -47
- package/src/rules/no-unsafe-eval-csp/index.js +0 -10
- package/src/rules/no-unsafe-inline-csp/index.js +0 -10
- package/src/rules/no-unvalidated-deeplinks/index.js +0 -11
- package/src/rules/no-websocket-eval/index.js +0 -26
- package/src/rules/no-websocket-innerhtml/index.js +0 -20
- package/src/rules/no-worker-message-innerhtml/index.js +0 -23
- package/src/rules/require-blob-url-revocation/index.js +0 -10
- package/src/rules/require-cookie-secure-attrs/index.js +0 -7
- package/src/rules/require-csp-headers/index.js +0 -13
- package/src/rules/require-https-only/index.js +0 -13
- package/src/rules/require-mime-type-validation/index.js +0 -13
- package/src/rules/require-postmessage-origin-check/index.js +0 -17
- package/src/rules/require-url-validation/index.js +0 -12
- package/src/rules/require-websocket-wss/index.js +0 -17
- package/AGENTS.md +0 -97
- package/CHANGELOG.md +0 -188
- package/src/rules/detect-mixed-content/index.d.ts +0 -12
- package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -12
- package/src/rules/no-clickjacking/index.d.ts +0 -36
- package/src/rules/no-client-side-auth-logic/index.d.ts +0 -12
- package/src/rules/no-cookie-auth-tokens/index.d.ts +0 -23
- package/src/rules/no-credentials-in-query-params/index.d.ts +0 -12
- package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -12
- package/src/rules/no-dynamic-service-worker-url/index.d.ts +0 -23
- package/src/rules/no-eval/index.d.ts +0 -26
- package/src/rules/no-filereader-innerhtml/index.d.ts +0 -24
- package/src/rules/no-http-urls/index.d.ts +0 -17
- package/src/rules/no-innerhtml/index.d.ts +0 -28
- package/src/rules/no-insecure-redirects/index.d.ts +0 -26
- package/src/rules/no-insecure-websocket/index.d.ts +0 -12
- package/src/rules/no-jwt-in-storage/index.d.ts +0 -24
- package/src/rules/no-missing-cors-check/index.d.ts +0 -28
- package/src/rules/no-missing-csrf-protection/index.d.ts +0 -30
- package/src/rules/no-missing-security-headers/index.d.ts +0 -26
- package/src/rules/no-password-in-url/index.d.ts +0 -12
- package/src/rules/no-permissive-cors/index.d.ts +0 -12
- package/src/rules/no-postmessage-innerhtml/index.d.ts +0 -24
- package/src/rules/no-postmessage-wildcard-origin/index.d.ts +0 -24
- package/src/rules/no-sensitive-cookie-js/index.d.ts +0 -26
- package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -12
- package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -12
- package/src/rules/no-sensitive-indexeddb/index.d.ts +0 -23
- package/src/rules/no-sensitive-localstorage/index.d.ts +0 -28
- package/src/rules/no-sensitive-sessionstorage/index.d.ts +0 -25
- package/src/rules/no-tracking-without-consent/index.d.ts +0 -12
- package/src/rules/no-unencrypted-transmission/index.d.ts +0 -30
- package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -28
- package/src/rules/no-unsafe-eval-csp/index.d.ts +0 -24
- package/src/rules/no-unsafe-inline-csp/index.d.ts +0 -24
- package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -12
- package/src/rules/no-websocket-eval/index.d.ts +0 -24
- package/src/rules/no-websocket-innerhtml/index.d.ts +0 -24
- package/src/rules/no-worker-message-innerhtml/index.d.ts +0 -24
- package/src/rules/require-blob-url-revocation/index.d.ts +0 -24
- package/src/rules/require-cookie-secure-attrs/index.d.ts +0 -23
- package/src/rules/require-csp-headers/index.d.ts +0 -12
- package/src/rules/require-https-only/index.d.ts +0 -12
- package/src/rules/require-mime-type-validation/index.d.ts +0 -12
- package/src/rules/require-postmessage-origin-check/index.d.ts +0 -26
- package/src/rules/require-url-validation/index.d.ts +0 -12
- package/src/rules/require-websocket-wss/index.d.ts +0 -26
|
@@ -1,13 +1,7 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noCookieAuthTokens = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Auth token patterns
|
|
11
5
|
const AUTH_PATTERNS = [
|
|
12
6
|
/token/i,
|
|
13
7
|
/jwt/i,
|
|
@@ -21,10 +15,6 @@ const AUTH_PATTERNS = [
|
|
|
21
15
|
function isAuthToken(cookieString) {
|
|
22
16
|
return AUTH_PATTERNS.some((p) => p.test(cookieString));
|
|
23
17
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Extract string parts from a binary expression (concatenation)
|
|
26
|
-
* e.g., 'accessToken=' + token => 'accessToken='
|
|
27
|
-
*/
|
|
28
18
|
function extractStringParts(node) {
|
|
29
19
|
const parts = [];
|
|
30
20
|
function traverse(n) {
|
|
@@ -89,7 +79,6 @@ exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
|
89
79
|
}
|
|
90
80
|
return {
|
|
91
81
|
AssignmentExpression(node) {
|
|
92
|
-
// Check for document.cookie = ...
|
|
93
82
|
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
94
83
|
node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
95
84
|
node.left.object.name === 'document' &&
|
|
@@ -101,11 +90,9 @@ exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
|
101
90
|
cookieValue = node.right.value;
|
|
102
91
|
}
|
|
103
92
|
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
104
|
-
// Check template literal quasis
|
|
105
93
|
cookieValue = node.right.quasis.map((q) => q.value.raw).join('');
|
|
106
94
|
}
|
|
107
95
|
else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
108
|
-
// Handle string concatenation: 'accessToken=' + token
|
|
109
96
|
cookieValue = extractStringParts(node.right);
|
|
110
97
|
}
|
|
111
98
|
if (cookieValue && isAuthToken(cookieValue)) {
|
|
@@ -1,16 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noCredentialsInQueryParams = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Disallow credentials in URL query parameters
|
|
11
|
-
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
-
* @see https://cwe.mitre.org/data/definitions/598.html
|
|
13
|
-
*/
|
|
14
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
5
|
exports.noCredentialsInQueryParams = (0, eslint_devkit_1.createRule)({
|
|
16
6
|
name: 'no-credentials-in-query-params',
|
|
@@ -1,14 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noDisabledCertificateValidation = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Prevent disabled SSL/TLS certificate validation
|
|
11
|
-
*/
|
|
12
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
5
|
exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
|
|
14
6
|
name: 'no-disabled-certificate-validation',
|
|
@@ -41,7 +33,6 @@ exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
|
|
|
41
33
|
const dangerousProperties = new Set(['rejectUnauthorized', 'strictSSL', 'verify']);
|
|
42
34
|
return {
|
|
43
35
|
Property(node) {
|
|
44
|
-
// Check for dangerous SSL options set to false
|
|
45
36
|
if (node.key.type === 'Identifier' &&
|
|
46
37
|
dangerousProperties.has(node.key.name) &&
|
|
47
38
|
node.value.type === 'Literal' &&
|
|
@@ -50,7 +41,6 @@ exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
|
|
|
50
41
|
}
|
|
51
42
|
},
|
|
52
43
|
AssignmentExpression(node) {
|
|
53
|
-
// Check for NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
|
54
44
|
if (node.left.type === 'MemberExpression' &&
|
|
55
45
|
node.left.object.type === 'MemberExpression' &&
|
|
56
46
|
node.left.object.object.type === 'Identifier' &&
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noDynamicServiceWorkerUrl = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -57,23 +52,19 @@ exports.noDynamicServiceWorkerUrl = (0, eslint_devkit_1.createRule)({
|
|
|
57
52
|
}
|
|
58
53
|
return {
|
|
59
54
|
CallExpression(node) {
|
|
60
|
-
// Check for navigator.serviceWorker.register(url)
|
|
61
55
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
62
56
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
63
57
|
node.callee.property.name === 'register') {
|
|
64
58
|
const obj = node.callee.object;
|
|
65
|
-
// Check if it's navigator.serviceWorker.register
|
|
66
59
|
if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
67
60
|
obj.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
68
61
|
obj.property.name === 'serviceWorker') {
|
|
69
62
|
const urlArg = node.arguments[0];
|
|
70
63
|
if (!urlArg)
|
|
71
64
|
return;
|
|
72
|
-
// Allow string literals (static URLs)
|
|
73
65
|
if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
74
66
|
return;
|
|
75
67
|
}
|
|
76
|
-
// Flag any non-literal URL
|
|
77
68
|
context.report({
|
|
78
69
|
node,
|
|
79
70
|
messageId: 'dynamicSwUrl',
|
|
@@ -1,15 +1,10 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noEval = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const DANGEROUS_FUNCTIONS = new Set([
|
|
11
6
|
'eval',
|
|
12
|
-
'execScript',
|
|
7
|
+
'execScript',
|
|
13
8
|
]);
|
|
14
9
|
const DANGEROUS_METHODS_WITH_STRING_ARG = new Set([
|
|
15
10
|
'setTimeout',
|
|
@@ -79,7 +74,6 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
79
74
|
return {
|
|
80
75
|
CallExpression(node) {
|
|
81
76
|
const callee = node.callee;
|
|
82
|
-
// Check for eval(), execScript()
|
|
83
77
|
if (callee.type === 'Identifier') {
|
|
84
78
|
if (DANGEROUS_FUNCTIONS.has(callee.name)) {
|
|
85
79
|
context.report({
|
|
@@ -95,7 +89,6 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
95
89
|
});
|
|
96
90
|
return;
|
|
97
91
|
}
|
|
98
|
-
// Check for setTimeout/setInterval with string argument
|
|
99
92
|
if (DANGEROUS_METHODS_WITH_STRING_ARG.has(callee.name)) {
|
|
100
93
|
const firstArg = node.arguments[0];
|
|
101
94
|
if (firstArg &&
|
|
@@ -115,11 +108,6 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
115
108
|
}
|
|
116
109
|
}
|
|
117
110
|
}
|
|
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
111
|
if (callee.type === 'MemberExpression') {
|
|
124
112
|
let propertyName = null;
|
|
125
113
|
if (!callee.computed &&
|
|
@@ -148,7 +136,6 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
|
|
|
148
136
|
}
|
|
149
137
|
}
|
|
150
138
|
},
|
|
151
|
-
// Check for new Function()
|
|
152
139
|
NewExpression(node) {
|
|
153
140
|
if (allowFunctionConstructor) {
|
|
154
141
|
return;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noFilereaderInnerhtml = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Dangerous DOM properties and methods
|
|
11
5
|
const DANGEROUS_PROPERTIES = new Set(['innerHTML', 'outerHTML']);
|
|
12
6
|
const DANGEROUS_METHODS = new Set(['insertAdjacentHTML', 'write', 'writeln']);
|
|
13
7
|
exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
@@ -63,18 +57,13 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
63
57
|
if (allowInTests && isTestFile) {
|
|
64
58
|
return {};
|
|
65
59
|
}
|
|
66
|
-
// Track FileReader onload handlers
|
|
67
60
|
let inFileReaderHandler = false;
|
|
68
61
|
let eventParamName = null;
|
|
69
|
-
/**
|
|
70
|
-
* Check if we're in a FileReader onload assignment
|
|
71
|
-
*/
|
|
72
62
|
function isFileReaderOnloadAssignment(node) {
|
|
73
63
|
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
74
64
|
node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
75
65
|
(node.left.property.name === 'onload' ||
|
|
76
66
|
node.left.property.name === 'onloadend')) {
|
|
77
|
-
// Check if object looks like a FileReader (reader, fileReader, fr, etc.)
|
|
78
67
|
const objName = node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
|
|
79
68
|
? node.left.object.name.toLowerCase()
|
|
80
69
|
: '';
|
|
@@ -93,9 +82,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
93
82
|
}
|
|
94
83
|
return { isHandler: false, eventParam: null };
|
|
95
84
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if we're in a FileReader addEventListener('load')
|
|
98
|
-
*/
|
|
99
85
|
function isFileReaderAddEventListener(node) {
|
|
100
86
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
101
87
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
@@ -116,11 +102,7 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
116
102
|
}
|
|
117
103
|
return { isHandler: false, eventParam: null };
|
|
118
104
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Check if expression references e.target.result or event.target.result
|
|
121
|
-
*/
|
|
122
105
|
function referencesFileReaderResult(node, eventName) {
|
|
123
|
-
// Check for e.target.result pattern
|
|
124
106
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
125
107
|
if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
126
108
|
node.property.name === 'result' &&
|
|
@@ -131,20 +113,17 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
131
113
|
node.object.object.name === eventName) {
|
|
132
114
|
return true;
|
|
133
115
|
}
|
|
134
|
-
// Check nested
|
|
135
116
|
return referencesFileReaderResult(node.object, eventName);
|
|
136
117
|
}
|
|
137
118
|
return false;
|
|
138
119
|
}
|
|
139
120
|
return {
|
|
140
121
|
AssignmentExpression(node) {
|
|
141
|
-
// Check if entering FileReader handler
|
|
142
122
|
const { isHandler, eventParam } = isFileReaderOnloadAssignment(node);
|
|
143
123
|
if (isHandler) {
|
|
144
124
|
inFileReaderHandler = true;
|
|
145
125
|
eventParamName = eventParam;
|
|
146
126
|
}
|
|
147
|
-
// Check for innerHTML/outerHTML assignment within handler
|
|
148
127
|
if (!inFileReaderHandler || !eventParamName)
|
|
149
128
|
return;
|
|
150
129
|
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
@@ -175,13 +154,11 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
175
154
|
}
|
|
176
155
|
},
|
|
177
156
|
CallExpression(node) {
|
|
178
|
-
// Check if entering addEventListener handler
|
|
179
157
|
const { isHandler, eventParam } = isFileReaderAddEventListener(node);
|
|
180
158
|
if (isHandler) {
|
|
181
159
|
inFileReaderHandler = true;
|
|
182
160
|
eventParamName = eventParam;
|
|
183
161
|
}
|
|
184
|
-
// Check for dangerous method calls within handler
|
|
185
162
|
if (!inFileReaderHandler || !eventParamName)
|
|
186
163
|
return;
|
|
187
164
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
@@ -1,16 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noHttpUrls = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Disallow hardcoded HTTP URLs
|
|
11
|
-
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
-
* @see https://cwe.mitre.org/data/definitions/319.html
|
|
13
|
-
*/
|
|
14
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
5
|
exports.noHttpUrls = (0, eslint_devkit_1.createRule)({
|
|
16
6
|
name: 'no-http-urls',
|
|
@@ -79,18 +69,15 @@ exports.noHttpUrls = (0, eslint_devkit_1.createRule)({
|
|
|
79
69
|
function isAllowedException(url) {
|
|
80
70
|
try {
|
|
81
71
|
const parsedUrl = new URL(url);
|
|
82
|
-
// Check if host is in allowed list
|
|
83
72
|
if (allowedHosts.includes(parsedUrl.hostname)) {
|
|
84
73
|
return true;
|
|
85
74
|
}
|
|
86
|
-
// Check if port is in allowed list
|
|
87
75
|
if (parsedUrl.port && allowedPorts.includes(parseInt(parsedUrl.port, 10))) {
|
|
88
76
|
return true;
|
|
89
77
|
}
|
|
90
78
|
return false;
|
|
91
79
|
}
|
|
92
80
|
catch {
|
|
93
|
-
// If URL parsing fails, treat as pattern match
|
|
94
81
|
return allowedHosts.some(host => url.includes(host));
|
|
95
82
|
}
|
|
96
83
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noInnerhtml = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -14,16 +9,10 @@ const DEFAULT_SANITIZERS = [
|
|
|
14
9
|
'xss',
|
|
15
10
|
'purify',
|
|
16
11
|
];
|
|
17
|
-
/**
|
|
18
|
-
* Check if the right side is sanitized
|
|
19
|
-
*/
|
|
20
12
|
function isSanitized(node, sourceCode, sanitizers) {
|
|
21
13
|
const text = sourceCode.getText(node);
|
|
22
14
|
return sanitizers.some((s) => text.includes(s));
|
|
23
15
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Check if the value is a literal string
|
|
26
|
-
*/
|
|
27
16
|
function isLiteralString(node) {
|
|
28
17
|
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
29
18
|
return true;
|
|
@@ -102,23 +91,16 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
102
91
|
}
|
|
103
92
|
const sourceCode = context.sourceCode;
|
|
104
93
|
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
94
|
const dangerousSinkMethods = new Set([
|
|
110
95
|
'insertAdjacentHTML',
|
|
111
96
|
'write',
|
|
112
97
|
'writeln',
|
|
113
98
|
]);
|
|
114
99
|
function reportSink(reportNode, sinkName, taintedNode) {
|
|
115
|
-
// Allow literal strings if configured.
|
|
116
100
|
if (allowLiteralStrings && isLiteralString(taintedNode))
|
|
117
101
|
return;
|
|
118
|
-
// Allow if sanitized via a trusted sanitiser call.
|
|
119
102
|
if (isSanitized(taintedNode, sourceCode, trustedSanitizers))
|
|
120
103
|
return;
|
|
121
|
-
// Determine source type for the diagnostic message.
|
|
122
104
|
let source = 'dynamic content';
|
|
123
105
|
if (taintedNode.type === 'Identifier') {
|
|
124
106
|
source = `variable "${taintedNode.name}"`;
|
|
@@ -138,7 +120,6 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
138
120
|
}
|
|
139
121
|
return {
|
|
140
122
|
AssignmentExpression(node) {
|
|
141
|
-
// Check for element.innerHTML = ... or element.outerHTML = ...
|
|
142
123
|
if (node.left.type !== 'MemberExpression') {
|
|
143
124
|
return;
|
|
144
125
|
}
|
|
@@ -151,10 +132,6 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
151
132
|
}
|
|
152
133
|
reportSink(node, property.name, node.right);
|
|
153
134
|
},
|
|
154
|
-
// element.insertAdjacentHTML(position, htmlString) — same XSS class
|
|
155
|
-
// as innerHTML but a different sink shape. Also covers
|
|
156
|
-
// document.write(...) and document.writeln(...) which are the
|
|
157
|
-
// historic parent injection sinks.
|
|
158
135
|
CallExpression(node) {
|
|
159
136
|
if (node.callee.type !== 'MemberExpression')
|
|
160
137
|
return;
|
|
@@ -163,8 +140,6 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
163
140
|
return;
|
|
164
141
|
if (!dangerousSinkMethods.has(property.name))
|
|
165
142
|
return;
|
|
166
|
-
// The HTML payload is the LAST argument for insertAdjacentHTML
|
|
167
|
-
// (`(position, html)`) and the only argument for write/writeln.
|
|
168
143
|
const tainted = node.arguments[node.arguments.length - 1];
|
|
169
144
|
if (!tainted)
|
|
170
145
|
return;
|
|
@@ -1,17 +1,8 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noInsecureRedirects = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Resolve an identifier to the text of its initialization expression.
|
|
13
|
-
* Scans backward through sibling statements in the same block scope.
|
|
14
|
-
*/
|
|
15
6
|
function resolveVariableInit(ident, sourceCode) {
|
|
16
7
|
const name = ident.name;
|
|
17
8
|
let current = ident.parent;
|
|
@@ -39,17 +30,10 @@ function resolveVariableInit(ident, sourceCode) {
|
|
|
39
30
|
}
|
|
40
31
|
return null;
|
|
41
32
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if redirect URL is validated
|
|
44
|
-
*/
|
|
45
33
|
function isRedirectValidated(node, sourceCode) {
|
|
46
34
|
const callText = sourceCode.getText(node);
|
|
47
|
-
// Check if URL is from user input (req.query, req.body, req.params)
|
|
48
35
|
const userInputPattern = /\b(req\.(query|body|params)|window\.location|document\.location)\b/;
|
|
49
|
-
// Direct check: res.redirect(req.query.returnTo)
|
|
50
36
|
let hasUserInput = userInputPattern.test(callText);
|
|
51
|
-
// Indirect check: resolve variable references to their init expressions
|
|
52
|
-
// e.g., const returnUrl = req.query.returnTo; res.redirect(returnUrl);
|
|
53
37
|
if (!hasUserInput && node.arguments.length > 0) {
|
|
54
38
|
const arg = node.arguments[0];
|
|
55
39
|
if (arg.type === 'Identifier') {
|
|
@@ -60,61 +44,51 @@ function isRedirectValidated(node, sourceCode) {
|
|
|
60
44
|
}
|
|
61
45
|
}
|
|
62
46
|
if (!hasUserInput) {
|
|
63
|
-
// Not from user input, assume safe
|
|
64
47
|
return true;
|
|
65
48
|
}
|
|
66
|
-
// Look for validation patterns in the surrounding code
|
|
67
|
-
// This is a simplified static analysis - in practice, would need data flow analysis
|
|
68
49
|
const program = sourceCode.ast;
|
|
69
50
|
const nodeStart = node.loc?.start;
|
|
70
51
|
const nodeEnd = node.loc?.end;
|
|
71
52
|
if (!nodeStart || !nodeEnd || !program) {
|
|
72
53
|
return false;
|
|
73
54
|
}
|
|
74
|
-
// Check for validation function calls before this redirect
|
|
75
55
|
const validationPatterns = [
|
|
76
56
|
/\b(validateUrl|validateRedirect|isValidUrl|isSafeUrl)\s*\(/,
|
|
77
57
|
/\b(whitelist|allowedDomains|permittedUrls|ALLOWED_\w+)\s*\./,
|
|
78
58
|
/\b(url\.hostname|url\.host)\s*===/,
|
|
79
|
-
/\b\w+\.(includes|has)\s*\(/,
|
|
59
|
+
/\b\w+\.(includes|has)\s*\(/,
|
|
80
60
|
/\bstartsWith\s*\(\s*['"]/,
|
|
81
61
|
/\bendsWith\s*\(\s*['"]/,
|
|
82
62
|
/\bindexOf\s*\(\s*['"]/,
|
|
83
63
|
/\bmatch\s*\(\s*\//,
|
|
84
64
|
];
|
|
85
|
-
// Look for validation in the same function scope
|
|
86
65
|
let current = node;
|
|
87
66
|
let depth = 0;
|
|
88
67
|
const maxDepth = 20;
|
|
89
68
|
while (current && depth < maxDepth) {
|
|
90
|
-
// Check siblings before this node
|
|
91
69
|
const parent = current.parent;
|
|
92
70
|
if (!parent)
|
|
93
71
|
break;
|
|
94
72
|
if (parent.type === 'BlockStatement' || parent.type === 'Program') {
|
|
95
73
|
const body = parent.body;
|
|
96
74
|
const currentIndex = body.indexOf(current);
|
|
97
|
-
// Check previous statements in the same block
|
|
98
75
|
for (let i = currentIndex - 1; i >= 0 && i >= currentIndex - 5; i--) {
|
|
99
76
|
const stmt = body[i];
|
|
100
77
|
const stmtText = sourceCode.getText(stmt);
|
|
101
78
|
if (validationPatterns.some(pattern => pattern.test(stmtText))) {
|
|
102
|
-
return true;
|
|
79
|
+
return true;
|
|
103
80
|
}
|
|
104
81
|
}
|
|
105
82
|
}
|
|
106
|
-
// Check if inside an if-block with validation in the condition
|
|
107
|
-
// e.g., if (isValidUrl(redirect)) { res.redirect(redirect); }
|
|
108
83
|
if (parent.type === 'IfStatement' && parent.test) {
|
|
109
84
|
const testText = sourceCode.getText(parent.test);
|
|
110
85
|
if (validationPatterns.some(pattern => pattern.test(testText))) {
|
|
111
|
-
return true;
|
|
86
|
+
return true;
|
|
112
87
|
}
|
|
113
88
|
}
|
|
114
89
|
current = parent;
|
|
115
90
|
depth++;
|
|
116
91
|
}
|
|
117
|
-
// No validation found
|
|
118
92
|
return false;
|
|
119
93
|
}
|
|
120
94
|
exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
@@ -195,16 +169,11 @@ exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
|
195
169
|
return {};
|
|
196
170
|
}
|
|
197
171
|
const sourceCode = context.sourceCode;
|
|
198
|
-
/**
|
|
199
|
-
* Check redirect calls and assignments
|
|
200
|
-
*/
|
|
201
172
|
function checkCallExpression(node) {
|
|
202
|
-
// Check for res.redirect, window.location, etc.
|
|
203
173
|
if (node.callee.type === 'MemberExpression' &&
|
|
204
174
|
node.callee.property.type === 'Identifier') {
|
|
205
175
|
const methodName = node.callee.property.name;
|
|
206
176
|
if (['redirect', 'replace', 'assign'].includes(methodName)) {
|
|
207
|
-
// Check if redirect URL is validated
|
|
208
177
|
if (!isRedirectValidated(node, sourceCode)) {
|
|
209
178
|
context.report({
|
|
210
179
|
node,
|
|
@@ -228,11 +197,7 @@ exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
|
228
197
|
}
|
|
229
198
|
}
|
|
230
199
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Check assignment expressions like window.location.href = ...
|
|
233
|
-
*/
|
|
234
200
|
function checkAssignmentExpression(node) {
|
|
235
|
-
// Check for window.location.href assignments
|
|
236
201
|
if (node.left.type === 'MemberExpression' &&
|
|
237
202
|
node.left.object.type === 'MemberExpression' &&
|
|
238
203
|
node.left.object.object.type === 'Identifier' &&
|
|
@@ -241,7 +206,6 @@ exports.noInsecureRedirects = (0, eslint_devkit_2.createRule)({
|
|
|
241
206
|
node.left.object.property.name === 'location' &&
|
|
242
207
|
node.left.property.type === 'Identifier' &&
|
|
243
208
|
['href', 'replace', 'assign'].includes(node.left.property.name)) {
|
|
244
|
-
// Check if assignment value comes from user input
|
|
245
209
|
const rightText = sourceCode.getText(node.right);
|
|
246
210
|
const userInputPattern = /\b(req\.(query|body|params)|window\.location|document\.location)\b/;
|
|
247
211
|
if (userInputPattern.test(rightText)) {
|
|
@@ -1,14 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.noInsecureWebsocket = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Require secure WebSocket connections (wss://)
|
|
11
|
-
*/
|
|
12
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
5
|
exports.noInsecureWebsocket = (0, eslint_devkit_1.createRule)({
|
|
14
6
|
name: 'no-insecure-websocket',
|
|
@@ -40,16 +32,13 @@ exports.noInsecureWebsocket = (0, eslint_devkit_1.createRule)({
|
|
|
40
32
|
}
|
|
41
33
|
return {
|
|
42
34
|
NewExpression(node) {
|
|
43
|
-
// Check for new WebSocket('ws://...')
|
|
44
35
|
if (node.callee.type === 'Identifier' && node.callee.name === 'WebSocket') {
|
|
45
36
|
const urlArg = node.arguments[0];
|
|
46
|
-
// Check literal string
|
|
47
37
|
if (urlArg && urlArg.type === 'Literal' &&
|
|
48
38
|
typeof urlArg.value === 'string' &&
|
|
49
39
|
urlArg.value.startsWith('ws://')) {
|
|
50
40
|
report(node);
|
|
51
41
|
}
|
|
52
|
-
// Check template literal
|
|
53
42
|
if (urlArg && urlArg.type === 'TemplateLiteral') {
|
|
54
43
|
const text = context.sourceCode.getText(urlArg);
|
|
55
44
|
if (text.includes('ws://')) {
|
|
@@ -59,7 +48,6 @@ exports.noInsecureWebsocket = (0, eslint_devkit_1.createRule)({
|
|
|
59
48
|
}
|
|
60
49
|
},
|
|
61
50
|
Literal(node) {
|
|
62
|
-
// Check for ws:// URLs in string literals
|
|
63
51
|
if (typeof node.value === 'string' && node.value.startsWith('ws://')) {
|
|
64
52
|
report(node);
|
|
65
53
|
}
|