eslint-plugin-express-security 1.3.4 → 1.5.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 (52) hide show
  1. package/README.md +46 -27
  2. package/package.json +27 -18
  3. package/src/index.d.ts +17 -40
  4. package/src/index.js +47 -62
  5. package/src/oxlint.d.ts +17 -20
  6. package/src/oxlint.js +0 -18
  7. package/src/rules/no-client-controlled-authorization/index.js +194 -0
  8. package/src/rules/no-cors-credentials-wildcard/index.js +0 -22
  9. package/src/rules/no-disabled-helmet-protections/index.js +125 -0
  10. package/src/rules/no-error-details-in-response/index.js +176 -0
  11. package/src/rules/no-exposed-debug-endpoints/index.js +27 -32
  12. package/src/rules/no-express-unsafe-regex-route/index.js +1 -32
  13. package/src/rules/no-graphql-introspection-production/index.js +0 -21
  14. package/src/rules/no-host-header-in-links/index.js +235 -0
  15. package/src/rules/no-idor-resource-access/index.js +126 -0
  16. package/src/rules/no-insecure-cookie-options/index.js +0 -12
  17. package/src/rules/no-missing-cors-check/index.js +4 -54
  18. package/src/rules/no-missing-csrf-protection/index.js +0 -25
  19. package/src/rules/no-missing-security-headers/index.js +50 -69
  20. package/src/rules/no-permissive-cors/index.js +0 -27
  21. package/src/rules/no-permissive-trust-proxy/index.js +106 -0
  22. package/src/rules/no-sensitive-data-in-query/index.js +182 -0
  23. package/src/rules/no-static-root-exposure/index.js +267 -0
  24. package/src/rules/no-unsafe-csp-directives/index.js +264 -0
  25. package/src/rules/no-user-controlled-redirect/index.js +0 -26
  26. package/src/rules/no-user-controlled-render-locals/index.js +268 -0
  27. package/src/rules/require-case-insensitive-path-guard/index.js +180 -0
  28. package/src/rules/require-csrf-protection/index.js +0 -42
  29. package/src/rules/require-express-body-parser-limits/index.js +0 -24
  30. package/src/rules/require-helmet/index.js +1 -25
  31. package/src/rules/require-query-type-guard/index.js +258 -0
  32. package/src/rules/require-rate-limiting/index.js +0 -13
  33. package/src/rules/require-route-authentication/index.js +225 -0
  34. package/src/rules/require-strict-transport-security/index.js +171 -0
  35. package/src/types/index.js +0 -5
  36. package/src/utils/index.js +81 -0
  37. package/AGENTS.md +0 -100
  38. package/CHANGELOG.md +0 -149
  39. package/src/rules/no-cors-credentials-wildcard/index.d.ts +0 -26
  40. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -14
  41. package/src/rules/no-express-unsafe-regex-route/index.d.ts +0 -27
  42. package/src/rules/no-graphql-introspection-production/index.d.ts +0 -26
  43. package/src/rules/no-insecure-cookie-options/index.d.ts +0 -39
  44. package/src/rules/no-missing-cors-check/index.d.ts +0 -28
  45. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -30
  46. package/src/rules/no-missing-security-headers/index.d.ts +0 -26
  47. package/src/rules/no-permissive-cors/index.d.ts +0 -28
  48. package/src/rules/no-user-controlled-redirect/index.d.ts +0 -44
  49. package/src/rules/require-csrf-protection/index.d.ts +0 -28
  50. package/src/rules/require-express-body-parser-limits/index.d.ts +0 -31
  51. package/src/rules/require-helmet/index.d.ts +0 -29
  52. package/src/rules/require-rate-limiting/index.d.ts +0 -31
