eslint-plugin-browser-security 1.2.9 → 1.2.10
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,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.noPostmessageWildcardOrigin = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -62,7 +57,6 @@ exports.noPostmessageWildcardOrigin = (0, eslint_devkit_1.createRule)({
|
|
|
62
57
|
}
|
|
63
58
|
return {
|
|
64
59
|
CallExpression(node) {
|
|
65
|
-
// Check for .postMessage() calls
|
|
66
60
|
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
67
61
|
return;
|
|
68
62
|
}
|
|
@@ -71,14 +65,11 @@ exports.noPostmessageWildcardOrigin = (0, eslint_devkit_1.createRule)({
|
|
|
71
65
|
property.name !== 'postMessage') {
|
|
72
66
|
return;
|
|
73
67
|
}
|
|
74
|
-
// postMessage takes (message, targetOrigin, [transfer])
|
|
75
|
-
// or (message, options) where options.targetOrigin can be specified
|
|
76
68
|
const args = node.arguments;
|
|
77
69
|
if (args.length < 2) {
|
|
78
70
|
return;
|
|
79
71
|
}
|
|
80
72
|
const targetOriginArg = args[1];
|
|
81
|
-
// Check for literal "*" as second argument
|
|
82
73
|
if (targetOriginArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
83
74
|
targetOriginArg.value === '*') {
|
|
84
75
|
context.report({
|
|
@@ -93,7 +84,6 @@ exports.noPostmessageWildcardOrigin = (0, eslint_devkit_1.createRule)({
|
|
|
93
84
|
});
|
|
94
85
|
return;
|
|
95
86
|
}
|
|
96
|
-
// Check for options object with targetOrigin: "*"
|
|
97
87
|
if (targetOriginArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
98
88
|
for (const prop of targetOriginArg.properties) {
|
|
99
89
|
if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
|
|
@@ -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.noSensitiveCookieJs = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -30,17 +25,10 @@ const DEFAULT_SENSITIVE_PATTERNS = [
|
|
|
30
25
|
'credential',
|
|
31
26
|
'bearer',
|
|
32
27
|
];
|
|
33
|
-
/**
|
|
34
|
-
* Check if cookie key matches sensitive patterns
|
|
35
|
-
*/
|
|
36
28
|
function isSensitiveKey(key, patterns) {
|
|
37
29
|
const lowerKey = key.toLowerCase();
|
|
38
30
|
return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
|
|
39
31
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Parse cookie string to extract key
|
|
42
|
-
* e.g., "token=abc123; Secure" -> "token"
|
|
43
|
-
*/
|
|
44
32
|
function extractCookieKey(cookieString) {
|
|
45
33
|
const match = cookieString.match(/^([^=]+)=/);
|
|
46
34
|
return match ? match[1].trim() : null;
|
|
@@ -110,13 +98,11 @@ exports.noSensitiveCookieJs = (0, eslint_devkit_1.createRule)({
|
|
|
110
98
|
}
|
|
111
99
|
return {
|
|
112
100
|
AssignmentExpression(node) {
|
|
113
|
-
// Check for document.cookie = "..."
|
|
114
101
|
if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
115
102
|
return;
|
|
116
103
|
}
|
|
117
104
|
const obj = node.left.object;
|
|
118
105
|
const prop = node.left.property;
|
|
119
|
-
// Check if it's document.cookie
|
|
120
106
|
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
121
107
|
obj.name !== 'document') {
|
|
122
108
|
return;
|
|
@@ -125,22 +111,18 @@ exports.noSensitiveCookieJs = (0, eslint_devkit_1.createRule)({
|
|
|
125
111
|
prop.name !== 'cookie') {
|
|
126
112
|
return;
|
|
127
113
|
}
|
|
128
|
-
// Check the assigned value
|
|
129
114
|
const value = node.right;
|
|
130
115
|
let cookieKey = null;
|
|
131
|
-
// String literal: document.cookie = "token=abc"
|
|
132
116
|
if (value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
133
117
|
typeof value.value === 'string') {
|
|
134
118
|
cookieKey = extractCookieKey(value.value);
|
|
135
119
|
}
|
|
136
|
-
// Template literal: document.cookie = `token=${value}`
|
|
137
120
|
if (value.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
|
|
138
121
|
const firstQuasi = value.quasis[0];
|
|
139
122
|
if (firstQuasi) {
|
|
140
123
|
cookieKey = extractCookieKey(firstQuasi.value.raw);
|
|
141
124
|
}
|
|
142
125
|
}
|
|
143
|
-
// Binary expression: document.cookie = "token=" + value
|
|
144
126
|
if (value.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
|
|
145
127
|
const left = value.left;
|
|
146
128
|
if (left.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
@@ -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.noSensitiveDataInAnalytics = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Prevent PII sent to analytics
|
|
11
|
-
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
-
* @see https://cwe.mitre.org/data/definitions/359.html
|
|
13
|
-
*/
|
|
14
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
5
|
exports.noSensitiveDataInAnalytics = (0, eslint_devkit_1.createRule)({
|
|
16
6
|
name: 'no-sensitive-data-in-analytics',
|
|
@@ -43,7 +33,6 @@ exports.noSensitiveDataInAnalytics = (0, eslint_devkit_1.createRule)({
|
|
|
43
33
|
}
|
|
44
34
|
return {
|
|
45
35
|
CallExpression(node) {
|
|
46
|
-
// analytics.track() with sensitive data
|
|
47
36
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
48
37
|
node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
49
38
|
node.callee.object.name === 'analytics' &&
|
|
@@ -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.noSensitiveDataInCache = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Prevent caching sensitive data without encryption
|
|
11
|
-
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
-
* @see https://cwe.mitre.org/data/definitions/524.html
|
|
13
|
-
*/
|
|
14
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
5
|
exports.noSensitiveDataInCache = (0, eslint_devkit_1.createRule)({
|
|
16
6
|
name: 'no-sensitive-data-in-cache',
|
|
@@ -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.noSensitiveIndexeddb = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Sensitive store/key patterns
|
|
11
5
|
const SENSITIVE_PATTERNS = [
|
|
12
6
|
/password/i,
|
|
13
7
|
/secret/i,
|
|
@@ -74,7 +68,6 @@ exports.noSensitiveIndexeddb = (0, eslint_devkit_1.createRule)({
|
|
|
74
68
|
}
|
|
75
69
|
return {
|
|
76
70
|
CallExpression(node) {
|
|
77
|
-
// Check for db.createObjectStore('sensitiveStore')
|
|
78
71
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
79
72
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
80
73
|
node.callee.property.name === 'createObjectStore') {
|
|
@@ -92,7 +85,6 @@ exports.noSensitiveIndexeddb = (0, eslint_devkit_1.createRule)({
|
|
|
92
85
|
}
|
|
93
86
|
}
|
|
94
87
|
}
|
|
95
|
-
// Check for store.add/put with sensitive key names
|
|
96
88
|
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
97
89
|
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
98
90
|
(node.callee.property.name === 'add' || node.callee.property.name === 'put')) {
|
|
@@ -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.noSensitiveLocalstorage = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -29,9 +24,6 @@ const DEFAULT_SENSITIVE_PATTERNS = [
|
|
|
29
24
|
'credential',
|
|
30
25
|
'bearer',
|
|
31
26
|
];
|
|
32
|
-
/**
|
|
33
|
-
* Check if key matches sensitive patterns
|
|
34
|
-
*/
|
|
35
27
|
function isSensitiveKey(key, patterns) {
|
|
36
28
|
const lowerKey = key.toLowerCase();
|
|
37
29
|
return patterns.some((pattern) => lowerKey.includes(pattern.toLowerCase()));
|
|
@@ -109,7 +101,6 @@ exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
|
|
|
109
101
|
return {
|
|
110
102
|
CallExpression(node) {
|
|
111
103
|
const callee = node.callee;
|
|
112
|
-
// Check for localStorage.setItem() or sessionStorage.setItem()
|
|
113
104
|
if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
114
105
|
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
115
106
|
storageObjects.includes(callee.object.name) &&
|
|
@@ -124,7 +115,6 @@ exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
|
|
|
124
115
|
keyValue = keyArg.value;
|
|
125
116
|
}
|
|
126
117
|
else if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
127
|
-
// Variable name might be indicative
|
|
128
118
|
keyValue = keyArg.name;
|
|
129
119
|
}
|
|
130
120
|
if (keyValue && isSensitiveKey(keyValue, sensitivePatterns)) {
|
|
@@ -145,7 +135,6 @@ exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
|
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
137
|
},
|
|
148
|
-
// Also check direct assignment: localStorage['token'] = value
|
|
149
138
|
AssignmentExpression(node) {
|
|
150
139
|
if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
151
140
|
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.noSensitiveSessionstorage = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
-
// Sensitive data patterns
|
|
11
5
|
const SENSITIVE_PATTERNS = [
|
|
12
6
|
/password/i,
|
|
13
7
|
/passwd/i,
|
|
@@ -29,9 +23,6 @@ const SENSITIVE_PATTERNS = [
|
|
|
29
23
|
/pin/i,
|
|
30
24
|
/encryption[_-]?key/i,
|
|
31
25
|
];
|
|
32
|
-
/**
|
|
33
|
-
* Check if key matches sensitive patterns
|
|
34
|
-
*/
|
|
35
26
|
function isSensitiveKey(key, additionalPatterns = []) {
|
|
36
27
|
const allPatterns = [
|
|
37
28
|
...SENSITIVE_PATTERNS,
|
|
@@ -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.noTrackingWithoutConsent = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* @fileoverview Require consent before tracking
|
|
11
|
-
*/
|
|
12
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
5
|
exports.noTrackingWithoutConsent = (0, eslint_devkit_1.createRule)({
|
|
14
6
|
name: 'no-tracking-without-consent',
|
|
@@ -53,7 +45,6 @@ exports.noTrackingWithoutConsent = (0, eslint_devkit_1.createRule)({
|
|
|
53
45
|
}
|
|
54
46
|
return {
|
|
55
47
|
CallExpression(node) {
|
|
56
|
-
// Detect analytics.track() or similar
|
|
57
48
|
if (node.callee.type === 'MemberExpression' &&
|
|
58
49
|
node.callee.object.type === 'Identifier' &&
|
|
59
50
|
node.callee.object.name === 'analytics' &&
|
|
@@ -63,7 +54,6 @@ exports.noTrackingWithoutConsent = (0, eslint_devkit_1.createRule)({
|
|
|
63
54
|
report(node);
|
|
64
55
|
}
|
|
65
56
|
}
|
|
66
|
-
// Google Analytics gtag
|
|
67
57
|
if (node.callee.type === 'Identifier' && node.callee.name === 'gtag') {
|
|
68
58
|
if (!isInsideConsentCheck(node)) {
|
|
69
59
|
report(node);
|
|
@@ -1,16 +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.noUnencryptedTransmission = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Default insecure protocol patterns
|
|
13
|
-
*/
|
|
14
6
|
const DEFAULT_INSECURE_PROTOCOLS = [
|
|
15
7
|
'http://',
|
|
16
8
|
'ws://',
|
|
@@ -20,9 +12,6 @@ const DEFAULT_INSECURE_PROTOCOLS = [
|
|
|
20
12
|
'redis://',
|
|
21
13
|
'mysql://',
|
|
22
14
|
];
|
|
23
|
-
/**
|
|
24
|
-
* Secure protocol alternatives
|
|
25
|
-
*/
|
|
26
15
|
const SECURE_ALTERNATIVES = {
|
|
27
16
|
'http://': 'https://',
|
|
28
17
|
'ws://': 'wss://',
|
|
@@ -32,34 +21,24 @@ const SECURE_ALTERNATIVES = {
|
|
|
32
21
|
'redis://': 'rediss://',
|
|
33
22
|
'mysql://': 'mysqls://',
|
|
34
23
|
};
|
|
35
|
-
/**
|
|
36
|
-
* Check if a string contains insecure protocol
|
|
37
|
-
*/
|
|
38
24
|
function containsInsecureProtocol(value, insecureProtocols, secureAlternatives) {
|
|
39
25
|
const lowerValue = value.toLowerCase();
|
|
40
26
|
for (const protocol of insecureProtocols) {
|
|
41
27
|
const lowerProtocol = protocol.toLowerCase();
|
|
42
|
-
// Check if the protocol appears in the value (as a URL scheme)
|
|
43
28
|
if (lowerValue.includes(lowerProtocol)) {
|
|
44
|
-
// Check if it's not already using the secure version
|
|
45
29
|
const secureAlternative = secureAlternatives[lowerProtocol];
|
|
46
30
|
if (secureAlternative) {
|
|
47
|
-
// Only report if secure version is not present
|
|
48
31
|
if (!lowerValue.includes(secureAlternative.toLowerCase())) {
|
|
49
32
|
return { isInsecure: true, protocol };
|
|
50
33
|
}
|
|
51
34
|
}
|
|
52
35
|
else {
|
|
53
|
-
// No secure alternative defined, so it's insecure
|
|
54
36
|
return { isInsecure: true, protocol };
|
|
55
37
|
}
|
|
56
38
|
}
|
|
57
39
|
}
|
|
58
40
|
return { isInsecure: false, protocol: '' };
|
|
59
41
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Check if a string matches any ignore pattern
|
|
62
|
-
*/
|
|
63
42
|
function matchesIgnorePattern(text, patterns) {
|
|
64
43
|
return patterns.some(pattern => {
|
|
65
44
|
try {
|
|
@@ -146,7 +125,6 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
146
125
|
const protocolsToCheck = insecureProtocols && insecureProtocols.length > 0
|
|
147
126
|
? insecureProtocols
|
|
148
127
|
: DEFAULT_INSECURE_PROTOCOLS;
|
|
149
|
-
// Merge user-provided secure alternatives with defaults
|
|
150
128
|
const secureAlternativesToUse = secureAlternatives && Object.keys(secureAlternatives).length > 0
|
|
151
129
|
? { ...SECURE_ALTERNATIVES, ...secureAlternatives }
|
|
152
130
|
: SECURE_ALTERNATIVES;
|
|
@@ -159,22 +137,16 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
159
137
|
}
|
|
160
138
|
const value = node.value;
|
|
161
139
|
const text = sourceCode.getText(node);
|
|
162
|
-
// Check if it matches any ignore pattern
|
|
163
140
|
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
164
141
|
return;
|
|
165
142
|
}
|
|
166
|
-
// Skip test files (allow localhost in test files)
|
|
167
143
|
if (isTestFile) {
|
|
168
|
-
// Only allow localhost URLs in test files
|
|
169
144
|
if (text.includes('localhost')) {
|
|
170
145
|
return;
|
|
171
146
|
}
|
|
172
|
-
// For other URLs in test files, still check them
|
|
173
147
|
}
|
|
174
148
|
const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
|
|
175
149
|
if (isInsecure) {
|
|
176
|
-
// NOTE: localhost URLs in test files already returned above, so no
|
|
177
|
-
// second `isTestFile && localhost` check is needed here.
|
|
178
150
|
const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
|
|
179
151
|
const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
|
|
180
152
|
context.report({
|
|
@@ -193,7 +165,6 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
193
165
|
},
|
|
194
166
|
fix(fixer) {
|
|
195
167
|
if (secureProtocol && secureProtocol !== 'secure protocol') {
|
|
196
|
-
// Replace the insecure protocol with secure one
|
|
197
168
|
const newValue = value.replace(new RegExp(protocol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), secureProtocol);
|
|
198
169
|
return fixer.replaceText(node, JSON.stringify(newValue));
|
|
199
170
|
}
|
|
@@ -209,11 +180,9 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
209
180
|
return;
|
|
210
181
|
}
|
|
211
182
|
const text = sourceCode.getText(node);
|
|
212
|
-
// Check if it matches any ignore pattern
|
|
213
183
|
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
214
184
|
return;
|
|
215
185
|
}
|
|
216
|
-
// Check each quasis (static parts) and expressions
|
|
217
186
|
for (const quasi of node.quasis) {
|
|
218
187
|
const value = quasi.value.raw;
|
|
219
188
|
const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
|
|
@@ -227,7 +196,6 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
227
196
|
issue: `using insecure protocol ${protocol} in template literal`,
|
|
228
197
|
safeAlternative,
|
|
229
198
|
},
|
|
230
|
-
// Don't provide auto-fix for template literals (too risky - might break interpolation)
|
|
231
199
|
});
|
|
232
200
|
}
|
|
233
201
|
}
|
|
@@ -1,29 +1,19 @@
|
|
|
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.noUnescapedUrlParameter = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Check if a node is inside a URL encoding function call
|
|
13
|
-
*/
|
|
14
6
|
function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
15
7
|
let current = node;
|
|
16
8
|
while (current) {
|
|
17
9
|
if (current.type === 'CallExpression') {
|
|
18
10
|
const callee = current.callee;
|
|
19
|
-
// Check for encodeURIComponent, encodeURI
|
|
20
11
|
if (callee.type === 'Identifier') {
|
|
21
12
|
const calleeName = callee.name;
|
|
22
13
|
if (['encodeURIComponent', 'encodeURI', 'escape'].includes(calleeName)) {
|
|
23
14
|
return true;
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
// Check if it's a trusted library call
|
|
27
17
|
if (callee.type === 'MemberExpression') {
|
|
28
18
|
const object = callee.object;
|
|
29
19
|
if (object.type === 'Identifier') {
|
|
@@ -34,7 +24,6 @@ function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
|
34
24
|
}
|
|
35
25
|
}
|
|
36
26
|
}
|
|
37
|
-
// Traverse up the AST
|
|
38
27
|
if ('parent' in current && current.parent) {
|
|
39
28
|
current = current.parent;
|
|
40
29
|
}
|
|
@@ -44,9 +33,6 @@ function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
|
44
33
|
}
|
|
45
34
|
return false;
|
|
46
35
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Check if a string matches any ignore pattern
|
|
49
|
-
*/
|
|
50
36
|
function matchesIgnorePattern(text, ignorePatterns) {
|
|
51
37
|
return ignorePatterns.some(pattern => {
|
|
52
38
|
try {
|
|
@@ -58,25 +44,20 @@ function matchesIgnorePattern(text, ignorePatterns) {
|
|
|
58
44
|
}
|
|
59
45
|
});
|
|
60
46
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Check if a node is a URL construction pattern
|
|
63
|
-
*/
|
|
64
47
|
function isUrlConstruction(node, sourceCode) {
|
|
65
48
|
let text = sourceCode.getText(node);
|
|
66
|
-
// For template literals, combine raw strings to improve pattern detection
|
|
67
49
|
if (node.type === 'TemplateLiteral') {
|
|
68
50
|
text = node.quasis.map(q => q.value.raw).join('');
|
|
69
51
|
}
|
|
70
|
-
// Check for URL construction patterns
|
|
71
52
|
const urlPatterns = [
|
|
72
|
-
/\bhttps?:\/\//,
|
|
53
|
+
/\bhttps?:\/\//,
|
|
73
54
|
/\bnew\s+URL\s*\(/,
|
|
74
|
-
/\burl\s*[=:]\s*/,
|
|
75
|
-
/\burl\s*\+/,
|
|
55
|
+
/\burl\s*[=:]\s*/,
|
|
56
|
+
/\burl\s*\+/,
|
|
76
57
|
/\bwindow\.location/,
|
|
77
58
|
/\blocation\.href/,
|
|
78
59
|
/\bwindow\.open\s*\(/,
|
|
79
|
-
/\?[^=]+=/,
|
|
60
|
+
/\?[^=]+=/,
|
|
80
61
|
];
|
|
81
62
|
return urlPatterns.some(pattern => pattern.test(text));
|
|
82
63
|
}
|
|
@@ -106,7 +87,6 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
106
87
|
issueName: 'Use encodeURIComponent',
|
|
107
88
|
description: 'Use encodeURIComponent for URL params',
|
|
108
89
|
severity: 'LOW',
|
|
109
|
-
// oxlint-disable-next-line no-template-curly-in-string
|
|
110
90
|
fix: '`https://example.com?q=${encodeURIComponent(param)}`',
|
|
111
91
|
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent',
|
|
112
92
|
}),
|
|
@@ -161,41 +141,32 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
161
141
|
if (isTestFile) {
|
|
162
142
|
return;
|
|
163
143
|
}
|
|
164
|
-
// Check if this is a URL construction
|
|
165
144
|
if (!isUrlConstruction(node, sourceCode)) {
|
|
166
145
|
return;
|
|
167
146
|
}
|
|
168
|
-
// Check each expression in the template
|
|
169
147
|
for (const expression of node.expressions) {
|
|
170
148
|
const text = sourceCode.getText(expression);
|
|
171
|
-
// Check if it matches any ignore pattern
|
|
172
149
|
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
173
150
|
continue;
|
|
174
151
|
}
|
|
175
|
-
// Check if it's already encoded
|
|
176
152
|
if (isInsideEncodingCall(expression, sourceCode, trustedLibraries)) {
|
|
177
153
|
continue;
|
|
178
154
|
}
|
|
179
|
-
// Check if it's a user input pattern
|
|
180
155
|
const userInputPatterns = [
|
|
181
156
|
/\breq\.(query|params|body|headers|cookies)/,
|
|
182
157
|
/\brequest\.(query|params|body)/,
|
|
183
158
|
/\buserInput\b/i,
|
|
184
159
|
/\binput\b/i,
|
|
185
160
|
/\bsearchParams\b/,
|
|
186
|
-
/\bparam\b/i,
|
|
161
|
+
/\bparam\b/i,
|
|
187
162
|
];
|
|
188
|
-
// Check both the expression text and the full template literal
|
|
189
|
-
// This catches nested patterns like req.query.id
|
|
190
163
|
const fullText = sourceCode.getText(node);
|
|
191
164
|
const exprText = sourceCode.getText(expression);
|
|
192
165
|
const isUserInput = userInputPatterns.some(pattern => pattern.test(text)) ||
|
|
193
166
|
userInputPatterns.some(pattern => pattern.test(fullText)) ||
|
|
194
167
|
userInputPatterns.some(pattern => pattern.test(exprText)) ||
|
|
195
|
-
// Also check for nested member expressions like req.query.id
|
|
196
168
|
(expression.type === 'MemberExpression' &&
|
|
197
169
|
userInputPatterns.some(pattern => {
|
|
198
|
-
// Check the full expression including nested properties
|
|
199
170
|
return pattern.test(exprText);
|
|
200
171
|
}));
|
|
201
172
|
if (isUserInput) {
|
|
@@ -224,23 +195,18 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
224
195
|
if (isTestFile) {
|
|
225
196
|
return;
|
|
226
197
|
}
|
|
227
|
-
// Check for string concatenation in URL construction
|
|
228
198
|
if (node.operator === '+') {
|
|
229
199
|
if (!isUrlConstruction(node, sourceCode)) {
|
|
230
200
|
return;
|
|
231
201
|
}
|
|
232
|
-
// Check right side (usually the parameter)
|
|
233
202
|
if (node.right.type !== 'Literal') {
|
|
234
203
|
const rightText = sourceCode.getText(node.right);
|
|
235
|
-
// Check if it matches any ignore pattern
|
|
236
204
|
if (matchesIgnorePattern(rightText, ignorePatterns)) {
|
|
237
205
|
return;
|
|
238
206
|
}
|
|
239
|
-
// Check if it's already encoded
|
|
240
207
|
if (isInsideEncodingCall(node.right, sourceCode, trustedLibraries)) {
|
|
241
208
|
return;
|
|
242
209
|
}
|
|
243
|
-
// Check if it's a user input pattern
|
|
244
210
|
const userInputPatterns = [
|
|
245
211
|
/\breq\.(query|params|body)/,
|
|
246
212
|
/\brequest\.(query|params|body)/,
|
|
@@ -283,26 +249,21 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
283
249
|
];
|
|
284
250
|
if (patterns.some(p => p.test(text)))
|
|
285
251
|
return true;
|
|
286
|
-
// Trace identifiers
|
|
287
252
|
if (node.type === 'Identifier') {
|
|
288
253
|
if (visited.has(node.name))
|
|
289
254
|
return false;
|
|
290
255
|
visited.add(node.name);
|
|
291
256
|
const scope = sourceCode.getScope(node);
|
|
292
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
293
257
|
const variable = scope.variables.find((v) => v.name === node.name);
|
|
294
258
|
if (variable && variable.defs.length > 0) {
|
|
295
259
|
const def = variable.defs[0];
|
|
296
260
|
if (def.type === 'Variable' && def.node.init) {
|
|
297
261
|
const init = def.node.init;
|
|
298
|
-
// Check if init is constructed from other user inputs
|
|
299
262
|
if (isUserControlled(init, visited))
|
|
300
263
|
return true;
|
|
301
|
-
// Check if init is a TemplateLiteral containing user inputs in expressions
|
|
302
264
|
if (init.type === 'TemplateLiteral') {
|
|
303
265
|
return init.expressions.some(expr => isUserControlled(expr, visited));
|
|
304
266
|
}
|
|
305
|
-
// Check if init is BinaryExpression (concatenation)
|
|
306
267
|
if (init.type === 'BinaryExpression') {
|
|
307
268
|
return isUserControlled(init.left, visited) || isUserControlled(init.right, visited);
|
|
308
269
|
}
|
|
@@ -317,7 +278,6 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
317
278
|
AssignmentExpression(node) {
|
|
318
279
|
if (isTestFile)
|
|
319
280
|
return;
|
|
320
|
-
// Check for window.location = ... or window.location.href = ...
|
|
321
281
|
const left = node.left;
|
|
322
282
|
let isLocationAssignment = false;
|
|
323
283
|
if (left.type === 'MemberExpression') {
|
|
@@ -330,13 +290,11 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
|
330
290
|
}
|
|
331
291
|
}
|
|
332
292
|
else if (left.type === 'Identifier' && left.name === 'location') {
|
|
333
|
-
// In browser location = ... is valid
|
|
334
293
|
isLocationAssignment = true;
|
|
335
294
|
}
|
|
336
295
|
if (isLocationAssignment) {
|
|
337
296
|
const right = node.right;
|
|
338
297
|
const rightText = sourceCode.getText(right);
|
|
339
|
-
// Skip TemplateLiteral and BinaryExpression as they are covered by their own visitors
|
|
340
298
|
if (right.type === 'TemplateLiteral' || right.type === 'BinaryExpression') {
|
|
341
299
|
return;
|
|
342
300
|
}
|
|
@@ -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.noUnsafeEvalCsp = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -56,9 +51,6 @@ exports.noUnsafeEvalCsp = (0, eslint_devkit_1.createRule)({
|
|
|
56
51
|
return {};
|
|
57
52
|
}
|
|
58
53
|
const UNSAFE_EVAL_PATTERN = /'unsafe-eval'/gi;
|
|
59
|
-
/**
|
|
60
|
-
* Check a string value for unsafe-eval
|
|
61
|
-
*/
|
|
62
54
|
function checkForUnsafeEval(node, value) {
|
|
63
55
|
if (UNSAFE_EVAL_PATTERN.test(value)) {
|
|
64
56
|
context.report({
|
|
@@ -69,13 +61,11 @@ exports.noUnsafeEvalCsp = (0, eslint_devkit_1.createRule)({
|
|
|
69
61
|
}
|
|
70
62
|
}
|
|
71
63
|
return {
|
|
72
|
-
// Check string literals
|
|
73
64
|
Literal(node) {
|
|
74
65
|
if (typeof node.value === 'string') {
|
|
75
66
|
checkForUnsafeEval(node, node.value);
|
|
76
67
|
}
|
|
77
68
|
},
|
|
78
|
-
// Check template literals
|
|
79
69
|
TemplateLiteral(node) {
|
|
80
70
|
const value = node.quasis.map((q) => q.value.raw).join('');
|
|
81
71
|
checkForUnsafeEval(node, value);
|
|
@@ -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.noUnsafeInlineCsp = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -56,9 +51,6 @@ exports.noUnsafeInlineCsp = (0, eslint_devkit_1.createRule)({
|
|
|
56
51
|
return {};
|
|
57
52
|
}
|
|
58
53
|
const UNSAFE_INLINE_PATTERN = /'unsafe-inline'/gi;
|
|
59
|
-
/**
|
|
60
|
-
* Check a string value for unsafe-inline
|
|
61
|
-
*/
|
|
62
54
|
function checkForUnsafeInline(node, value) {
|
|
63
55
|
if (UNSAFE_INLINE_PATTERN.test(value)) {
|
|
64
56
|
context.report({
|
|
@@ -69,13 +61,11 @@ exports.noUnsafeInlineCsp = (0, eslint_devkit_1.createRule)({
|
|
|
69
61
|
}
|
|
70
62
|
}
|
|
71
63
|
return {
|
|
72
|
-
// Check string literals
|
|
73
64
|
Literal(node) {
|
|
74
65
|
if (typeof node.value === 'string') {
|
|
75
66
|
checkForUnsafeInline(node, node.value);
|
|
76
67
|
}
|
|
77
68
|
},
|
|
78
|
-
// Check template literals
|
|
79
69
|
TemplateLiteral(node) {
|
|
80
70
|
const value = node.quasis.map((q) => q.value.raw).join('');
|
|
81
71
|
checkForUnsafeInline(node, value);
|