eslint-plugin-secure-coding 3.0.0 → 3.0.2

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 (158) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +1 -1
  3. package/README.md +90 -422
  4. package/package.json +6 -5
  5. package/src/index.d.ts +5 -14
  6. package/src/index.js +36 -265
  7. package/src/rules/detect-non-literal-regexp/index.d.ts +20 -1
  8. package/src/rules/detect-non-literal-regexp/index.js +5 -0
  9. package/src/rules/detect-object-injection/index.d.ts +25 -1
  10. package/src/rules/detect-object-injection/index.js +5 -0
  11. package/src/rules/detect-weak-password-validation/index.d.ts +8 -2
  12. package/src/rules/detect-weak-password-validation/index.js +6 -1
  13. package/src/rules/no-directive-injection/index.d.ts +27 -1
  14. package/src/rules/no-directive-injection/index.js +5 -0
  15. package/src/rules/no-electron-security-issues/index.d.ts +27 -1
  16. package/src/rules/no-electron-security-issues/index.js +5 -0
  17. package/src/rules/no-format-string-injection/index.d.ts +28 -1
  18. package/src/rules/no-format-string-injection/index.js +5 -0
  19. package/src/rules/no-graphql-injection/index.d.ts +29 -1
  20. package/src/rules/no-graphql-injection/index.js +5 -0
  21. package/src/rules/no-hardcoded-credentials/index.d.ts +19 -1
  22. package/src/rules/no-hardcoded-credentials/index.js +5 -0
  23. package/src/rules/no-hardcoded-session-tokens/index.d.ts +8 -2
  24. package/src/rules/no-hardcoded-session-tokens/index.js +6 -1
  25. package/src/rules/no-improper-sanitization/index.d.ts +27 -1
  26. package/src/rules/no-improper-sanitization/index.js +5 -0
  27. package/src/rules/no-improper-type-validation/index.d.ts +27 -1
  28. package/src/rules/no-improper-type-validation/index.js +5 -0
  29. package/src/rules/no-insecure-comparison/index.d.ts +20 -1
  30. package/src/rules/no-insecure-comparison/index.js +5 -0
  31. package/src/rules/no-ldap-injection/index.d.ts +30 -1
  32. package/src/rules/no-ldap-injection/index.js +5 -0
  33. package/src/rules/no-missing-authentication/index.d.ts +20 -1
  34. package/src/rules/no-missing-authentication/index.js +5 -1
  35. package/src/rules/no-pii-in-logs/index.d.ts +8 -4
  36. package/src/rules/no-pii-in-logs/index.js +15 -12
  37. package/src/rules/no-privilege-escalation/index.d.ts +20 -1
  38. package/src/rules/no-privilege-escalation/index.js +5 -0
  39. package/src/rules/no-redos-vulnerable-regex/index.d.ts +22 -1
  40. package/src/rules/no-redos-vulnerable-regex/index.js +5 -0
  41. package/src/rules/no-sensitive-data-exposure/index.d.ts +20 -1
  42. package/src/rules/no-sensitive-data-exposure/index.js +5 -0
  43. package/src/rules/no-unchecked-loop-condition/index.d.ts +27 -1
  44. package/src/rules/no-unchecked-loop-condition/index.js +5 -0
  45. package/src/rules/no-unlimited-resource-allocation/index.d.ts +27 -1
  46. package/src/rules/no-unlimited-resource-allocation/index.js +5 -0
  47. package/src/rules/no-unsafe-deserialization/index.d.ts +31 -1
  48. package/src/rules/no-unsafe-deserialization/index.js +5 -0
  49. package/src/rules/no-unsafe-regex-construction/index.d.ts +22 -1
  50. package/src/rules/no-unsafe-regex-construction/index.js +5 -0
  51. package/src/rules/no-weak-password-recovery/index.d.ts +27 -1
  52. package/src/rules/no-weak-password-recovery/index.js +5 -0
  53. package/src/rules/no-xpath-injection/index.d.ts +30 -1
  54. package/src/rules/no-xpath-injection/index.js +5 -0
  55. package/src/rules/no-xxe-injection/index.d.ts +30 -1
  56. package/src/rules/no-xxe-injection/index.js +5 -0
  57. package/src/rules/require-backend-authorization/index.d.ts +8 -2
  58. package/src/rules/require-backend-authorization/index.js +6 -1
  59. package/src/rules/require-secure-defaults/index.d.ts +8 -4
  60. package/src/rules/require-secure-defaults/index.js +7 -6
  61. package/src/types/index.d.ts +10 -52
  62. package/src/types/index.js +3 -12
  63. package/src/rules/detect-child-process/index.d.ts +0 -11
  64. package/src/rules/detect-child-process/index.js +0 -529
  65. package/src/rules/detect-eval-with-expression/index.d.ts +0 -9
  66. package/src/rules/detect-eval-with-expression/index.js +0 -392
  67. package/src/rules/detect-mixed-content/index.d.ts +0 -8
  68. package/src/rules/detect-mixed-content/index.js +0 -44
  69. package/src/rules/detect-non-literal-fs-filename/index.d.ts +0 -7
  70. package/src/rules/detect-non-literal-fs-filename/index.js +0 -454
  71. package/src/rules/detect-suspicious-dependencies/index.d.ts +0 -8
  72. package/src/rules/detect-suspicious-dependencies/index.js +0 -71
  73. package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -8
  74. package/src/rules/no-allow-arbitrary-loads/index.js +0 -47
  75. package/src/rules/no-arbitrary-file-access/index.d.ts +0 -13
  76. package/src/rules/no-arbitrary-file-access/index.js +0 -195
  77. package/src/rules/no-buffer-overread/index.d.ts +0 -29
  78. package/src/rules/no-buffer-overread/index.js +0 -606
  79. package/src/rules/no-clickjacking/index.d.ts +0 -10
  80. package/src/rules/no-clickjacking/index.js +0 -396
  81. package/src/rules/no-client-side-auth-logic/index.d.ts +0 -6
  82. package/src/rules/no-client-side-auth-logic/index.js +0 -69
  83. package/src/rules/no-credentials-in-query-params/index.d.ts +0 -8
  84. package/src/rules/no-credentials-in-query-params/index.js +0 -57
  85. package/src/rules/no-data-in-temp-storage/index.d.ts +0 -6
  86. package/src/rules/no-data-in-temp-storage/index.js +0 -64
  87. package/src/rules/no-debug-code-in-production/index.d.ts +0 -8
  88. package/src/rules/no-debug-code-in-production/index.js +0 -51
  89. package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -6
  90. package/src/rules/no-disabled-certificate-validation/index.js +0 -61
  91. package/src/rules/no-dynamic-dependency-loading/index.d.ts +0 -8
  92. package/src/rules/no-dynamic-dependency-loading/index.js +0 -51
  93. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -6
  94. package/src/rules/no-exposed-debug-endpoints/index.js +0 -62
  95. package/src/rules/no-exposed-sensitive-data/index.d.ts +0 -11
  96. package/src/rules/no-exposed-sensitive-data/index.js +0 -340
  97. package/src/rules/no-http-urls/index.d.ts +0 -12
  98. package/src/rules/no-http-urls/index.js +0 -114
  99. package/src/rules/no-insecure-redirects/index.d.ts +0 -7
  100. package/src/rules/no-insecure-redirects/index.js +0 -216
  101. package/src/rules/no-insecure-websocket/index.d.ts +0 -6
  102. package/src/rules/no-insecure-websocket/index.js +0 -61
  103. package/src/rules/no-missing-cors-check/index.d.ts +0 -9
  104. package/src/rules/no-missing-cors-check/index.js +0 -399
  105. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -11
  106. package/src/rules/no-missing-csrf-protection/index.js +0 -180
  107. package/src/rules/no-missing-security-headers/index.d.ts +0 -7
  108. package/src/rules/no-missing-security-headers/index.js +0 -218
  109. package/src/rules/no-password-in-url/index.d.ts +0 -8
  110. package/src/rules/no-password-in-url/index.js +0 -54
  111. package/src/rules/no-permissive-cors/index.d.ts +0 -8
  112. package/src/rules/no-permissive-cors/index.js +0 -65
  113. package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -8
  114. package/src/rules/no-sensitive-data-in-analytics/index.js +0 -62
  115. package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -8
  116. package/src/rules/no-sensitive-data-in-cache/index.js +0 -52
  117. package/src/rules/no-toctou-vulnerability/index.d.ts +0 -7
  118. package/src/rules/no-toctou-vulnerability/index.js +0 -208
  119. package/src/rules/no-tracking-without-consent/index.d.ts +0 -6
  120. package/src/rules/no-tracking-without-consent/index.js +0 -67
  121. package/src/rules/no-unencrypted-transmission/index.d.ts +0 -11
  122. package/src/rules/no-unencrypted-transmission/index.js +0 -236
  123. package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -9
  124. package/src/rules/no-unescaped-url-parameter/index.js +0 -355
  125. package/src/rules/no-unsafe-dynamic-require/index.d.ts +0 -5
  126. package/src/rules/no-unsafe-dynamic-require/index.js +0 -106
  127. package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -6
  128. package/src/rules/no-unvalidated-deeplinks/index.js +0 -62
  129. package/src/rules/no-unvalidated-user-input/index.d.ts +0 -9
  130. package/src/rules/no-unvalidated-user-input/index.js +0 -420
  131. package/src/rules/no-verbose-error-messages/index.d.ts +0 -8
  132. package/src/rules/no-verbose-error-messages/index.js +0 -68
  133. package/src/rules/no-zip-slip/index.d.ts +0 -9
  134. package/src/rules/no-zip-slip/index.js +0 -445
  135. package/src/rules/require-code-minification/index.d.ts +0 -8
  136. package/src/rules/require-code-minification/index.js +0 -47
  137. package/src/rules/require-csp-headers/index.d.ts +0 -6
  138. package/src/rules/require-csp-headers/index.js +0 -64
  139. package/src/rules/require-data-minimization/index.d.ts +0 -8
  140. package/src/rules/require-data-minimization/index.js +0 -53
  141. package/src/rules/require-dependency-integrity/index.d.ts +0 -6
  142. package/src/rules/require-dependency-integrity/index.js +0 -64
  143. package/src/rules/require-https-only/index.d.ts +0 -8
  144. package/src/rules/require-https-only/index.js +0 -62
  145. package/src/rules/require-mime-type-validation/index.d.ts +0 -6
  146. package/src/rules/require-mime-type-validation/index.js +0 -66
  147. package/src/rules/require-network-timeout/index.d.ts +0 -8
  148. package/src/rules/require-network-timeout/index.js +0 -50
  149. package/src/rules/require-package-lock/index.d.ts +0 -8
  150. package/src/rules/require-package-lock/index.js +0 -63
  151. package/src/rules/require-secure-credential-storage/index.d.ts +0 -8
  152. package/src/rules/require-secure-credential-storage/index.js +0 -50
  153. package/src/rules/require-secure-deletion/index.d.ts +0 -8
  154. package/src/rules/require-secure-deletion/index.js +0 -44
  155. package/src/rules/require-storage-encryption/index.d.ts +0 -8
  156. package/src/rules/require-storage-encryption/index.js +0 -50
  157. package/src/rules/require-url-validation/index.d.ts +0 -6
  158. package/src/rules/require-url-validation/index.js +0 -72
