eslint-plugin-secure-coding 3.4.0 → 3.4.1
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 -18
- package/src/index.d.ts +17 -23
- package/src/index.js +2 -131
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/detect-non-literal-regexp/index.js +5 -79
- package/src/rules/detect-object-injection/index.js +2 -221
- package/src/rules/detect-weak-password-validation/index.js +0 -12
- package/src/rules/no-directive-injection/index.js +0 -33
- package/src/rules/no-electron-security-issues/index.js +0 -41
- package/src/rules/no-format-string-injection/index.js +0 -82
- package/src/rules/no-graphql-injection/index.js +8 -133
- package/src/rules/no-hardcoded-credentials/index.js +3 -297
- package/src/rules/no-hardcoded-session-tokens/index.js +0 -11
- package/src/rules/no-improper-sanitization/index.js +0 -44
- package/src/rules/no-improper-type-validation/index.js +1 -51
- package/src/rules/no-insecure-comparison/index.js +2 -43
- package/src/rules/no-ldap-injection/index.js +8 -61
- package/src/rules/no-missing-authentication/index.js +2 -56
- package/src/rules/no-pii-in-logs/index.js +0 -13
- package/src/rules/no-privilege-escalation/index.js +2 -49
- package/src/rules/no-redos-vulnerable-regex/index.js +3 -49
- package/src/rules/no-sensitive-data-exposure/index.js +5 -29
- package/src/rules/no-template-injection/index.js +0 -6
- package/src/rules/no-unchecked-loop-condition/index.js +3 -99
- package/src/rules/no-unlimited-resource-allocation/index.js +2 -75
- package/src/rules/no-unsafe-deserialization/index.js +1 -111
- package/src/rules/no-unsafe-regex-construction/index.js +22 -62
- package/src/rules/no-weak-password-recovery/index.js +0 -43
- package/src/rules/no-xpath-injection/index.js +13 -75
- package/src/rules/no-xxe-injection/index.js +1 -47
- package/src/rules/require-backend-authorization/index.js +0 -10
- package/src/rules/require-secure-defaults/index.js +0 -10
- package/src/types/index.js +0 -5
- package/AGENTS.md +0 -131
- package/CHANGELOG.md +0 -379
- package/src/rules/detect-non-literal-regexp/index.d.ts +0 -28
- package/src/rules/detect-object-injection/index.d.ts +0 -35
- package/src/rules/detect-weak-password-validation/index.d.ts +0 -12
- package/src/rules/no-directive-injection/index.d.ts +0 -38
- package/src/rules/no-electron-security-issues/index.d.ts +0 -36
- package/src/rules/no-format-string-injection/index.d.ts +0 -44
- package/src/rules/no-graphql-injection/index.d.ts +0 -47
- package/src/rules/no-hardcoded-credentials/index.d.ts +0 -95
- package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -12
- package/src/rules/no-improper-sanitization/index.d.ts +0 -38
- package/src/rules/no-improper-type-validation/index.d.ts +0 -36
- package/src/rules/no-insecure-comparison/index.d.ts +0 -26
- package/src/rules/no-ldap-injection/index.d.ts +0 -53
- package/src/rules/no-missing-authentication/index.d.ts +0 -32
- package/src/rules/no-pii-in-logs/index.d.ts +0 -12
- package/src/rules/no-privilege-escalation/index.d.ts +0 -32
- package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -28
- package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -30
- package/src/rules/no-template-injection/index.d.ts +0 -23
- package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -38
- package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -38
- package/src/rules/no-unsafe-deserialization/index.d.ts +0 -40
- package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -30
- package/src/rules/no-weak-password-recovery/index.d.ts +0 -38
- package/src/rules/no-xpath-injection/index.d.ts +0 -39
- package/src/rules/no-xxe-injection/index.d.ts +0 -36
- package/src/rules/require-backend-authorization/index.d.ts +0 -12
- package/src/rules/require-secure-defaults/index.d.ts +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-secure-coding",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "ESLint plugin for secure coding — detects LDAP, XPath, XXE, GraphQL and template injection, unsafe deserialization, ReDoS, missing authentication, and PII in logs.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"homepage": "https://eslint.interlace.tools/docs/security/plugin-secure-coding?utm_source=npm&utm_medium=referral&utm_campaign=eslint-plugin-secure-coding",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/ofri-peretz/eslint",
|
|
27
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git",
|
|
28
28
|
"directory": "packages/eslint-plugin-secure-coding"
|
|
29
29
|
},
|
|
30
30
|
"bugs": {
|
|
@@ -35,11 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"src/",
|
|
38
|
-
"dist/",
|
|
39
38
|
"README.md",
|
|
40
|
-
"LICENSE"
|
|
41
|
-
"CHANGELOG.md",
|
|
42
|
-
"AGENTS.md"
|
|
39
|
+
"LICENSE"
|
|
43
40
|
],
|
|
44
41
|
"keywords": [
|
|
45
42
|
"eslint",
|
|
@@ -79,27 +76,17 @@
|
|
|
79
76
|
"engines": {
|
|
80
77
|
"node": ">=18.0.0"
|
|
81
78
|
},
|
|
82
|
-
"scripts": {
|
|
83
|
-
"build": "tsx ../../scripts/build-package.ts",
|
|
84
|
-
"test": "vitest run",
|
|
85
|
-
"test:coverage": "vitest run --coverage",
|
|
86
|
-
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
87
|
-
},
|
|
88
79
|
"dependencies": {
|
|
89
80
|
"tslib": "^2.3.0",
|
|
90
|
-
"@interlace/eslint-devkit": "^1.
|
|
81
|
+
"@interlace/eslint-devkit": "^1.6.1",
|
|
91
82
|
"scslre": "^0.3.0",
|
|
92
83
|
"@eslint-community/regexpp": "^4.10.0"
|
|
93
84
|
},
|
|
94
|
-
"devDependencies": {
|
|
95
|
-
"@typescript-eslint/parser": "^8.46.2",
|
|
96
|
-
"@typescript-eslint/rule-tester": "^8.46.2"
|
|
97
|
-
},
|
|
98
85
|
"peerDependencies": {
|
|
99
86
|
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
100
87
|
},
|
|
101
88
|
"funding": {
|
|
102
89
|
"type": "github",
|
|
103
|
-
"url": "https://github.com/ofri-peretz/eslint"
|
|
90
|
+
"url": "git+https://github.com/ofri-peretz/eslint.git"
|
|
104
91
|
}
|
|
105
92
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
export default plugin;
|
|
20
|
-
/**
|
|
21
|
-
* Re-export all types from the types barrel
|
|
22
|
-
*/
|
|
23
|
-
export type { AllSecurityRulesOptions, } from './types/index';
|
|
1
|
+
// Minimal declaration written by scripts/build-package.ts.
|
|
2
|
+
//
|
|
3
|
+
// tsc's generated entry declaration inlined every inferred rule-option type
|
|
4
|
+
// (up to 166 kB per plugin) for an API no consumer calls directly. This types
|
|
5
|
+
// what a flat config actually touches. Per-rule option types remain available
|
|
6
|
+
// from the "./types" subpath export where a plugin provides one.
|
|
7
|
+
import type { Linter, Rule } from 'eslint';
|
|
8
|
+
|
|
9
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
10
|
+
export declare const configs: Record<string, Linter.Config>;
|
|
11
|
+
export declare const plugin: {
|
|
12
|
+
meta: { name: string; version: string };
|
|
13
|
+
rules: Record<string, Rule.RuleModule>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare const _default: typeof plugin;
|
|
17
|
+
export default _default;
|
package/src/index.js
CHANGED
|
@@ -1,26 +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.configs = exports.plugin = exports.rules = void 0;
|
|
9
|
-
/**
|
|
10
|
-
* eslint-plugin-secure-coding
|
|
11
|
-
*
|
|
12
|
-
* A comprehensive security-focused ESLint plugin restricted to "pure coding security rules"
|
|
13
|
-
* (logic, AST patterns, and generic vulnerabilities independent of environment).
|
|
14
|
-
*
|
|
15
|
-
* Rules focus on:
|
|
16
|
-
* - Language-level logic flaws
|
|
17
|
-
* - AST pattern risks
|
|
18
|
-
* - Generic injection patterns
|
|
19
|
-
* - Cryptographic logic (logic level)
|
|
20
|
-
*
|
|
21
|
-
* @see https://github.com/ofri-peretz/eslint#readme
|
|
22
|
-
*/
|
|
23
|
-
// Security rules - Injection
|
|
24
4
|
const no_graphql_injection_1 = require("./rules/no-graphql-injection");
|
|
25
5
|
const no_xxe_injection_1 = require("./rules/no-xxe-injection");
|
|
26
6
|
const no_xpath_injection_1 = require("./rules/no-xpath-injection");
|
|
@@ -28,40 +8,28 @@ const no_ldap_injection_1 = require("./rules/no-ldap-injection");
|
|
|
28
8
|
const no_directive_injection_1 = require("./rules/no-directive-injection");
|
|
29
9
|
const no_format_string_injection_1 = require("./rules/no-format-string-injection");
|
|
30
10
|
const no_template_injection_1 = require("./rules/no-template-injection");
|
|
31
|
-
// Security rules - Regex
|
|
32
11
|
const detect_non_literal_regexp_1 = require("./rules/detect-non-literal-regexp");
|
|
33
12
|
const no_redos_vulnerable_regex_1 = require("./rules/no-redos-vulnerable-regex");
|
|
34
13
|
const no_unsafe_regex_construction_1 = require("./rules/no-unsafe-regex-construction");
|
|
35
|
-
// Security rules - Object & Prototype
|
|
36
14
|
const detect_object_injection_1 = require("./rules/detect-object-injection");
|
|
37
15
|
const no_unsafe_deserialization_1 = require("./rules/no-unsafe-deserialization");
|
|
38
|
-
// Security rules - Credentials & Crypto
|
|
39
16
|
const no_hardcoded_credentials_1 = require("./rules/no-hardcoded-credentials");
|
|
40
17
|
const no_insecure_comparison_1 = require("./rules/no-insecure-comparison");
|
|
41
|
-
// Security rules - Input Validation
|
|
42
18
|
const no_improper_sanitization_1 = require("./rules/no-improper-sanitization");
|
|
43
19
|
const no_improper_type_validation_1 = require("./rules/no-improper-type-validation");
|
|
44
|
-
// Security rules - Authentication & Authorization
|
|
45
20
|
const no_missing_authentication_1 = require("./rules/no-missing-authentication");
|
|
46
21
|
const no_privilege_escalation_1 = require("./rules/no-privilege-escalation");
|
|
47
22
|
const no_weak_password_recovery_1 = require("./rules/no-weak-password-recovery");
|
|
48
23
|
const require_backend_authorization_1 = require("./rules/require-backend-authorization");
|
|
49
|
-
// Security rules - Data Exposure
|
|
50
24
|
const no_sensitive_data_exposure_1 = require("./rules/no-sensitive-data-exposure");
|
|
51
25
|
const no_pii_in_logs_1 = require("./rules/no-pii-in-logs");
|
|
52
|
-
// Security rules - Resource & DoS
|
|
53
26
|
const no_unlimited_resource_allocation_1 = require("./rules/no-unlimited-resource-allocation");
|
|
54
27
|
const no_unchecked_loop_condition_1 = require("./rules/no-unchecked-loop-condition");
|
|
55
|
-
// Security rules - Auth & runtime hardening (wired 2026-05-09 — implementations existed but were unregistered)
|
|
56
28
|
const detect_weak_password_validation_1 = require("./rules/detect-weak-password-validation");
|
|
57
29
|
const no_electron_security_issues_1 = require("./rules/no-electron-security-issues");
|
|
58
30
|
const no_hardcoded_session_tokens_1 = require("./rules/no-hardcoded-session-tokens");
|
|
59
31
|
const require_secure_defaults_1 = require("./rules/require-secure-defaults");
|
|
60
|
-
/**
|
|
61
|
-
* Collection of all core security ESLint rules
|
|
62
|
-
*/
|
|
63
32
|
exports.rules = {
|
|
64
|
-
// Fundamental Injection (6 rules)
|
|
65
33
|
'no-graphql-injection': no_graphql_injection_1.noGraphqlInjection,
|
|
66
34
|
'no-xxe-injection': no_xxe_injection_1.noXxeInjection,
|
|
67
35
|
'no-xpath-injection': no_xpath_injection_1.noXpathInjection,
|
|
@@ -69,111 +37,55 @@ exports.rules = {
|
|
|
69
37
|
'no-directive-injection': no_directive_injection_1.noDirectiveInjection,
|
|
70
38
|
'no-format-string-injection': no_format_string_injection_1.noFormatStringInjection,
|
|
71
39
|
'no-template-injection': no_template_injection_1.noTemplateInjection,
|
|
72
|
-
// Regex Safety & Stability (3 rules)
|
|
73
40
|
'detect-non-literal-regexp': detect_non_literal_regexp_1.detectNonLiteralRegexp,
|
|
74
41
|
'no-redos-vulnerable-regex': no_redos_vulnerable_regex_1.noRedosVulnerableRegex,
|
|
75
42
|
'no-unsafe-regex-construction': no_unsafe_regex_construction_1.noUnsafeRegexConstruction,
|
|
76
|
-
// Data & Logic Integrity (5 rules)
|
|
77
43
|
'detect-object-injection': detect_object_injection_1.detectObjectInjection,
|
|
78
44
|
'no-unsafe-deserialization': no_unsafe_deserialization_1.noUnsafeDeserialization,
|
|
79
45
|
'no-insecure-comparison': no_insecure_comparison_1.noInsecureComparison,
|
|
80
46
|
'no-improper-sanitization': no_improper_sanitization_1.noImproperSanitization,
|
|
81
47
|
'no-improper-type-validation': no_improper_type_validation_1.noImproperTypeValidation,
|
|
82
|
-
// Auth/Access Logic (4 rules)
|
|
83
48
|
'no-missing-authentication': no_missing_authentication_1.noMissingAuthentication,
|
|
84
49
|
'no-privilege-escalation': no_privilege_escalation_1.noPrivilegeEscalation,
|
|
85
50
|
'no-weak-password-recovery': no_weak_password_recovery_1.noWeakPasswordRecovery,
|
|
86
51
|
'require-backend-authorization': require_backend_authorization_1.requireBackendAuthorization,
|
|
87
|
-
// Secrets & Exposure (3 rules)
|
|
88
52
|
'no-hardcoded-credentials': no_hardcoded_credentials_1.noHardcodedCredentials,
|
|
89
53
|
'no-sensitive-data-exposure': no_sensitive_data_exposure_1.noSensitiveDataExposure,
|
|
90
54
|
'no-pii-in-logs': no_pii_in_logs_1.noPiiInLogs,
|
|
91
|
-
// Resource Handling (2 rules)
|
|
92
55
|
'no-unlimited-resource-allocation': no_unlimited_resource_allocation_1.noUnlimitedResourceAllocation,
|
|
93
56
|
'no-unchecked-loop-condition': no_unchecked_loop_condition_1.noUncheckedLoopCondition,
|
|
94
|
-
// Auth & runtime hardening (4 rules — wired 2026-05-09)
|
|
95
57
|
'detect-weak-password-validation': detect_weak_password_validation_1.detectWeakPasswordValidation,
|
|
96
58
|
'no-electron-security-issues': no_electron_security_issues_1.noElectronSecurityIssues,
|
|
97
59
|
'no-hardcoded-session-tokens': no_hardcoded_session_tokens_1.noHardcodedSessionTokens,
|
|
98
60
|
'require-secure-defaults': require_secure_defaults_1.requireSecureDefaults,
|
|
99
61
|
};
|
|
100
|
-
/**
|
|
101
|
-
* ESLint Plugin object
|
|
102
|
-
*/
|
|
103
62
|
exports.plugin = {
|
|
104
63
|
meta: {
|
|
105
64
|
name: 'eslint-plugin-secure-coding',
|
|
106
|
-
version: '3.4.
|
|
65
|
+
version: '3.4.1',
|
|
107
66
|
},
|
|
108
67
|
rules: exports.rules,
|
|
109
68
|
};
|
|
110
|
-
/**
|
|
111
|
-
* Preset configurations for security rules
|
|
112
|
-
*/
|
|
113
69
|
const recommendedRules = {
|
|
114
|
-
// Critical - Injection vulnerabilities
|
|
115
|
-
// no-graphql-injection demoted to 'warn' 2026-05-09 — `npm run ilb:severity-audit`
|
|
116
|
-
// showed 61% of Wild hits on adversarial Edge code. Fails the README §1
|
|
117
|
-
// ≥ 95% precision floor for `error`-tier severity.
|
|
118
70
|
'secure-coding/no-graphql-injection': 'warn',
|
|
119
71
|
'secure-coding/no-xxe-injection': 'error',
|
|
120
72
|
'secure-coding/no-xpath-injection': 'error',
|
|
121
73
|
'secure-coding/no-ldap-injection': 'error',
|
|
122
|
-
// Critical - Deserialization
|
|
123
|
-
// Demoted 2026-05-09 — 76% Edge ratio.
|
|
124
74
|
'secure-coding/no-unsafe-deserialization': 'warn',
|
|
125
|
-
// High - Regex vulnerabilities
|
|
126
75
|
'secure-coding/detect-non-literal-regexp': 'warn',
|
|
127
|
-
// Demoted 2026-05-09 — 91% Edge ratio.
|
|
128
76
|
'secure-coding/no-redos-vulnerable-regex': 'error',
|
|
129
77
|
'secure-coding/no-unsafe-regex-construction': 'error',
|
|
130
|
-
// High - Prototype pollution
|
|
131
78
|
'secure-coding/detect-object-injection': 'warn',
|
|
132
|
-
// Critical - Credentials
|
|
133
79
|
'secure-coding/no-hardcoded-credentials': 'error',
|
|
134
|
-
// NOTE: `no-insecure-comparison` is intentionally NOT in `recommended`
|
|
135
|
-
// (removed 2026-07-31). It is `deprecated` in favour of
|
|
136
|
-
// `node-security/no-timing-unsafe-compare`, and what it actually reports on
|
|
137
|
-
// ordinary code is every `==` / `!=` — 876 findings on a 1,470-file corpus
|
|
138
|
-
// (webpack, lodash, eslint-plugin-import, two NestJS boilerplates), 100% of
|
|
139
|
-
// them already covered by core `eqeqeq`. Re-reporting another rule's
|
|
140
|
-
// findings under a CWE-697 security banner is noise, not signal, and no
|
|
141
|
-
// narrowing fixes that: the loose-equality half of this rule is a style
|
|
142
|
-
// check wearing a security hat.
|
|
143
|
-
//
|
|
144
|
-
// The timing-attack half (a secret compared with `===`) is the part worth
|
|
145
|
-
// keeping, and `node-security/no-timing-unsafe-compare` is where it lives —
|
|
146
|
-
// in that plugin's `recommended` preset since 2026-08-02, so consumers on
|
|
147
|
-
// presets keep CWE-697 coverage. It does mean the coverage now lives in a
|
|
148
|
-
// different package: a project that installs only `eslint-plugin-secure-coding`
|
|
149
|
-
// needs `eslint-plugin-node-security` as well to keep it.
|
|
150
|
-
// The rule remains exported and available via `strict` / explicit opt-in.
|
|
151
|
-
// Critical - Template injection
|
|
152
80
|
'secure-coding/no-template-injection': 'error',
|
|
153
|
-
// Critical - Data integrity
|
|
154
81
|
'secure-coding/no-improper-sanitization': 'error',
|
|
155
|
-
// High - Logic
|
|
156
|
-
// NOTE: no-missing-authentication and require-backend-authorization are deprecated in
|
|
157
|
-
// secure-coding — they assume Express route handler context and belong in express-security.
|
|
158
|
-
// Kept in the rules registry for backwards compat; removed from flagship config.
|
|
159
82
|
'secure-coding/no-privilege-escalation': 'warn',
|
|
160
|
-
'secure-coding/no-weak-password-recovery': 'warn',
|
|
161
|
-
// High - Exposure
|
|
83
|
+
'secure-coding/no-weak-password-recovery': 'warn',
|
|
162
84
|
'secure-coding/no-sensitive-data-exposure': 'warn',
|
|
163
|
-
// Medium - Resource & DoS
|
|
164
|
-
// Demoted 2026-05-09 — both rules fail the volume-error-risk gate
|
|
165
|
-
// (firing ≥ 100 times on Wild without sufficient fixture coverage to
|
|
166
|
-
// guarantee precision). Rules were also flagged for ≥ 76% Edge ratio.
|
|
167
85
|
'secure-coding/no-unlimited-resource-allocation': 'warn',
|
|
168
86
|
'secure-coding/no-unchecked-loop-condition': 'warn',
|
|
169
87
|
};
|
|
170
88
|
exports.configs = {
|
|
171
|
-
/**
|
|
172
|
-
* Flagship preset — the two rules from this plugin in the ecosystem-wide
|
|
173
|
-
* flagship list (`.agent/flagship-rules.md`). Use this when you want the
|
|
174
|
-
* highest-signal security subset shippable in CI gates without the noise
|
|
175
|
-
* of `recommended`.
|
|
176
|
-
*/
|
|
177
89
|
flagship: {
|
|
178
90
|
plugins: {
|
|
179
91
|
'secure-coding': exports.plugin,
|
|
@@ -183,81 +95,40 @@ exports.configs = {
|
|
|
183
95
|
'secure-coding/no-redos-vulnerable-regex': 'error',
|
|
184
96
|
},
|
|
185
97
|
},
|
|
186
|
-
/**
|
|
187
|
-
* Recommended security configuration
|
|
188
|
-
*
|
|
189
|
-
* Enables all core security rules with sensible severity levels.
|
|
190
|
-
*/
|
|
191
98
|
recommended: {
|
|
192
99
|
plugins: {
|
|
193
100
|
'secure-coding': exports.plugin,
|
|
194
101
|
},
|
|
195
102
|
rules: recommendedRules,
|
|
196
103
|
},
|
|
197
|
-
/**
|
|
198
|
-
* Recommended-strict configuration
|
|
199
|
-
*
|
|
200
|
-
* Same rule set as `recommended` but every rule is promoted to `'error'`.
|
|
201
|
-
* Use this when you want CI to block on all security findings rather than
|
|
202
|
-
* only warning on lower-confidence rules.
|
|
203
|
-
*
|
|
204
|
-
* This is the configuration independently chosen by production teams who
|
|
205
|
-
* audit `recommended` and decide they want zero tolerance on all 16 rules.
|
|
206
|
-
*/
|
|
207
104
|
'recommended-strict': {
|
|
208
105
|
plugins: {
|
|
209
106
|
'secure-coding': exports.plugin,
|
|
210
107
|
},
|
|
211
108
|
rules: Object.fromEntries(Object.keys(recommendedRules).map((rule) => [rule, 'error'])),
|
|
212
109
|
},
|
|
213
|
-
/**
|
|
214
|
-
* Strict security configuration
|
|
215
|
-
*
|
|
216
|
-
* ALL rules (including experimental and opinionated ones) set to 'error'.
|
|
217
|
-
* Prefer `recommended-strict` unless you specifically need full coverage.
|
|
218
|
-
*/
|
|
219
110
|
strict: {
|
|
220
111
|
plugins: {
|
|
221
112
|
'secure-coding': exports.plugin,
|
|
222
113
|
},
|
|
223
114
|
rules: Object.fromEntries(Object.keys(exports.rules).map(ruleName => [`secure-coding/${ruleName}`, 'error'])),
|
|
224
115
|
},
|
|
225
|
-
/**
|
|
226
|
-
* OWASP Top 10 focused configuration
|
|
227
|
-
*
|
|
228
|
-
* Rules mapped to OWASP Top 10 2021 categories.
|
|
229
|
-
*/
|
|
230
116
|
'owasp-top-10': {
|
|
231
117
|
plugins: {
|
|
232
118
|
'secure-coding': exports.plugin,
|
|
233
119
|
},
|
|
234
120
|
rules: {
|
|
235
|
-
// A01:2021 – Broken Access Control
|
|
236
|
-
// no-missing-authentication removed: Express-specific, use express-security plugin instead
|
|
237
121
|
'secure-coding/no-privilege-escalation': 'warn',
|
|
238
|
-
// A02:2021 – Cryptographic Failures
|
|
239
122
|
'secure-coding/no-hardcoded-credentials': 'error',
|
|
240
|
-
// Demoted from 'error': naming-heuristic detection (fires on variable names
|
|
241
|
-
// that sound sensitive). Cannot be enforcement-grade per I3 invariant.
|
|
242
123
|
'secure-coding/no-sensitive-data-exposure': 'warn',
|
|
243
|
-
// A03:2021 – Injection
|
|
244
124
|
'secure-coding/no-graphql-injection': 'error',
|
|
245
125
|
'secure-coding/no-xxe-injection': 'error',
|
|
246
126
|
'secure-coding/no-xpath-injection': 'error',
|
|
247
127
|
'secure-coding/no-ldap-injection': 'error',
|
|
248
|
-
// A04:2021 – Insecure Design
|
|
249
128
|
'secure-coding/no-weak-password-recovery': 'error',
|
|
250
129
|
'secure-coding/no-improper-type-validation': 'error',
|
|
251
|
-
// A07:2021 – Identification and Authentication Failures
|
|
252
|
-
// no-insecure-comparison removed for the same reason as in
|
|
253
|
-
// `recommended`: it re-reports `eqeqeq` under a security banner. Use
|
|
254
|
-
// `node-security/no-timing-unsafe-compare` for the timing-attack half.
|
|
255
|
-
// A08:2021 – Software and Data Integrity Failures
|
|
256
130
|
'secure-coding/no-unsafe-deserialization': 'error',
|
|
257
131
|
},
|
|
258
132
|
},
|
|
259
133
|
};
|
|
260
|
-
/**
|
|
261
|
-
* Default export for ESLint plugin
|
|
262
|
-
*/
|
|
263
134
|
exports.default = exports.plugin;
|
package/src/oxlint.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
import { plugin } from './index';
|
|
20
|
-
export = plugin;
|
|
1
|
+
// Minimal declaration written by scripts/build-package.ts.
|
|
2
|
+
//
|
|
3
|
+
// tsc's generated entry declaration inlined every inferred rule-option type
|
|
4
|
+
// (up to 166 kB per plugin) for an API no consumer calls directly. This types
|
|
5
|
+
// what a flat config actually touches. Per-rule option types remain available
|
|
6
|
+
// from the "./types" subpath export where a plugin provides one.
|
|
7
|
+
import type { Linter, Rule } from 'eslint';
|
|
8
|
+
|
|
9
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
10
|
+
export declare const configs: Record<string, Linter.Config>;
|
|
11
|
+
export declare const plugin: {
|
|
12
|
+
meta: { name: string; version: string };
|
|
13
|
+
rules: Record<string, Rule.RuleModule>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare const _default: typeof plugin;
|
|
17
|
+
export default _default;
|
package/src/oxlint.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
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
|
-
/**
|
|
8
|
-
* oxlint sub-export.
|
|
9
|
-
*
|
|
10
|
-
* Consumers wire oxlint to this entry via:
|
|
11
|
-
* { "jsPlugins": ["eslint-plugin-secure-coding/oxlint"] }
|
|
12
|
-
*
|
|
13
|
-
* oxlint's JS plugin loader does `require('eslint-plugin-secure-coding/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
2
|
const index_1 = require("./index");
|
|
21
3
|
module.exports = index_1.plugin;
|
|
@@ -1,14 +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.detectNonLiteralRegexp = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
// Type guard for regex literal nodes
|
|
12
6
|
const isRegExpLiteral = (node) => {
|
|
13
7
|
return node.type === 'Literal' && Object.prototype.hasOwnProperty.call(node, 'regex');
|
|
14
8
|
};
|
|
@@ -32,7 +26,6 @@ const REGEXP_PATTERNS = [
|
|
|
32
26
|
safeAlternative: 'Static RegExp literals or validated patterns',
|
|
33
27
|
example: {
|
|
34
28
|
bad: 'RegExp(userPattern)',
|
|
35
|
-
// oxlint-disable-next-line no-template-curly-in-string
|
|
36
29
|
good: 'const safePattern = userPattern.replace(/[.*+?^${}()|[\\]\\\\]/g, \'\\\\$&\'); new RegExp(`^${safePattern}$`)'
|
|
37
30
|
},
|
|
38
31
|
effort: '15-20 minutes',
|
|
@@ -44,8 +37,8 @@ const REGEXP_PATTERNS = [
|
|
|
44
37
|
vulnerability: 'redos',
|
|
45
38
|
safeAlternative: 'Avoid nested quantifiers, use atomic groups',
|
|
46
39
|
example: {
|
|
47
|
-
bad: '/(a+)+b/',
|
|
48
|
-
good: '/(?>a+)b/',
|
|
40
|
+
bad: '/(a+)+b/',
|
|
41
|
+
good: '/(?>a+)b/',
|
|
49
42
|
},
|
|
50
43
|
effort: '20-30 minutes',
|
|
51
44
|
riskLevel: 'critical'
|
|
@@ -61,7 +54,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
61
54
|
cwe: 'CWE-400',
|
|
62
55
|
},
|
|
63
56
|
messages: {
|
|
64
|
-
// 🎯 Token optimization: 41% reduction (51→30 tokens) - compact template variables
|
|
65
57
|
regexpReDoS: (0, eslint_devkit_1.formatLLMMessage)({
|
|
66
58
|
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
67
59
|
issueName: 'ReDoS vulnerability',
|
|
@@ -107,9 +99,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
107
99
|
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
108
100
|
issueName: 'Escape Input',
|
|
109
101
|
description: 'Escape special regex characters',
|
|
110
|
-
// oxlint-disable-next-line no-template-curly-in-string
|
|
111
102
|
severity: 'LOW',
|
|
112
|
-
// oxlint-disable-next-line no-template-curly-in-string
|
|
113
103
|
fix: 'input.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")',
|
|
114
104
|
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping',
|
|
115
105
|
})
|
|
@@ -149,35 +139,20 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
149
139
|
],
|
|
150
140
|
create(context) {
|
|
151
141
|
const options = context.options[0] || {};
|
|
152
|
-
// `options` is always an object here (defaulted just above), so a
|
|
153
|
-
// second `|| {}` fallback could never fire — removed as dead code.
|
|
154
142
|
const { allowLiterals = false, maxPatternLength = 100, } = options;
|
|
155
|
-
/**
|
|
156
|
-
* Check if a node is a literal string (potentially safe)
|
|
157
|
-
* Includes template literals without expressions
|
|
158
|
-
*/
|
|
159
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
160
143
|
const isLiteralString = (node) => {
|
|
161
144
|
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
162
145
|
return true;
|
|
163
146
|
}
|
|
164
|
-
// Template literals without expressions are also static/safe
|
|
165
147
|
if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {
|
|
166
148
|
return true;
|
|
167
149
|
}
|
|
168
150
|
return false;
|
|
169
151
|
};
|
|
170
|
-
/**
|
|
171
|
-
* Check if a regex pattern contains dangerous ReDoS patterns
|
|
172
|
-
* Only flag truly dangerous patterns like nested quantifiers: (a+)+, (a*)*
|
|
173
|
-
*/
|
|
174
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
175
152
|
const hasReDoSPatterns = (pattern) => {
|
|
176
|
-
// Detect truly dangerous nested quantifier patterns that cause exponential backtracking
|
|
177
|
-
// Pattern like (a+)+, (a*)+, (a+)*, (a*)*, ([a-z]+)+
|
|
178
153
|
const nestedQuantifierPatterns = [
|
|
179
|
-
/\([^)]*[+*]\)[+*]/,
|
|
180
|
-
/\([^)]*[+*]\)\{[0-9,]+\}/,
|
|
154
|
+
/\([^)]*[+*]\)[+*]/,
|
|
155
|
+
/\([^)]*[+*]\)\{[0-9,]+\}/,
|
|
181
156
|
];
|
|
182
157
|
for (const dangerousPattern of nestedQuantifierPatterns) {
|
|
183
158
|
if (dangerousPattern.test(pattern)) {
|
|
@@ -186,17 +161,12 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
186
161
|
}
|
|
187
162
|
return false;
|
|
188
163
|
};
|
|
189
|
-
/**
|
|
190
|
-
* Extract regex pattern from RegExp construction
|
|
191
|
-
*/
|
|
192
164
|
const extractPattern = (node) => {
|
|
193
165
|
const sourceCode = context.sourceCode;
|
|
194
|
-
// Determine constructor type
|
|
195
166
|
let constructor = 'RegExp';
|
|
196
167
|
if (node.type === 'NewExpression' && node.callee.type === 'Identifier') {
|
|
197
168
|
constructor = `new ${node.callee.name}`;
|
|
198
169
|
}
|
|
199
|
-
// First argument is the pattern
|
|
200
170
|
const patternNode = node.arguments.length > 0 ? node.arguments[0] : null;
|
|
201
171
|
const pattern = patternNode ? sourceCode.getText(patternNode) : '';
|
|
202
172
|
const isDynamic = patternNode ? !isLiteralString(patternNode) : false;
|
|
@@ -204,18 +174,13 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
204
174
|
String(patternNode.value).length : pattern.length;
|
|
205
175
|
return { pattern, patternNode, constructor, isDynamic, length };
|
|
206
176
|
};
|
|
207
|
-
/**
|
|
208
|
-
* Detect the specific vulnerability pattern
|
|
209
|
-
*/
|
|
210
177
|
const detectVulnerability = (pattern, isDynamic) => {
|
|
211
|
-
// Check for dynamic construction first (highest risk)
|
|
212
178
|
if (isDynamic) {
|
|
213
179
|
for (const vuln of REGEXP_PATTERNS) {
|
|
214
180
|
if (new RegExp(vuln.pattern, 'i').test(pattern)) {
|
|
215
181
|
return vuln;
|
|
216
182
|
}
|
|
217
183
|
}
|
|
218
|
-
// Generic dynamic RegExp construction
|
|
219
184
|
return {
|
|
220
185
|
pattern: 'dynamic',
|
|
221
186
|
dangerous: true,
|
|
@@ -229,7 +194,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
229
194
|
riskLevel: 'high'
|
|
230
195
|
};
|
|
231
196
|
}
|
|
232
|
-
// Check for ReDoS patterns in literal regex
|
|
233
197
|
if (hasReDoSPatterns(pattern)) {
|
|
234
198
|
return {
|
|
235
199
|
pattern: 'redos-literal',
|
|
@@ -238,7 +202,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
238
202
|
safeAlternative: 'Restructure regex to avoid nested quantifiers',
|
|
239
203
|
example: {
|
|
240
204
|
bad: pattern,
|
|
241
|
-
good: pattern.replace(/(a+)\+/g, '$1')
|
|
205
|
+
good: pattern.replace(/(a+)\+/g, '$1')
|
|
242
206
|
},
|
|
243
207
|
effort: '20-30 minutes',
|
|
244
208
|
riskLevel: 'high'
|
|
@@ -246,10 +210,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
246
210
|
}
|
|
247
211
|
return null;
|
|
248
212
|
};
|
|
249
|
-
/**
|
|
250
|
-
* Generate refactoring steps based on the vulnerability
|
|
251
|
-
*/
|
|
252
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
253
213
|
const generateRefactoringSteps = (vulnerability) => {
|
|
254
214
|
if (vulnerability.pattern === 'dynamic') {
|
|
255
215
|
return [
|
|
@@ -269,12 +229,6 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
269
229
|
' 5. Consider alternatives like string methods'
|
|
270
230
|
].join('\n');
|
|
271
231
|
}
|
|
272
|
-
// Every `RegExpPattern` constructed in this module has
|
|
273
|
-
// `vulnerability: 'redos'` (see REGEXP_PATTERNS above and the two
|
|
274
|
-
// object literals returned from `detectVulnerability`) — there is no
|
|
275
|
-
// code path that ever produces `'injection'` or another value, so
|
|
276
|
-
// this is the only reachable case. Kept as a direct return (not a
|
|
277
|
-
// switch) to avoid unreachable branches that no test could ever hit.
|
|
278
232
|
return [
|
|
279
233
|
' 1. Avoid nested quantifiers and backreferences',
|
|
280
234
|
' 2. Use possessive quantifiers: *+, ++, ?+',
|
|
@@ -283,44 +237,25 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
283
237
|
' 5. Consider safe-regex library validation'
|
|
284
238
|
].join('\n');
|
|
285
239
|
};
|
|
286
|
-
/**
|
|
287
|
-
* Determine overall risk level
|
|
288
|
-
*/
|
|
289
|
-
// Every `RegExpPattern` ever constructed in this module (REGEXP_PATTERNS
|
|
290
|
-
// entries, and the two object literals in `detectVulnerability`) sets
|
|
291
|
-
// `riskLevel` to only `'high'` or `'critical'` — never `'medium'` or
|
|
292
|
-
// `'low'` — so those two branches are the only reachable outcomes.
|
|
293
240
|
const determineRiskLevel = (vulnerability, pattern) => {
|
|
294
241
|
if (vulnerability.riskLevel === 'critical' || hasReDoSPatterns(pattern)) {
|
|
295
242
|
return 'CRITICAL';
|
|
296
243
|
}
|
|
297
244
|
return 'HIGH';
|
|
298
245
|
};
|
|
299
|
-
/**
|
|
300
|
-
* Check RegExp constructor calls for vulnerabilities
|
|
301
|
-
*/
|
|
302
246
|
const checkRegExpCall = (node) => {
|
|
303
|
-
// Check for RegExp constructor calls
|
|
304
247
|
const isRegExpCall = node.callee.type === 'Identifier' && node.callee.name === 'RegExp';
|
|
305
248
|
const isNewRegExp = node.type === 'NewExpression' && node.callee.type === 'Identifier' && node.callee.name === 'RegExp';
|
|
306
249
|
if (!isRegExpCall && !isNewRegExp) {
|
|
307
250
|
return;
|
|
308
251
|
}
|
|
309
252
|
const { pattern, patternNode, isDynamic, length } = extractPattern(node);
|
|
310
|
-
// Allow literals if configured and pattern is reasonable length
|
|
311
253
|
if (allowLiterals && patternNode && isLiteralString(patternNode) && length <= maxPatternLength) {
|
|
312
|
-
// Still check for ReDoS patterns even in literals
|
|
313
254
|
if (!hasReDoSPatterns(pattern)) {
|
|
314
255
|
return;
|
|
315
256
|
}
|
|
316
257
|
}
|
|
317
258
|
const vulnerability = detectVulnerability(pattern, isDynamic);
|
|
318
|
-
// `detectVulnerability` always returns non-null when `isDynamic` is
|
|
319
|
-
// true (either a matched REGEXP_PATTERNS entry or its own generic
|
|
320
|
-
// "dynamic" object), so `vulnerability` can only be null when
|
|
321
|
-
// `isDynamic` is false — meaning a synthetic `isDynamic ? {...} :
|
|
322
|
-
// null` fallback here could never construct the object literal it
|
|
323
|
-
// used to; it always reduced to `null`. Removed as dead code.
|
|
324
259
|
const effectiveVulnerability = vulnerability;
|
|
325
260
|
if (!effectiveVulnerability) {
|
|
326
261
|
return;
|
|
@@ -362,20 +297,11 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
362
297
|
]
|
|
363
298
|
});
|
|
364
299
|
};
|
|
365
|
-
/**
|
|
366
|
-
* Check literal regex patterns for ReDoS vulnerabilities
|
|
367
|
-
*/
|
|
368
300
|
const checkLiteralRegExp = (node) => {
|
|
369
301
|
if (!isRegExpLiteral(node)) {
|
|
370
302
|
return;
|
|
371
303
|
}
|
|
372
304
|
const pattern = node.regex.pattern;
|
|
373
|
-
// Check for ReDoS patterns. `detectVulnerability(pattern, false)`
|
|
374
|
-
// re-tests the identical `hasReDoSPatterns(pattern)` condition just
|
|
375
|
-
// checked above (see its `isDynamic === false` branch) and always
|
|
376
|
-
// returns non-null when that's true — so `vulnerability` here can
|
|
377
|
-
// never be null. No `if (vulnerability)` guard, to avoid an
|
|
378
|
-
// unreachable false branch.
|
|
379
305
|
if (hasReDoSPatterns(pattern)) {
|
|
380
306
|
const vulnerability = detectVulnerability(pattern, false);
|
|
381
307
|
const riskLevel = determineRiskLevel(vulnerability, pattern);
|