eslint-plugin-secure-coding 3.1.3 → 3.3.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +128 -65
  3. package/package.json +23 -4
  4. package/src/index.js +70 -12
  5. package/src/oxlint.d.ts +20 -0
  6. package/src/oxlint.js +21 -0
  7. package/src/rules/detect-non-literal-regexp/index.js +9 -1
  8. package/src/rules/detect-object-injection/index.js +344 -6
  9. package/src/rules/detect-weak-password-validation/index.js +4 -1
  10. package/src/rules/no-directive-injection/index.js +7 -4
  11. package/src/rules/no-electron-security-issues/index.js +6 -2
  12. package/src/rules/no-format-string-injection/index.js +32 -23
  13. package/src/rules/no-graphql-injection/index.js +8 -3
  14. package/src/rules/no-hardcoded-credentials/index.js +366 -52
  15. package/src/rules/no-hardcoded-session-tokens/index.js +3 -0
  16. package/src/rules/no-improper-sanitization/index.js +31 -4
  17. package/src/rules/no-improper-type-validation/index.js +6 -4
  18. package/src/rules/no-insecure-comparison/index.js +39 -3
  19. package/src/rules/no-ldap-injection/index.js +6 -3
  20. package/src/rules/no-missing-authentication/index.js +5 -2
  21. package/src/rules/no-pii-in-logs/index.js +4 -1
  22. package/src/rules/no-privilege-escalation/index.js +5 -2
  23. package/src/rules/no-redos-vulnerable-regex/index.js +79 -0
  24. package/src/rules/no-sensitive-data-exposure/index.js +4 -1
  25. package/src/rules/no-template-injection/index.d.ts +23 -0
  26. package/src/rules/no-template-injection/index.js +90 -0
  27. package/src/rules/no-unchecked-loop-condition/index.js +5 -3
  28. package/src/rules/no-unlimited-resource-allocation/index.js +46 -30
  29. package/src/rules/no-unsafe-deserialization/index.js +22 -5
  30. package/src/rules/no-unsafe-regex-construction/index.js +10 -3
  31. package/src/rules/no-weak-password-recovery/index.js +5 -3
  32. package/src/rules/no-xpath-injection/index.js +6 -3
  33. package/src/rules/no-xxe-injection/index.js +48 -46
  34. package/src/rules/require-backend-authorization/index.js +6 -3
  35. package/src/rules/require-secure-defaults/index.js +3 -0
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ const no_xpath_injection_1 = require("./rules/no-xpath-injection");
27
27
  const no_ldap_injection_1 = require("./rules/no-ldap-injection");
28
28
  const no_directive_injection_1 = require("./rules/no-directive-injection");
29
29
  const no_format_string_injection_1 = require("./rules/no-format-string-injection");
30
+ const no_template_injection_1 = require("./rules/no-template-injection");
30
31
  // Security rules - Regex
31
32
  const detect_non_literal_regexp_1 = require("./rules/detect-non-literal-regexp");
32
33
  const no_redos_vulnerable_regex_1 = require("./rules/no-redos-vulnerable-regex");
@@ -51,6 +52,11 @@ const no_pii_in_logs_1 = require("./rules/no-pii-in-logs");
51
52
  // Security rules - Resource & DoS
52
53
  const no_unlimited_resource_allocation_1 = require("./rules/no-unlimited-resource-allocation");
53
54
  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
+ const detect_weak_password_validation_1 = require("./rules/detect-weak-password-validation");
57
+ const no_electron_security_issues_1 = require("./rules/no-electron-security-issues");
58
+ const no_hardcoded_session_tokens_1 = require("./rules/no-hardcoded-session-tokens");
59
+ const require_secure_defaults_1 = require("./rules/require-secure-defaults");
54
60
  /**
55
61
  * Collection of all core security ESLint rules
56
62
  */