@@ -1,51 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview Detect debug code in production
4
- * @see https://owasp.org/www-project-mobile-top-10/
5
- * @see https://cwe.mitre.org/data/definitions/489.html
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.noDebugCodeInProduction = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- exports.noDebugCodeInProduction = (0, eslint_devkit_1.createRule)({
11
- name: 'no-debug-code-in-production',
12
- meta: {
13
- type: 'problem',
14
- docs: {
15
- description: 'Detect debug code in production',
16
- category: 'Security',
17
- recommended: true,
18
- owaspMobile: ['M7'],
19
- cweIds: ["CWE-489"],
20
- },
21
- messages: {
22
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
23
- icon: eslint_devkit_1.MessageIcons.SECURITY,
24
- issueName: 'violation Detected',
25
- cwe: 'CWE-489',
26
- description: 'Detect debug code in production detected - DEBUG, __DEV__, console',
27
- severity: 'HIGH',
28
- fix: 'Review and apply secure practices',
29
- documentationLink: 'https://cwe.mitre.org/data/definitions/489.html',
30
- })
31
- },
32
- schema: [],
33
- },
34
- defaultOptions: [],
35
- create(context) {
36
- return {
37
- Identifier(node) {
38
- if (['DEBUG', '__DEV__'].includes(node.name)) {
39
- context.report({ node, messageId: 'violationDetected' });
40
- }
41
- },
42
- CallExpression(node) {
43
- if (node.callee.type === 'MemberExpression' &&
44
- node.callee.object.name === 'console' &&
45
- node.callee.property.name === 'log') {
46
- context.report({ node, messageId: 'violationDetected' });
47
- }
48
- },
49
- };
50
- },
51
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Prevent disabled SSL/TLS certificate validation
3
- */
4
- export interface Options {
5
- }
6
- export declare const noDisabledCertificateValidation: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview Prevent disabled SSL/TLS certificate validation
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.noDisabledCertificateValidation = void 0;
7
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
8
- exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
9
- name: 'no-disabled-certificate-validation',
10
- meta: {
11
- type: 'problem',
12
- docs: {
13
- description: 'Prevent disabled SSL/TLS certificate validation',
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Disabled Certificate Validation',
19
- cwe: 'CWE-295',
20
- description: 'SSL/TLS certificate validation is disabled - man-in-the-middle attack possible',
21
- severity: 'CRITICAL',
22
- fix: 'Remove rejectUnauthorized: false or verify: false, fix certificate issues properly',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/295.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- const dangerousProperties = ['rejectUnauthorized', 'strictSSL', 'verify'];
34
- return {
35
- Property(node) {
36
- // Check for dangerous SSL options set to false
37
- if (node.key.type === 'Identifier' &&
38
- dangerousProperties.includes(node.key.name) &&
39
- node.value.type === 'Literal' &&
40
- node.value.value === false) {
41
- report(node);
42
- }
43
- },
44
- AssignmentExpression(node) {
45
- // Check for NODE_TLS_REJECT_UNAUTHORIZED = '0'
46
- if (node.left.type === 'MemberExpression' &&
47
- node.left.object.type === 'MemberExpression' &&
48
- node.left.object.object.type === 'Identifier' &&
49
- node.left.object.object.name === 'process' &&
50
- node.left.object.property.type === 'Identifier' &&
51
- node.left.object.property.name === 'env' &&
52
- node.left.property.type === 'Identifier' &&
53
- node.left.property.name === 'NODE_TLS_REJECT_UNAUTHORIZED') {
54
- if (node.right.type === 'Literal' && node.right.value === '0') {
55
- report(node);
56
- }
57
- }
58
- },
59
- };
60
- },
61
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * @fileoverview Prevent dynamic dependency injection
3
- * @see https://owasp.org/www-project-mobile-top-10/
4
- * @see https://cwe.mitre.org/data/definitions/494.html
5
- */
6
- export interface Options {
7
- }
8
- export declare const noDynamicDependencyLoading: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview Prevent dynamic dependency injection
4
- * @see https://owasp.org/www-project-mobile-top-10/
5
- * @see https://cwe.mitre.org/data/definitions/494.html
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.noDynamicDependencyLoading = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- exports.noDynamicDependencyLoading = (0, eslint_devkit_1.createRule)({
11
- name: 'no-dynamic-dependency-loading',
12
- meta: {
13
- type: 'problem',
14
- docs: {
15
- description: 'Prevent runtime dependency injection with dynamic paths',
16
- category: 'Security',
17
- recommended: true,
18
- owaspMobile: ['M2'],
19
- cweIds: ['CWE-494'],
20
- },
21
- messages: {
22
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
23
- icon: eslint_devkit_1.MessageIcons.SECURITY,
24
- issueName: 'violation Detected',
25
- cwe: 'CWE-1104',
26
- description: 'Dynamic import/require detected - use static imports for security',
27
- severity: 'HIGH',
28
- fix: 'Review and apply secure practices',
29
- documentationLink: 'https://cwe.mitre.org/data/definitions/1104.html',
30
- })
31
- },
32
- schema: [],
33
- },
34
- defaultOptions: [],
35
- create(context) {
36
- return {
37
- CallExpression(node) {
38
- // Dynamic require
39
- if (node.callee.name === 'require' && node.arguments[0]?.type !== 'Literal') {
40
- context.report({ node, messageId: 'violationDetected' });
41
- }
42
- },
43
- ImportExpression(node) {
44
- // Dynamic import()
45
- if (node.source.type !== 'Literal') {
46
- context.report({ node, messageId: 'violationDetected' });
47
- }
48
- },
49
- };
50
- },
51
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Detect debug endpoints without auth
3
- */
4
- export interface Options {
5
- }
6
- export declare const noExposedDebugEndpoints: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- /**
3
- * @fileoverview Detect debug endpoints without auth
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.noExposedDebugEndpoints = void 0;
7
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
8
- exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
9
- name: 'no-exposed-debug-endpoints',
10
- meta: {
11
- type: 'problem',
12
- docs: {
13
- description: 'Detect debug endpoints without auth',
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Exposed Debug Endpoint',
19
- cwe: 'CWE-489',
20
- description: 'Debug endpoint exposed without authentication',
21
- severity: 'HIGH',
22
- fix: 'Remove debug endpoints from production or add authentication',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/489.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- const debugPaths = ['/debug', '/__debug__', '/admin', '/_admin', '/test', '/health'];
34
- return {
35
- CallExpression(node) {
36
- // Detect app.get('/debug', handler)
37
- if (node.callee.type === 'MemberExpression' &&
38
- node.callee.object.type === 'Identifier' &&
39
- ['app', 'router', 'express'].includes(node.callee.object.name) &&
40
- node.callee.property.type === 'Identifier' &&
41
- ['get', 'post', 'use'].includes(node.callee.property.name)) {
42
- const pathArg = node.arguments[0];
43
- if (pathArg && pathArg.type === 'Literal' && typeof pathArg.value === 'string') {
44
- const path = pathArg.value.toLowerCase();
45
- if (debugPaths.some(dp => path.includes(dp))) {
46
- report(node);
47
- }
48
- }
49
- }
50
- },
51
- Literal(node) {
52
- // Flag debug path strings in general
53
- if (typeof node.value === 'string') {
54
- const path = node.value.toLowerCase();
55
- if (debugPaths.some(dp => path === dp)) {
56
- report(node);
57
- }
58
- }
59
- },
60
- };
61
- },
62
- });
@@ -1,11 +0,0 @@
1
- export interface Options {
2
- /** Allow sensitive data in test files. Default: false */
3
- allowInTests?: boolean;
4
- /** Patterns to detect sensitive data. Default: ['ssn', 'social', 'credit', 'card', 'password', 'secret', 'token', 'apiKey'] */
5
- sensitivePatterns?: string[];
6
- /** Logging/output patterns to detect. Default: ['log', 'console', 'print', 'debug', 'error', 'warn', 'info', 'trace', 'response', 'res.', 'req.'] */
7
- loggingPatterns?: string[];
8
- /** Additional safe patterns to ignore. Default: [] */
9
- ignorePatterns?: string[];
10
- }
11
- export declare const noExposedSensitiveData: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -1,340 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noExposedSensitiveData = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- /**
7
- * Default sensitive data patterns
8
- */
9
- const DEFAULT_SENSITIVE_PATTERNS = [
10
- 'ssn',
11
- 'social',
12
- 'credit',
13
- 'card',
14
- 'password',
15
- 'secret',
16
- 'token',
17
- 'apiKey',
18
- 'apikey',
19
- 'api_key',
20
- 'privateKey',
21
- 'private_key',
22
- 'accessToken',
23
- 'access_token',
24
- 'refreshToken',
25
- 'refresh_token',
26
- 'authToken',
27
- 'auth_token',
28
- ];
29
- /**
30
- * Default logging/output patterns
31
- */
32
- const DEFAULT_LOGGING_PATTERNS = [
33
- 'log',
34
- 'console',
35
- 'print',
36
- 'debug',
37
- 'error',
38
- 'warn',
39
- 'info',
40
- 'trace',
41
- 'response',
42
- 'res.',
43
- 'req.',
44
- ];
45
- /**
46
- * Sensitive data regex patterns
47
- */
48
- const SENSITIVE_DATA_PATTERNS = {
49
- // SSN pattern (XXX-XX-XXXX)
50
- ssn: /\b\d{3}-\d{2}-\d{4}\b/,
51
- // Credit card pattern (basic - 13-19 digits, may have spaces/dashes)
52
- creditCard: /\b(?:\d{4}[-\s]?){3}\d{1,4}\b/,
53
- // Email with sensitive context
54
- sensitiveEmail: /\b(?:password|secret|token|key|credential)[\w.-]*@[\w.-]+\.\w+\b/i,
55
- };
56
- /**
57
- * Check if a string contains sensitive data patterns
58
- */
59
- function containsSensitiveData(value, sensitivePatterns) {
60
- // Check for SSN pattern
61
- if (SENSITIVE_DATA_PATTERNS.ssn.test(value)) {
62
- return { isSensitive: true, type: 'SSN pattern detected' };
63
- }
64
- // Check for credit card pattern
65
- if (SENSITIVE_DATA_PATTERNS.creditCard.test(value)) {
66
- return { isSensitive: true, type: 'Credit card pattern detected' };
67
- }
68
- // Check for sensitive keywords in variable names or values
69
- const lowerValue = value.toLowerCase();
70
- for (const pattern of sensitivePatterns) {
71
- if (lowerValue.includes(pattern.toLowerCase())) {
72
- // Check if it's in a sensitive context (not just a comment or documentation)
73
- if (/\b(?:log|console|print|debug|error|warn|info|trace|response|res\.|req\.|body|query|params)\b/i.test(value) ||
74
- /\b(?:password|secret|token|key|credential)\s*[:=]/i.test(value)) {
75
- return { isSensitive: true, type: `Sensitive data keyword: ${pattern}` };
76
- }
77
- }
78
- }
79
- return { isSensitive: false, type: '' };
80
- }
81
- /**
82
- * Check if a string matches any ignore pattern
83
- */
84
- function matchesIgnorePattern(text, patterns) {
85
- return patterns.some(pattern => {
86
- try {
87
- const regex = new RegExp(pattern, 'i');
88
- return regex.test(text);
89
- }
90
- catch {
91
- return false;
92
- }
93
- });
94
- }
95
- /**
96
- * Check if a node is in a logging or output context
97
- */
98
- function isInLoggingContext(node, sourceCode, loggingPatterns) {
99
- // Build regex pattern from logging patterns
100
- const patternRegex = new RegExp(`\\b(?:${loggingPatterns.map(p => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})\\b`, 'i');
101
- let current = node;
102
- // Check parent chain for logging calls
103
- while (current && 'parent' in current && current.parent) {
104
- current = current.parent;
105
- if (current.type === 'CallExpression') {
106
- const callExpr = current;
107
- const callText = sourceCode.getText(current);
108
- // Check if it's a logging method call
109
- if (callExpr.callee.type === 'MemberExpression') {
110
- const memberExpr = callExpr.callee;
111
- if (memberExpr.object.type === 'Identifier' && memberExpr.property.type === 'Identifier') {
112
- const objName = memberExpr.object.name.toLowerCase();
113
- const propName = memberExpr.property.name.toLowerCase();
114
- // Check against logging patterns
115
- if (loggingPatterns.some(p => objName.includes(p.toLowerCase()) || propName.includes(p.toLowerCase()))) {
116
- return true;
117
- }
118
- }
119
- }
120
- // Also check for patterns in the call text
121
- if (patternRegex.test(callText)) {
122
- return true;
123
- }
124
- }
125
- // Check if it's in an object expression that's being logged
126
- if (current.type === 'ObjectExpression') {
127
- // Check if parent is a CallExpression with logging
128
- if (current.parent && current.parent.type === 'CallExpression') {
129
- const parentCall = current.parent;
130
- const callText = sourceCode.getText(parentCall);
131
- if (patternRegex.test(callText)) {
132
- return true;
133
- }
134
- }
135
- }
136
- }
137
- return false;
138
- }
139
- exports.noExposedSensitiveData = (0, eslint_devkit_2.createRule)({
140
- name: 'no-exposed-sensitive-data',
141
- meta: {
142
- type: 'problem',
143
- docs: {
144
- description: 'Detects exposure of PII/sensitive data (SSN, credit card numbers in logs, etc.)',
145
- },
146
- hasSuggestions: true,
147
- messages: {
148
- exposedSensitiveData: (0, eslint_devkit_1.formatLLMMessage)({
149
- icon: eslint_devkit_1.MessageIcons.SECURITY,
150
- issueName: 'Exposed Sensitive Data',
151
- cwe: 'CWE-200',
152
- description: 'Sensitive data exposure detected: {{issue}}',
153
- severity: 'CRITICAL',
154
- fix: '{{safeAlternative}}',
155
- documentationLink: 'https://cwe.mitre.org/data/definitions/200.html',
156
- }),
157
- sanitizeData: (0, eslint_devkit_1.formatLLMMessage)({
158
- icon: eslint_devkit_1.MessageIcons.INFO,
159
- issueName: 'Sanitize Data',
160
- description: 'Remove or mask sensitive information',
161
- severity: 'LOW',
162
- fix: 'Mask or remove sensitive data before logging/transmitting',
163
- documentationLink: 'https://cwe.mitre.org/data/definitions/200.html',
164
- }),
165
- },
166
- schema: [
167
- {
168
- type: 'object',
169
- properties: {
170
- allowInTests: {
171
- type: 'boolean',
172
- default: false,
173
- description: 'Allow sensitive data in test files',
174
- },
175
- sensitivePatterns: {
176
- type: 'array',
177
- items: { type: 'string' },
178
- default: [],
179
- description: 'Patterns to detect sensitive data',
180
- },
181
- loggingPatterns: {
182
- type: 'array',
183
- items: { type: 'string' },
184
- default: [],
185
- description: 'Logging/output patterns to detect',
186
- },
187
- ignorePatterns: {
188
- type: 'array',
189
- items: { type: 'string' },
190
- default: [],
191
- description: 'Additional safe patterns to ignore',
192
- },
193
- },
194
- additionalProperties: false,
195
- },
196
- ],
197
- },
198
- defaultOptions: [
199
- {
200
- allowInTests: false,
201
- sensitivePatterns: [],
202
- loggingPatterns: [],
203
- ignorePatterns: [],
204
- },
205
- ],
206
- create(context, [options = {}]) {
207
- const { allowInTests = false, sensitivePatterns, loggingPatterns, ignorePatterns = [], } = options;
208
- const patternsToCheck = sensitivePatterns && sensitivePatterns.length > 0
209
- ? sensitivePatterns
210
- : DEFAULT_SENSITIVE_PATTERNS;
211
- const loggingPatternsToCheck = loggingPatterns && loggingPatterns.length > 0
212
- ? loggingPatterns
213
- : DEFAULT_LOGGING_PATTERNS;
214
- const filename = context.getFilename();
215
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
216
- const sourceCode = context.sourceCode || context.sourceCode;
217
- function checkLiteral(node) {
218
- if (isTestFile) {
219
- return;
220
- }
221
- if (typeof node.value !== 'string') {
222
- return;
223
- }
224
- const value = node.value;
225
- const text = sourceCode.getText(node);
226
- // Check if it matches any ignore pattern
227
- if (matchesIgnorePattern(text, ignorePatterns)) {
228
- return;
229
- }
230
- // Only check if in logging/output context
231
- if (!isInLoggingContext(node, sourceCode, loggingPatternsToCheck)) {
232
- return;
233
- }
234
- const { isSensitive, type } = containsSensitiveData(value, patternsToCheck);
235
- if (isSensitive) {
236
- // For SSN and credit card patterns, don't provide auto-fix suggestions
237
- // as they require manual review
238
- const isPatternMatch = type.includes('pattern detected');
239
- context.report({
240
- node,
241
- messageId: 'exposedSensitiveData',
242
- data: {
243
- issue: `${type} in logging/output context`,
244
- safeAlternative: 'Remove or mask sensitive data before logging: logger.info({ userId: user.id }) instead of logger.info({ password: user.password })',
245
- },
246
- ...(isPatternMatch ? {} : {
247
- suggest: [
248
- {
249
- messageId: 'sanitizeData',
250
- fix(fixer) {
251
- // Suggest removing or masking the sensitive data
252
- return fixer.replaceText(node, '"***REDACTED***"');
253
- },
254
- },
255
- ],
256
- }),
257
- });
258
- }
259
- }
260
- function checkIdentifier(node) {
261
- if (isTestFile) {
262
- return;
263
- }
264
- const name = node.name;
265
- const text = sourceCode.getText(node);
266
- // Check if it matches any ignore pattern
267
- if (matchesIgnorePattern(text, ignorePatterns)) {
268
- return;
269
- }
270
- // Only check if in logging/output context
271
- if (!isInLoggingContext(node, sourceCode, loggingPatternsToCheck)) {
272
- return;
273
- }
274
- // Check if identifier name contains sensitive patterns
275
- const lowerName = name.toLowerCase();
276
- for (const pattern of patternsToCheck) {
277
- if (lowerName.includes(pattern.toLowerCase())) {
278
- // Check if it's being accessed in a sensitive way
279
- if (node.parent) {
280
- const parentText = sourceCode.getText(node.parent);
281
- // Build regex pattern from logging patterns
282
- const loggingPatternRegex = new RegExp(`\\b(?:${loggingPatternsToCheck.map(p => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})\\b`, 'i');
283
- if (loggingPatternRegex.test(parentText)) {
284
- // Get the actual property name from context
285
- const actualPropertyName = name;
286
- context.report({
287
- node,
288
- messageId: 'exposedSensitiveData',
289
- data: {
290
- issue: `Sensitive variable "${name}" exposed in logging/output`,
291
- safeAlternative: `Remove or mask sensitive data: logger.info({ userId: user.id }) instead of logger.info({ ${actualPropertyName}: user.${actualPropertyName} })`,
292
- },
293
- // Don't provide auto-fix suggestions for identifiers (too risky)
294
- });
295
- break;
296
- }
297
- }
298
- }
299
- }
300
- }
301
- function checkMemberExpression(node) {
302
- if (isTestFile) {
303
- return;
304
- }
305
- const text = sourceCode.getText(node);
306
- // Check if it matches any ignore pattern
307
- if (matchesIgnorePattern(text, ignorePatterns)) {
308
- return;
309
- }
310
- // Only check if in logging/output context
311
- if (!isInLoggingContext(node, sourceCode, loggingPatternsToCheck)) {
312
- return;
313
- }
314
- // Check if property name contains sensitive patterns
315
- if (node.property.type === 'Identifier') {
316
- const propertyName = node.property.name.toLowerCase();
317
- for (const pattern of patternsToCheck) {
318
- if (propertyName.includes(pattern.toLowerCase())) {
319
- const objectName = node.object.type === 'Identifier' ? node.object.name : 'object';
320
- context.report({
321
- node,
322
- messageId: 'exposedSensitiveData',
323
- data: {
324
- issue: `Sensitive property "${node.property.name}" exposed in logging/output`,
325
- safeAlternative: `Remove or mask sensitive data: logger.info({ userId: user.id }) instead of logger.info({ ${node.property.name}: ${objectName}.${node.property.name} })`,
326
- },
327
- // Don't provide auto-fix suggestions for property access (too risky)
328
- });
329
- break;
330
- }
331
- }
332
- }
333
- }
334
- return {
335
- Literal: checkLiteral,
336
- Identifier: checkIdentifier,
337
- MemberExpression: checkMemberExpression,
338
- };
339
- },
340
- });
@@ -1,12 +0,0 @@
1
- /**
2
- * @fileoverview Disallow hardcoded HTTP URLs
3
- * @see https://owasp.org/www-project-mobile-top-10/
4
- * @see https://cwe.mitre.org/data/definitions/319.html
5
- */
6
- export interface Options {
7
- /** List of hostnames allowed to use HTTP (e.g., localhost, 127.0.0.1) */
8
- allowedHosts?: string[];
9
- /** List of ports allowed for HTTP (e.g., 3000, 8080 for development) */
10
- allowedPorts?: number[];
11
- }
12
- export declare const noHttpUrls: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;