eslint-plugin-browser-security 1.1.0 → 1.2.0
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/README.md +94 -133
- package/package.json +4 -3
- package/src/index.js +62 -0
- package/src/rules/detect-mixed-content/index.d.ts +12 -0
- package/src/rules/detect-mixed-content/index.js +45 -0
- package/src/rules/no-allow-arbitrary-loads/index.d.ts +12 -0
- package/src/rules/no-allow-arbitrary-loads/index.js +48 -0
- package/src/rules/no-clickjacking/index.d.ts +36 -0
- package/src/rules/no-clickjacking/index.js +401 -0
- package/src/rules/no-client-side-auth-logic/index.d.ts +12 -0
- package/src/rules/no-client-side-auth-logic/index.js +74 -0
- package/src/rules/no-cookie-auth-tokens/index.d.ts +3 -1
- package/src/rules/no-credentials-in-query-params/index.d.ts +12 -0
- package/src/rules/no-credentials-in-query-params/index.js +62 -0
- package/src/rules/no-disabled-certificate-validation/index.d.ts +12 -0
- package/src/rules/no-disabled-certificate-validation/index.js +66 -0
- package/src/rules/no-dynamic-service-worker-url/index.d.ts +3 -1
- package/src/rules/no-eval/index.d.ts +3 -1
- package/src/rules/no-filereader-innerhtml/index.d.ts +3 -1
- package/src/rules/no-http-urls/index.d.ts +17 -0
- package/src/rules/no-http-urls/index.js +119 -0
- package/src/rules/no-innerhtml/index.d.ts +3 -1
- package/src/rules/no-insecure-redirects/index.d.ts +26 -0
- package/src/rules/no-insecure-redirects/index.js +221 -0
- package/src/rules/no-insecure-websocket/index.d.ts +12 -0
- package/src/rules/no-insecure-websocket/index.js +66 -0
- package/src/rules/no-jwt-in-storage/index.d.ts +3 -1
- package/src/rules/no-missing-cors-check/index.d.ts +28 -0
- package/src/rules/no-missing-cors-check/index.js +404 -0
- package/src/rules/no-missing-csrf-protection/index.d.ts +30 -0
- package/src/rules/no-missing-csrf-protection/index.js +185 -0
- package/src/rules/no-missing-security-headers/index.d.ts +26 -0
- package/src/rules/no-missing-security-headers/index.js +223 -0
- package/src/rules/no-password-in-url/index.d.ts +12 -0
- package/src/rules/no-password-in-url/index.js +55 -0
- package/src/rules/no-permissive-cors/index.d.ts +12 -0
- package/src/rules/no-permissive-cors/index.js +74 -0
- package/src/rules/no-postmessage-innerhtml/index.d.ts +3 -1
- package/src/rules/no-postmessage-wildcard-origin/index.d.ts +3 -1
- package/src/rules/no-sensitive-cookie-js/index.d.ts +3 -1
- package/src/rules/no-sensitive-data-in-analytics/index.d.ts +12 -0
- package/src/rules/no-sensitive-data-in-analytics/index.js +66 -0
- package/src/rules/no-sensitive-data-in-cache/index.d.ts +12 -0
- package/src/rules/no-sensitive-data-in-cache/index.js +53 -0
- package/src/rules/no-sensitive-indexeddb/index.d.ts +3 -1
- package/src/rules/no-sensitive-localstorage/index.d.ts +3 -1
- package/src/rules/no-sensitive-sessionstorage/index.d.ts +3 -1
- package/src/rules/no-tracking-without-consent/index.d.ts +12 -0
- package/src/rules/no-tracking-without-consent/index.js +72 -0
- package/src/rules/no-unencrypted-transmission/index.d.ts +30 -0
- package/src/rules/no-unencrypted-transmission/index.js +241 -0
- package/src/rules/no-unescaped-url-parameter/index.d.ts +28 -0
- package/src/rules/no-unescaped-url-parameter/index.js +360 -0
- package/src/rules/no-unsafe-eval-csp/index.d.ts +3 -1
- package/src/rules/no-unsafe-inline-csp/index.d.ts +3 -1
- package/src/rules/no-unvalidated-deeplinks/index.d.ts +12 -0
- package/src/rules/no-unvalidated-deeplinks/index.js +67 -0
- package/src/rules/no-websocket-eval/index.d.ts +3 -1
- package/src/rules/no-websocket-innerhtml/index.d.ts +3 -1
- package/src/rules/no-worker-message-innerhtml/index.d.ts +3 -1
- package/src/rules/require-blob-url-revocation/index.d.ts +3 -1
- package/src/rules/require-cookie-secure-attrs/index.d.ts +3 -1
- package/src/rules/require-csp-headers/index.d.ts +12 -0
- package/src/rules/require-csp-headers/index.js +69 -0
- package/src/rules/require-https-only/index.d.ts +12 -0
- package/src/rules/require-https-only/index.js +67 -0
- package/src/rules/require-mime-type-validation/index.d.ts +12 -0
- package/src/rules/require-mime-type-validation/index.js +71 -0
- package/src/rules/require-postmessage-origin-check/index.d.ts +3 -1
- package/src/rules/require-url-validation/index.d.ts +12 -0
- package/src/rules/require-url-validation/index.js +77 -0
- package/src/rules/require-websocket-wss/index.d.ts +3 -1
- package/LICENSE +0 -21
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireHttpsOnly = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Enforce HTTPS for all external requests
|
|
11
|
+
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
+
* @see https://cwe.mitre.org/data/definitions/319.html
|
|
13
|
+
*/
|
|
14
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
|
+
/** HTTP methods supported by axios for request interception */
|
|
16
|
+
const AXIOS_HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
17
|
+
exports.requireHttpsOnly = (0, eslint_devkit_1.createRule)({
|
|
18
|
+
name: 'require-https-only',
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Enforce HTTPS for all external requests',
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
27
|
+
issueName: 'violation Detected',
|
|
28
|
+
cwe: 'CWE-319',
|
|
29
|
+
description: 'Enforce HTTPS for all external requests detected - this is a security risk',
|
|
30
|
+
severity: 'HIGH',
|
|
31
|
+
fix: 'Review and apply secure practices',
|
|
32
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
schema: [],
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
create(context) {
|
|
39
|
+
function report(node) {
|
|
40
|
+
context.report({
|
|
41
|
+
node,
|
|
42
|
+
messageId: 'violationDetected',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
CallExpression(node) {
|
|
47
|
+
const callee = node.callee;
|
|
48
|
+
// Check fetch() calls
|
|
49
|
+
const isFetch = callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && callee.name === 'fetch';
|
|
50
|
+
// Check axios.get/post/etc calls
|
|
51
|
+
const isAxios = callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
52
|
+
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
53
|
+
callee.object.name === 'axios' &&
|
|
54
|
+
callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
55
|
+
AXIOS_HTTP_METHODS.includes(callee.property.name);
|
|
56
|
+
if ((isFetch || isAxios) && node.arguments[0]) {
|
|
57
|
+
const url = node.arguments[0];
|
|
58
|
+
if (url.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
59
|
+
typeof url.value === 'string' &&
|
|
60
|
+
url.value.startsWith('http://')) {
|
|
61
|
+
report(node);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export interface Options {
|
|
7
|
+
}
|
|
8
|
+
type RuleOptions = [Options?];
|
|
9
|
+
export declare const requireMimeTypeValidation: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireMimeTypeValidation = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Require MIME type validation for uploads
|
|
11
|
+
*/
|
|
12
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
|
+
exports.requireMimeTypeValidation = (0, eslint_devkit_1.createRule)({
|
|
14
|
+
name: 'require-mime-type-validation',
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Require MIME type validation for file uploads',
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
23
|
+
issueName: 'Missing MIME Validation',
|
|
24
|
+
cwe: 'CWE-434',
|
|
25
|
+
description: 'File upload without MIME type validation - unrestricted upload vulnerability',
|
|
26
|
+
severity: 'HIGH',
|
|
27
|
+
fix: 'Add fileFilter option to validate MIME types',
|
|
28
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/434.html',
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
function report(node) {
|
|
36
|
+
context.report({ node, messageId: 'violationDetected' });
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
// Detect multer().single() or multer().array() without fileFilter
|
|
41
|
+
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
42
|
+
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
43
|
+
['single', 'array', 'fields'].includes(node.callee.property.name)) {
|
|
44
|
+
// Check if parent has fileFilter configuration
|
|
45
|
+
const calleeObj = node.callee.object;
|
|
46
|
+
if (calleeObj.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
|
|
47
|
+
const multerArgs = calleeObj.arguments[0];
|
|
48
|
+
if (multerArgs && multerArgs.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
49
|
+
const hasFileFilter = multerArgs.properties.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Property && p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && (p.key.name === 'fileFilter' || p.key.name === 'limits'));
|
|
50
|
+
if (!hasFileFilter) {
|
|
51
|
+
report(node);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (!multerArgs) {
|
|
55
|
+
// No config at all = no validation
|
|
56
|
+
report(node);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Detect upload() calls directly
|
|
61
|
+
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.callee.name === 'upload') {
|
|
62
|
+
// Check if there's validation in arguments
|
|
63
|
+
if (node.arguments.length === 0 ||
|
|
64
|
+
(node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier)) {
|
|
65
|
+
report(node);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -20,5 +20,7 @@ export interface Options {
|
|
|
20
20
|
trustedOrigins?: string[];
|
|
21
21
|
}
|
|
22
22
|
type RuleOptions = [Options?];
|
|
23
|
-
export declare const requirePostmessageOriginCheck: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
23
|
+
export declare const requirePostmessageOriginCheck: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
24
26
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export interface Options {
|
|
7
|
+
}
|
|
8
|
+
type RuleOptions = [Options?];
|
|
9
|
+
export declare const requireUrlValidation: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireUrlValidation = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Enforce URL validation before navigation
|
|
11
|
+
*/
|
|
12
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
|
+
exports.requireUrlValidation = (0, eslint_devkit_1.createRule)({
|
|
14
|
+
name: 'require-url-validation',
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Enforce URL validation before navigation',
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
23
|
+
issueName: 'URL Validation Required',
|
|
24
|
+
cwe: 'CWE-601',
|
|
25
|
+
description: 'Unvalidated URL used for navigation - this is a security risk',
|
|
26
|
+
severity: 'HIGH',
|
|
27
|
+
fix: 'Validate URLs before using them for navigation',
|
|
28
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/601.html',
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
function report(node) {
|
|
36
|
+
context.report({ node, messageId: 'violationDetected' });
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
AssignmentExpression(node) {
|
|
40
|
+
// Detect window.location assignment from user input
|
|
41
|
+
if (node.left.type === 'MemberExpression' &&
|
|
42
|
+
node.left.object.type === 'Identifier' &&
|
|
43
|
+
node.left.object.name === 'window' &&
|
|
44
|
+
node.left.property.type === 'Identifier' &&
|
|
45
|
+
node.left.property.name === 'location') {
|
|
46
|
+
// Flag if right side is a variable (not a literal URL)
|
|
47
|
+
if (node.right.type === 'Identifier') {
|
|
48
|
+
report(node);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Detect location.href assignment
|
|
52
|
+
if (node.left.type === 'MemberExpression' &&
|
|
53
|
+
node.left.object.type === 'Identifier' &&
|
|
54
|
+
node.left.object.name === 'location' &&
|
|
55
|
+
node.left.property.type === 'Identifier' &&
|
|
56
|
+
node.left.property.name === 'href') {
|
|
57
|
+
if (node.right.type === 'Identifier') {
|
|
58
|
+
report(node);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
CallExpression(node) {
|
|
63
|
+
// Detect window.open with variable URL
|
|
64
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
65
|
+
node.callee.object.type === 'Identifier' &&
|
|
66
|
+
node.callee.object.name === 'window' &&
|
|
67
|
+
node.callee.property.type === 'Identifier' &&
|
|
68
|
+
node.callee.property.name === 'open') {
|
|
69
|
+
const urlArg = node.arguments[0];
|
|
70
|
+
if (urlArg && urlArg.type === 'Identifier') {
|
|
71
|
+
report(node);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|
|
@@ -20,5 +20,7 @@ export interface Options {
|
|
|
20
20
|
allowLocalhost?: boolean;
|
|
21
21
|
}
|
|
22
22
|
type RuleOptions = [Options?];
|
|
23
|
-
export declare const requireWebsocketWss: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
23
|
+
export declare const requireWebsocketWss: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
24
26
|
export {};
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Ofri Peretz
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|