@@ -62,6 +68,7 @@ exports.rules = {
62
68
  'no-ldap-injection': no_ldap_injection_1.noLdapInjection,
63
69
  'no-directive-injection': no_directive_injection_1.noDirectiveInjection,
64
70
  'no-format-string-injection': no_format_string_injection_1.noFormatStringInjection,
71
+ 'no-template-injection': no_template_injection_1.noTemplateInjection,
65
72
  // Regex Safety & Stability (3 rules)
66
73
  'detect-non-literal-regexp': detect_non_literal_regexp_1.detectNonLiteralRegexp,
67
74
  'no-redos-vulnerable-regex': no_redos_vulnerable_regex_1.noRedosVulnerableRegex,
@@ -84,6 +91,11 @@ exports.rules = {
84
91
  // Resource Handling (2 rules)
85
92
  'no-unlimited-resource-allocation': no_unlimited_resource_allocation_1.noUnlimitedResourceAllocation,
86
93
  'no-unchecked-loop-condition': no_unchecked_loop_condition_1.noUncheckedLoopCondition,
94
+ // Auth & runtime hardening (4 rules — wired 2026-05-09)
95
+ 'detect-weak-password-validation': detect_weak_password_validation_1.detectWeakPasswordValidation,
96
+ 'no-electron-security-issues': no_electron_security_issues_1.noElectronSecurityIssues,
97
+ 'no-hardcoded-session-tokens': no_hardcoded_session_tokens_1.noHardcodedSessionTokens,
98
+ 'require-secure-defaults': require_secure_defaults_1.requireSecureDefaults,
87
99
  };
88
100
  /**
89
101
  * ESLint Plugin object
@@ -91,7 +103,7 @@ exports.rules = {
91
103
  exports.plugin = {
92
104
  meta: {
93
105
  name: 'eslint-plugin-secure-coding',
94
- version: '1.1.0',
106
+ version: '3.3.0',
95
107
  },
96
108
  rules: exports.rules,
97
109
  };
@@ -100,34 +112,61 @@ exports.plugin = {
100
112
  */
101
113
  const recommendedRules = {
102
114
  // Critical - Injection vulnerabilities
103
- 'secure-coding/no-graphql-injection': 'error',
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
+ 'secure-coding/no-graphql-injection': 'warn',
104
119
  'secure-coding/no-xxe-injection': 'error',
105
120
  'secure-coding/no-xpath-injection': 'error',
106
121
  'secure-coding/no-ldap-injection': 'error',
107
122
  // Critical - Deserialization
108
- 'secure-coding/no-unsafe-deserialization': 'error',
123
+ // Demoted 2026-05-09 — 76% Edge ratio.
124
+ 'secure-coding/no-unsafe-deserialization': 'warn',
109
125
  // High - Regex vulnerabilities
110
126
  'secure-coding/detect-non-literal-regexp': 'warn',
127
+ // Demoted 2026-05-09 — 91% Edge ratio.
111
128
  'secure-coding/no-redos-vulnerable-regex': 'error',
112
- 'secure-coding/no-unsafe-regex-construction': 'warn',
129
+ 'secure-coding/no-unsafe-regex-construction': 'error',
113
130
  // High - Prototype pollution
114
131
  'secure-coding/detect-object-injection': 'warn',
115
132
  // Critical - Credentials
116
133
  'secure-coding/no-hardcoded-credentials': 'error',
117
134
  'secure-coding/no-insecure-comparison': 'warn',
135
+ // Critical - Template injection
136
+ 'secure-coding/no-template-injection': 'error',
118
137
  // Critical - Data integrity
119
138
  'secure-coding/no-improper-sanitization': 'error',
120
139
  // High - Logic
121
- 'secure-coding/no-missing-authentication': 'warn',
140
+ // NOTE: no-missing-authentication and require-backend-authorization are deprecated in
141
+ // secure-coding — they assume Express route handler context and belong in express-security.
142
+ // Kept in the rules registry for backwards compat; removed from flagship config.
122
143
  'secure-coding/no-privilege-escalation': 'warn',
123
- 'secure-coding/no-weak-password-recovery': 'error',
144
+ 'secure-coding/no-weak-password-recovery': 'warn', // naming heuristic — demoted
124
145
  // High - Exposure
125
146
  'secure-coding/no-sensitive-data-exposure': 'warn',
126
147
  // Medium - Resource & DoS
127
- 'secure-coding/no-unlimited-resource-allocation': 'error',
128
- 'secure-coding/no-unchecked-loop-condition': 'error',
148
+ // Demoted 2026-05-09 — both rules fail the volume-error-risk gate
149
+ // (firing ≥ 100 times on Wild without sufficient fixture coverage to
150
+ // guarantee precision). Rules were also flagged for ≥ 76% Edge ratio.
151
+ 'secure-coding/no-unlimited-resource-allocation': 'warn',
152
+ 'secure-coding/no-unchecked-loop-condition': 'warn',
129
153
  };
130
154
  exports.configs = {
155
+ /**
156
+ * Flagship preset — the two rules from this plugin in the ecosystem-wide
157
+ * flagship list (`.agent/flagship-rules.md`). Use this when you want the
158
+ * highest-signal security subset shippable in CI gates without the noise
159
+ * of `recommended`.
160
+ */
161
+ flagship: {
162
+ plugins: {
163
+ 'secure-coding': exports.plugin,
164
+ },
165
+ rules: {
166
+ 'secure-coding/no-hardcoded-credentials': 'error',
167
+ 'secure-coding/no-redos-vulnerable-regex': 'error',
168
+ },
169
+ },
131
170
  /**
132
171
  * Recommended security configuration
133
172
  *
@@ -139,10 +178,27 @@ exports.configs = {
139
178
  },
140
179
  rules: recommendedRules,
141
180
  },
181
+ /**
182
+ * Recommended-strict configuration
183
+ *
184
+ * Same rule set as `recommended` but every rule is promoted to `'error'`.
185
+ * Use this when you want CI to block on all security findings rather than
186
+ * only warning on lower-confidence rules.
187
+ *
188
+ * This is the configuration independently chosen by production teams who
189
+ * audit `recommended` and decide they want zero tolerance on all 16 rules.
190
+ */
191
+ 'recommended-strict': {
192
+ plugins: {
193
+ 'secure-coding': exports.plugin,
194
+ },
195
+ rules: Object.fromEntries(Object.keys(recommendedRules).map((rule) => [rule, 'error'])),
196
+ },
142
197
  /**
143
198
  * Strict security configuration
144
199
  *
145
- * All security rules set to 'error' for maximum protection.
200
+ * ALL rules (including experimental and opinionated ones) set to 'error'.
201
+ * Prefer `recommended-strict` unless you specifically need full coverage.
146
202
  */
147
203
  strict: {
148
204
  plugins: {
@@ -161,11 +217,13 @@ exports.configs = {
161
217
  },
162
218
  rules: {
163
219
  // A01:2021 – Broken Access Control
164
- 'secure-coding/no-missing-authentication': 'error',
165
- 'secure-coding/no-privilege-escalation': 'error',
220
+ // no-missing-authentication removed: Express-specific, use express-security plugin instead
221
+ 'secure-coding/no-privilege-escalation': 'warn',
166
222
  // A02:2021 – Cryptographic Failures
167
223
  'secure-coding/no-hardcoded-credentials': 'error',
168
- 'secure-coding/no-sensitive-data-exposure': 'error',
224
+ // Demoted from 'error': naming-heuristic detection (fires on variable names
225
+ // that sound sensitive). Cannot be enforcement-grade per I3 invariant.
226
+ 'secure-coding/no-sensitive-data-exposure': 'warn',
169
227
  // A03:2021 – Injection
170
228
  'secure-coding/no-graphql-injection': 'error',
171
229
  'secure-coding/no-xxe-injection': 'error',
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * oxlint sub-export.
8
+ *
9
+ * Consumers wire oxlint to this entry via:
10
+ * { "jsPlugins": ["eslint-plugin-secure-coding/oxlint"] }
11
+ *
12
+ * oxlint's JS plugin loader does `require('eslint-plugin-secure-coding/oxlint')` and reads
13
+ * `.rules` off the result. The compiled output of `export = plugin` is
14
+ * `module.exports = plugin`, which gives oxlint the plugin object directly
15
+ * (`{ meta, rules }`) — no wrapper, no `.default` indirection.
16
+ *
17
+ * Generated by scripts/generate-oxlint-shims.mjs. Do not edit by hand.
18
+ */
19
+ import { plugin } from './index';
20
+ export = plugin;
package/src/oxlint.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ /**
8
+ * oxlint sub-export.
9
+ *
10
+ * Consumers wire oxlint to this entry via:
11
+ * { "jsPlugins": ["eslint-plugin-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
+ const index_1 = require("./index");
21
+ module.exports = index_1.plugin;
@@ -32,6 +32,7 @@ const REGEXP_PATTERNS = [
32
32
  safeAlternative: 'Static RegExp literals or validated patterns',
33
33
  example: {
34
34
  bad: 'RegExp(userPattern)',
35
+ // oxlint-disable-next-line no-template-curly-in-string
35
36
  good: 'const safePattern = userPattern.replace(/[.*+?^${}()|[\\]\\\\]/g, \'\\\\$&\'); new RegExp(`^${safePattern}$`)'
36
37
  },
37
38
  effort: '15-20 minutes',
@@ -55,7 +56,9 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
55
56
  meta: {
56
57
  type: 'problem',
57
58
  docs: {
59
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-non-literal-regexp.md',
58
60
  description: 'Detects RegExp(variable), which might allow an attacker to DOS your server with a long-running regular expression',
61
+ cwe: 'CWE-400',
59
62
  },
60
63
  messages: {
61
64
  // 🎯 Token optimization: 41% reduction (51→30 tokens) - compact template variables
@@ -104,7 +107,9 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
104
107
  icon: eslint_devkit_1.MessageIcons.INFO,
105
108
  issueName: 'Escape Input',
106
109
  description: 'Escape special regex characters',
110
+ // oxlint-disable-next-line no-template-curly-in-string
107
111
  severity: 'LOW',
112
+ // oxlint-disable-next-line no-template-curly-in-string
108
113
  fix: 'input.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\\\$&")',
109
114
  documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping',
110
115
  })
@@ -149,6 +154,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
149
154
  * Check if a node is a literal string (potentially safe)
150
155
  * Includes template literals without expressions
151
156
  */
157
+ // oxlint-disable-next-line consistent-function-scoping
152
158
  const isLiteralString = (node) => {
153
159
  if (node.type === 'Literal' && typeof node.value === 'string') {
154
160
  return true;
@@ -163,6 +169,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
163
169
  * Check if a regex pattern contains dangerous ReDoS patterns
164
170
  * Only flag truly dangerous patterns like nested quantifiers: (a+)+, (a*)*
165
171
  */
172
+ // oxlint-disable-next-line consistent-function-scoping
166
173
  const hasReDoSPatterns = (pattern) => {
167
174
  // Detect truly dangerous nested quantifier patterns that cause exponential backtracking
168
175
  // Pattern like (a+)+, (a*)+, (a+)*, (a*)*, ([a-z]+)+
@@ -181,7 +188,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
181
188
  * Extract regex pattern from RegExp construction
182
189
  */
183
190
  const extractPattern = (node) => {
184
- const sourceCode = context.sourceCode || context.sourceCode;
191
+ const sourceCode = context.sourceCode;
185
192
  // Determine constructor type
186
193
  let constructor = 'RegExp';
187
194
  if (node.type === 'NewExpression' && node.callee.type === 'Identifier') {
@@ -240,6 +247,7 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
240
247
  /**
241
248
  * Generate refactoring steps based on the vulnerability
242
249
  */
250
+ // oxlint-disable-next-line consistent-function-scoping
243
251
  const generateRefactoringSteps = (vulnerability) => {
244
252
  if (vulnerability.pattern === 'dynamic') {
245
253
  return [