@@ -1,30 +0,0 @@
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
- * ESLint Rule: no-missing-csrf-protection
8
- * Detects missing CSRF token validation in POST/PUT/DELETE requests
9
- * CWE-352: Cross-Site Request Forgery (CSRF)
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/352.html
12
- * @see https://owasp.org/www-community/attacks/csrf
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'missingCsrfProtection' | 'addCsrfValidation';
16
- export interface Options {
17
- /** Allow missing CSRF protection in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** CSRF middleware patterns to recognize. Default: ['csrf', 'csurf', 'csrfProtection', 'verifyCsrfToken'] */
20
- csrfMiddlewarePatterns?: string[];
21
- /** HTTP methods that require CSRF protection. Default: ['post', 'put', 'delete', 'patch'] */
22
- protectedMethods?: string[];
23
- /** Additional safe patterns to ignore. Default: [] */
24
- ignorePatterns?: string[];
25
- }
26
- type RuleOptions = [Options?];
27
- export declare const noMissingCsrfProtection: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
28
- name: string;
29
- };
30
- export {};
@@ -1,26 +0,0 @@
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
- * ESLint Rule: no-missing-security-headers
8
- * Detects missing security headers in HTTP responses
9
- * CWE-693: Protection Mechanism Failure
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/693.html
12
- * @see https://owasp.org/www-project-secure-headers/
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'missingSecurityHeader' | 'addSecurityHeaders' | 'useMiddleware' | 'setHeader';
16
- export interface Options {
17
- /** Required security headers. Default: ['Content-Security-Policy', 'X-Frame-Options', 'X-Content-Type-Options'] */
18
- requiredHeaders?: string[];
19
- /** Ignore in test files. Default: true */
20
- ignoreInTests?: boolean;
21
- }
22
- type RuleOptions = [Options?];
23
- export declare const noMissingSecurityHeaders: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
24
- name: string;
25
- };
26
- export {};
@@ -1,28 +0,0 @@
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
- * ESLint Rule: no-permissive-cors
8
- * Detects overly permissive CORS configurations in Express.js applications
9
- * CWE-942: Permissive Cross-domain Policy with Untrusted Domains
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/942.html
12
- * @see https://owasp.org/www-community/attacks/CORS_OriginHeaderScrutiny
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'permissiveCors' | 'useWhitelist';
16
- export interface Options {
17
- /** Allow permissive CORS in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** Allow origin: true for development. Default: false */
20
- allowOriginTrue?: boolean;
21
- /** Allowed origins that should not trigger warnings. Default: [] */
22
- allowedOrigins?: string[];
23
- }
24
- type RuleOptions = [Options?];
25
- export declare const noPermissiveCors: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
26
- name: string;
27
- };
28
- export {};
@@ -1,44 +0,0 @@
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
- * ESLint Rule: no-user-controlled-redirect
8
- *
9
- * Detects open-redirect vulnerabilities where res.redirect() is called with a
10
- * value directly sourced from user-controlled request properties (req.query,
11
- * req.body, req.params, req.headers). An attacker can craft a link that
12
- * redirects victims to a malicious site after a legitimate-looking interaction.
13
- *
14
- * CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
15
- * OWASP A01:2021 – Broken Access Control
16
- *
17
- * ## Detection method: structural-api
18
- *
19
- * This rule passes the litmus test: it fires on the AST shape of
20
- * `res.redirect(req.query.*)` — not on variable names. Rename `res` to `r`
21
- * and `req` to `q` in the source; the rule still fires because it checks the
22
- * member-access chain `<ident>.redirect(<ident>.<userSourceProp>.*)`.
23
- *
24
- * The rule only fires when the redirect argument is DIRECTLY a request
25
- * property access — it does NOT attempt data-flow or taint analysis.
26
- * `const url = req.query.url; res.redirect(url)` is not detected (the
27
- * indirect case). This conservative approach means zero false positives on
28
- * validated redirects while catching the most common unvalidated pattern.
29
- *
30
- * @see https://cwe.mitre.org/data/definitions/601.html
31
- * @see https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
32
- */
33
- import type { TSESLint } from '@interlace/eslint-devkit';
34
- export interface Options {
35
- /** Additional response object names beyond the default set. Default: [] */
36
- responseObjects?: string[];
37
- /** Additional request object names beyond the default set. Default: [] */
38
- requestObjects?: string[];
39
- }
40
- type RuleOptions = [Options?];
41
- export declare const noUserControlledRedirect: TSESLint.RuleModule<"openRedirect", RuleOptions, unknown, TSESLint.RuleListener> & {
42
- name: string;
43
- };
44
- export {};
@@ -1,28 +0,0 @@
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
- * ESLint Rule: require-csrf-protection
8
- * Detects Express.js routes handling state-changing requests without CSRF protection
9
- * CWE-352: Cross-Site Request Forgery (CSRF)
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/352.html
12
- * @see https://owasp.org/www-community/attacks/csrf
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'missingCsrf' | 'addCsrf';
16
- export interface Options {
17
- /** Allow missing CSRF in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** HTTP methods that require CSRF protection. Default: ['post', 'put', 'patch', 'delete'] */
20
- protectedMethods?: string[];
21
- /** Route patterns to ignore (e.g., /api/webhook). Default: [] */
22
- ignorePatterns?: string[];
23
- }
24
- type RuleOptions = [Options?];
25
- export declare const requireCsrfProtection: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
26
- name: string;
27
- };
28
- export {};
@@ -1,31 +0,0 @@
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
- * ESLint Rule: require-express-body-parser-limits
8
- * Detects Express.js body parsers missing or with excessive size limits
9
- * CWE-400: Uncontrolled Resource Consumption
10
- *
11
- * CVE-2024-45590 highlights DoS vulnerabilities in body-parser.
12
- * Without size limits, attackers can exhaust server memory.
13
- *
14
- * @see https://cwe.mitre.org/data/definitions/400.html
15
- * @see https://expressjs.com/en/4x/api.html#express.json
16
- */
17
- import type { TSESLint } from '@interlace/eslint-devkit';
18
- type MessageIds = 'missingLimit' | 'excessiveLimit' | 'addLimit';
19
- export interface Options {
20
- /** Allow in test files. Default: false */
21
- allowInTests?: boolean;
22
- /** Maximum allowed limit in bytes. Default: 102400 (100kb) */
23
- maxLimit?: number;
24
- /** Limits that are considered excessive (as strings). Default: ['50mb', '100mb', '500mb', '1gb'] */
25
- excessiveLimits?: string[];
26
- }
27
- type RuleOptions = [Options?];
28
- export declare const requireExpressBodyParserLimits: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
29
- name: string;
30
- };
31
- export {};
@@ -1,29 +0,0 @@
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
- * ESLint Rule: require-helmet
8
- * Detects Express.js applications missing helmet middleware for security headers
9
- * CWE-693: Protection Mechanism Failure
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/693.html
12
- * @see https://helmetjs.github.io/
13
- * @see https://owasp.org/www-project-secure-headers/
14
- */
15
- import type { TSESLint } from '@interlace/eslint-devkit';
16
- type MessageIds = 'missingHelmet' | 'addHelmet';
17
- export interface Options {
18
- /** Allow missing helmet in test files. Default: false */
19
- allowInTests?: boolean;
20
- /** Alternative security headers middleware names to accept. Default: [] */
21
- alternativeMiddleware?: string[];
22
- /** Skip rule if helmet/security headers are provided elsewhere (e.g., reverse proxy). Default: false */
23
- assumeHelmetMiddleware?: boolean;
24
- }
25
- type RuleOptions = [Options?];
26
- export declare const requireHelmet: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
27
- name: string;
28
- };
29
- export {};
@@ -1,31 +0,0 @@
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
- * ESLint Rule: require-rate-limiting
8
- * Detects Express.js applications missing rate limiting middleware
9
- * CWE-770: Allocation of Resources Without Limits or Throttling
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/770.html
12
- * @see https://owasp.org/www-community/controls/Blocking_Brute_Force_Attacks
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'missingRateLimiting' | 'addRateLimiting';
16
- export interface Options {
17
- /** Allow missing rate limiting in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** Alternative rate limiting middleware names. Default: [] */
20
- alternativeMiddleware?: string[];
21
- /**
22
- * Skip rule if rate limiting is provided elsewhere (e.g., AWS API Gateway, Cloudflare, nginx).
23
- * Default: false
24
- */
25
- assumeRateLimiting?: boolean;
26
- }
27
- type RuleOptions = [Options?];
28
- export declare const requireRateLimiting: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
29
- name: string;
30
- };
31
- export {};