@sun-asterisk/sunlint 1.3.36 → 1.3.38

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 (113) hide show
  1. package/cli.js +34 -0
  2. package/config/rules/enhanced-rules-registry.json +387 -98
  3. package/config/rules/rules-registry-generated.json +202 -174
  4. package/config/rules-summary.json +1 -1
  5. package/core/architecture-integration.js +115 -17
  6. package/core/cli-action-handler.js +103 -28
  7. package/core/cli-program.js +7 -2
  8. package/core/github-annotate-service.js +62 -0
  9. package/core/impact-integration.js +31 -16
  10. package/core/init-command.js +261 -0
  11. package/core/output-service.js +64 -10
  12. package/core/performance-optimizer.js +1 -1
  13. package/core/summary-report-service.js +46 -0
  14. package/core/unified-rule-registry.js +4 -3
  15. package/docs/DART_RULE_EXECUTION_FLOW.md +1 -1
  16. package/docs/REGISTRY_GENERATION_DIAGRAM.md +289 -0
  17. package/docs/REGISTRY_GENERATION_FLOW.md +486 -0
  18. package/docs/skills/CREATE_NEW_DART_RULE.md +932 -0
  19. package/engines/eslint-engine.js +6 -0
  20. package/engines/heuristic-engine.js +23 -10
  21. package/engines/impact/core/detectors/database-detector.js +1 -1
  22. package/engines/impact/core/detectors/endpoint-detector.js +1 -1
  23. package/engines/impact/core/report-generator.js +235 -73
  24. package/origin-rules/dart-en.md +4 -4
  25. package/origin-rules/security-en.md +470 -282
  26. package/package.json +1 -1
  27. package/rules/dart/D001_recommended_lint_rules/config.json +134 -0
  28. package/rules/index.js +6 -4
  29. package/rules/security/S001_backend_auth_communications/dart/analyzer.js +44 -0
  30. package/rules/security/S001_backend_auth_communications/index.js +87 -0
  31. package/rules/security/S001_backend_auth_communications/typescript/analyzer.js +164 -0
  32. package/rules/security/S002_os_command_injection/dart/analyzer.js +44 -0
  33. package/rules/security/S002_os_command_injection/index.js +87 -0
  34. package/rules/security/S002_os_command_injection/typescript/analyzer.js +194 -0
  35. package/rules/security/S008_svg_content_validation/dart/analyzer.js +44 -0
  36. package/rules/security/S008_svg_content_validation/index.js +87 -0
  37. package/rules/security/S008_svg_content_validation/typescript/analyzer.js +216 -0
  38. package/rules/security/S018_no_sensitive_browser_storage/dart/analyzer.js +44 -0
  39. package/rules/security/S018_no_sensitive_browser_storage/index.js +86 -0
  40. package/rules/security/S018_no_sensitive_browser_storage/typescript/analyzer.js +193 -0
  41. package/rules/security/S021_referrer_policy/dart/analyzer.js +44 -0
  42. package/rules/security/S021_referrer_policy/index.js +86 -0
  43. package/rules/security/S021_referrer_policy/typescript/analyzer.js +183 -0
  44. package/rules/security/S023_no_json_injection/config.json +133 -44
  45. package/rules/security/S023_no_json_injection/dart/analyzer.js +7 -6
  46. package/rules/security/S023_no_json_injection/typescript/analyzer.js +402 -126
  47. package/rules/security/S023_no_json_injection/typescript/ast-analyzer.js +571 -154
  48. package/rules/security/S026_tls_all_connections/config.json +30 -0
  49. package/rules/security/S026_tls_all_connections/typescript/analyzer.js +339 -0
  50. package/rules/security/S027_mtls_certificate_validation/config.json +30 -0
  51. package/rules/security/S027_mtls_certificate_validation/typescript/analyzer.js +225 -0
  52. package/rules/security/S035_separate_app_hostnames/config.json +28 -0
  53. package/rules/security/S035_separate_app_hostnames/typescript/analyzer.js +186 -0
  54. package/rules/security/S036_lfi_rfi_protection/config.json +2 -2
  55. package/rules/security/S039_tls_certificate_validation/config.json +29 -0
  56. package/rules/security/S039_tls_certificate_validation/typescript/analyzer.js +229 -0
  57. package/rules/security/S046_jwt_algorithm_allowlist/config.json +28 -0
  58. package/rules/security/S046_jwt_algorithm_allowlist/dart/analyzer.js +44 -0
  59. package/rules/security/S046_jwt_algorithm_allowlist/index.js +87 -0
  60. package/rules/security/S046_jwt_algorithm_allowlist/typescript/analyzer.js +235 -0
  61. package/rules/security/S047_oauth_pkce_protection/config.json +31 -0
  62. package/rules/security/S047_oauth_pkce_protection/dart/analyzer.js +44 -0
  63. package/rules/security/S047_oauth_pkce_protection/index.js +86 -0
  64. package/rules/security/S047_oauth_pkce_protection/typescript/analyzer.js +78 -0
  65. package/rules/security/S048_oauth_redirect_uri_validation/config.json +30 -0
  66. package/rules/security/S048_oauth_redirect_uri_validation/typescript/analyzer.js +278 -0
  67. package/rules/security/S049_short_validity_tokens/typescript/config.json +10 -3
  68. package/rules/security/S050_reference_tokens_entropy/config.json +28 -0
  69. package/rules/security/S050_reference_tokens_entropy/dart/analyzer.js +45 -0
  70. package/rules/security/S050_reference_tokens_entropy/index.js +86 -0
  71. package/rules/security/S050_reference_tokens_entropy/typescript/analyzer.js +74 -0
  72. package/rules/security/S053_generic_error_messages/config.json +28 -0
  73. package/rules/security/S053_generic_error_messages/dart/analyzer.js +45 -0
  74. package/rules/security/S053_generic_error_messages/index.js +86 -0
  75. package/rules/security/S053_generic_error_messages/typescript/analyzer.js +80 -0
  76. package/rules/security/S055_content_type_validation/typescript/symbol-based-analyzer.js +64 -2
  77. package/rules/security/S059_disable_debug_mode/config.json +28 -0
  78. package/rules/security/S059_disable_debug_mode/dart/analyzer.js +45 -0
  79. package/rules/security/S059_disable_debug_mode/index.js +86 -0
  80. package/rules/security/S059_disable_debug_mode/typescript/analyzer.js +85 -0
  81. package/rules/security/S060_password_minimum_length/config.json +28 -0
  82. package/rules/security/S060_password_minimum_length/dart/analyzer.js +45 -0
  83. package/rules/security/S060_password_minimum_length/index.js +86 -0
  84. package/rules/security/S060_password_minimum_length/typescript/analyzer.js +78 -0
  85. package/rules/security/S026_json_schema_validation/config.json +0 -27
  86. package/rules/security/S026_json_schema_validation/typescript/analyzer.js +0 -251
  87. package/rules/security/S027_no_hardcoded_secrets/config.json +0 -29
  88. package/rules/security/S027_no_hardcoded_secrets/typescript/analyzer.js +0 -309
  89. package/rules/security/S027_no_hardcoded_secrets/typescript/categories.json +0 -153
  90. package/rules/security/S035_path_session_cookies/config.json +0 -99
  91. package/rules/security/S035_path_session_cookies/typescript/analyzer.js +0 -316
  92. package/rules/security/S035_path_session_cookies/typescript/regex-based-analyzer.js +0 -724
  93. package/rules/security/S035_path_session_cookies/typescript/symbol-based-analyzer.js +0 -373
  94. package/rules/security/S039_no_session_tokens_in_url/config.json +0 -92
  95. package/rules/security/S039_no_session_tokens_in_url/typescript/analyzer.js +0 -262
  96. package/rules/security/S039_no_session_tokens_in_url/typescript/regex-based-analyzer.js +0 -337
  97. package/rules/security/S039_no_session_tokens_in_url/typescript/symbol-based-analyzer.js +0 -443
  98. package/rules/security/S048_no_current_password_in_reset/config.json +0 -48
  99. package/rules/security/S048_no_current_password_in_reset/typescript/analyzer.js +0 -366
  100. /package/rules/security/{S026_json_schema_validation → S026_tls_all_connections}/dart/analyzer.js +0 -0
  101. /package/rules/security/{S026_json_schema_validation → S026_tls_all_connections}/index.js +0 -0
  102. /package/rules/security/{S027_no_hardcoded_secrets → S027_mtls_certificate_validation}/dart/analyzer.js +0 -0
  103. /package/rules/security/{S027_no_hardcoded_secrets → S027_mtls_certificate_validation}/index.js +0 -0
  104. /package/rules/security/{S027_no_hardcoded_secrets → S027_mtls_certificate_validation}/typescript/categorized-analyzer.js +0 -0
  105. /package/rules/security/{S035_path_session_cookies → S035_separate_app_hostnames}/dart/analyzer.js +0 -0
  106. /package/rules/security/{S035_path_session_cookies → S035_separate_app_hostnames}/index.js +0 -0
  107. /package/rules/security/{S035_path_session_cookies → S035_separate_app_hostnames}/typescript/README.md +0 -0
  108. /package/rules/security/{S039_no_session_tokens_in_url → S039_tls_certificate_validation}/dart/analyzer.js +0 -0
  109. /package/rules/security/{S039_no_session_tokens_in_url → S039_tls_certificate_validation}/index.js +0 -0
  110. /package/rules/security/{S039_no_session_tokens_in_url → S039_tls_certificate_validation}/typescript/README.md +0 -0
  111. /package/rules/security/{S048_no_current_password_in_reset → S048_oauth_redirect_uri_validation}/dart/analyzer.js +0 -0
  112. /package/rules/security/{S048_no_current_password_in_reset → S048_oauth_redirect_uri_validation}/index.js +0 -0
  113. /package/rules/security/{S048_no_current_password_in_reset → S048_oauth_redirect_uri_validation}/typescript/README.md +0 -0
@@ -3,33 +3,46 @@
3
3
  > This is a comprehensive list of security rules designed to enhance the security posture of applications.
4
4
  > Each rule includes a title, detailed description, applicable programming languages, and priority level.
5
5
 
6
- ### 📘 Rule S001 – Fail securely when access control errors occur
6
+ ### 📘 Rule S001 – Authenticate backend component communications securely
7
7
 
8
- - **Objective**: Ensure the system does not accidentally grant access when errors occur, helping to reduce the risk of unauthorized access and protect sensitive resources.
8
+ - **Objective**: Ensure all communications between backend components (APIs, middleware, data layers) are authenticated using secure, short-lived credentials instead of static secrets.
9
9
  - **Details**:
10
- - When errors occur in access control checks (e.g., query errors, runtime exceptions), the system must deny access instead of granting default permissions.
11
- - Must not fall back to "allow" state if permission data is missing or logic errors occur.
12
- - Access control mechanisms must fail in a "deny by default" manner.
10
+ - Backend-to-backend communications that bypass standard user session mechanisms must be authenticated.
11
+ - **Required authentication methods**:
12
+ - Individual service accounts (per-service identity)
13
+ - Short-term tokens (JWT with short expiry, OAuth tokens)
14
+ - Certificate-based authentication (mTLS)
15
+ - **Prohibited credentials**:
16
+ - Static passwords or API keys
17
+ - Shared accounts with privileged access
18
+ - Long-lived unchanging credentials
19
+ - Apply to: service-to-service calls, internal APIs, message queues, database connections, cache layers.
13
20
  - **Applies to**: All languages
14
- - **Tools**: SonarQube (S4524), PMD (SecurityCodeGuidelines), Manual Review, Unit Test
21
+ - **Tools**: Manual Review, IAM Policy Audit, mTLS Scanner, Secret Rotation Checker
15
22
  - **Principles**: CODE_QUALITY, SECURITY
16
- - **Version**: 1.1
17
- - **Status**: draft
23
+ - **Version**: 2.0
24
+ - **Status**: activated
18
25
  - **Severity**: critical
19
26
 
20
- ### 📘 Rule S002 – Avoid IDOR vulnerabilities in CRUD operations
27
+ ### 📘 Rule S002 – Protect against OS command injection
21
28
 
22
- - **Objective**: Prevent unauthorized access to sensitive data by verifying users' actual access rights, avoiding reliance solely on IDs in URLs.
29
+ - **Objective**: Prevent OS command injection attacks by ensuring all operating system calls use parameterized queries or proper output encoding.
23
30
  - **Details**:
24
- - Must not control permissions based solely on `id` sent from the client.
25
- - Always verify resource ownership at the backend (authorization logic).
26
- - Prefer using UUID or encrypted IDs to avoid predictable sequential IDs.
27
- - Check APIs like: `GET/PUT/DELETE /api/resource/{id}` must ensure the id belongs to the current user.
31
+ - **Never** concatenate user input directly into OS commands or shell executions.
32
+ - **Required protection methods**:
33
+ - Use parameterized OS queries (subprocess with argument lists)
34
+ - Apply contextual command line output encoding
35
+ - Use language-specific safe APIs (e.g., `subprocess.run()` with `shell=False`)
36
+ - **Avoid**:
37
+ - `shell=True` with user input
38
+ - String concatenation in `exec()`, `system()`, `Runtime.exec()`
39
+ - Backtick operators or `$()` with untrusted data
40
+ - Validate and sanitize all inputs before passing to system commands.
28
41
  - **Applies to**: All languages
29
- - **Tools**: SonarQube (S6142, S2076), Semgrep (custom rule), Manual Review
42
+ - **Tools**: SonarQube (S2076, S4721), Semgrep (command-injection), Bandit (B602, B603), Manual Review
30
43
  - **Principles**: CODE_QUALITY, SECURITY
31
- - **Version**: 1.1
32
- - **Status**: draft
44
+ - **Version**: 2.0
45
+ - **Status**: activated
33
46
  - **Severity**: critical
34
47
 
35
48
  ### 📘 Rule S003 – URL redirects must be within an allow list
@@ -63,81 +76,109 @@
63
76
  - **Status**: activated
64
77
  - **Severity**: medium
65
78
 
66
- ### 📘 Rule S005 – Do not use Origin header for authentication or access control
79
+ ### 📘 Rule S005 – Enforce authorization at trusted service layer
67
80
 
68
- - **Objective**: Prevent authentication or authorization decisions based on `Origin` header which can be easily spoofed from the client side and is unreliable for security purposes.
81
+ - **Objective**: Ensure authorization rules are enforced at a trusted server-side service layer, not relying on client-side controls that can be manipulated.
69
82
  - **Details**:
70
- - `Origin` header can be modified from the client side (via curl, script, proxy), so it must not be used as a basis for:
71
- - User identification
72
- - Access permission checks
73
- - Security business logic routing
74
- - `Origin` should only be used for source authentication in CSRF checks or CORS policies, **not for authorization decisions**.
75
- - If behavior needs to be limited by domain, must check against tokens, user sessions, or actually verified scopes.
83
+ - **Never** rely on client-side JavaScript for authorization decisions.
84
+ - **Required practices**:
85
+ - Enforce all authorization checks on trusted backend services
86
+ - Validate permissions server-side before processing requests
87
+ - Use middleware or interceptors at the service layer
88
+ - **Untrusted controls to avoid**:
89
+ - Client-side JavaScript permission checks
90
+ - Hidden form fields for authorization
91
+ - URL parameters for access control
92
+ - Browser-stored tokens without server validation
93
+ - All sensitive operations must be re-validated at the backend regardless of client-side checks.
76
94
  - **Applies to**: All languages
77
- - **Tools**: Manual Review, Semgrep (custom rule), SonarQube (custom rule)
95
+ - **Tools**: Manual Review, Static Analysis, Penetration Testing, SonarQube (custom rule)
78
96
  - **Principles**: CODE_QUALITY, SECURITY
79
- - **Version**: 1.0
97
+ - **Version**: 2.0
80
98
  - **Status**: activated
81
- - **Severity**: low
99
+ - **Severity**: critical
82
100
 
83
- ### 📘 Rule S006 – Do not send recovery or activation codes in plaintext
101
+ ### 📘 Rule S006 – Do not use default credentials for service authentication
84
102
 
85
- - **Objective**: Prevent leakage of verification codes, recovery codes, or activation tokens if email/SMS is intercepted or exposed thereby minimizing the risk of account takeover attacks.
103
+ - **Objective**: Ensure service authentication never uses default or well-known credentials that attackers can easily guess or find in documentation.
86
104
  - **Details**:
87
- - Should not send recovery or activation codes in predictable formats, sequential numbers, or containing user identifying information.
88
- - Codes sent via email/SMS must be random codes with short time-to-live (TTL), verified one-way by the system (hashed) or verified by session.
89
- - Should not store plaintext codes in database or log sent code content.
90
- - Prefer verification via temporary encrypted one-time links.
105
+ - **Never** use default credentials for any service authentication:
106
+ - `root/root`, `admin/admin`, `test/test`
107
+ - Default database passwords (e.g., `postgres/postgres`, `sa/sa`)
108
+ - Factory-default API keys or tokens
109
+ - **Required practices**:
110
+ - Generate unique, strong credentials for each service instance
111
+ - Rotate credentials regularly
112
+ - Use secrets management tools (Vault, AWS Secrets Manager)
113
+ - Scan configurations and deployment scripts for default credential patterns.
114
+ - Block deployments containing default credentials in CI/CD pipelines.
91
115
  - **Applies to**: All languages
92
- - **Tools**: Manual Review, Semgrep (custom rule), Secret Detection (regex scanner), SonarQube (custom rule)
116
+ - **Tools**: Manual Review, Secret Scanner, GitLeaks, TruffleHog, CI/CD Policy Checks
93
117
  - **Principles**: CODE_QUALITY, SECURITY
94
- - **Version**: 1.0
118
+ - **Version**: 2.0
95
119
  - **Status**: activated
96
- - **Severity**: medium
120
+ - **Severity**: critical
97
121
 
98
- ### 📘 Rule S007 – Do not store OTP codes in plaintext
122
+ ### 📘 Rule S007 – Perform output encoding before interpreter use
99
123
 
100
- - **Objective**: Protect the system from OTP reuse attacks if database/logs are accessed without authorization. OTP, magic-links, or reset codes must be treated like passwords – only stored in one-way hashed form, not recoverable.
124
+ - **Objective**: Ensure the application performs proper output encoding and escaping as a final step before data is used by the target interpreter, preventing injection attacks.
101
125
  - **Details**:
102
- - Must not store OTP codes, reset tokens, or magic-link codes in original form (plaintext) in database or log files.
103
- - OTP should have short TTL (e.g., 5 minutes) and be stored using hash functions like SHA-256.
104
- - During verification, should only compare hashed versions.
105
- - Never resend original OTP to user if already stored – generate new code if needed.
126
+ - Output encoding must occur either:
127
+ - As a final step before being used by the interpreter
128
+ - Or by the interpreter itself (using built-in encoding features)
129
+ - **Context-specific encoding**:
130
+ - HTML context: encode `<`, `>`, `&`, `"`, `'`
131
+ - JavaScript context: escape strings properly
132
+ - SQL context: use parameterized queries
133
+ - URL context: use `encodeURIComponent()`
134
+ - Shell context: escape shell metacharacters
135
+ - **Never** trust that earlier encoding is sufficient – encode at the point of use.
136
+ - Use framework-provided encoding functions where available.
106
137
  - **Applies to**: All languages
107
- - **Tools**: Manual Review, Semgrep (custom rule), Secret Detection, SonarQube (custom rule)
138
+ - **Tools**: SonarQube (S5131, S2076), Semgrep (injection rules), ESLint, Manual Review
108
139
  - **Principles**: CODE_QUALITY, SECURITY
109
- - **Version**: 1.0
140
+ - **Version**: 2.0
110
141
  - **Status**: activated
111
- - **Severity**: medium
142
+ - **Severity**: high
112
143
 
113
- ### 📘 Rule S008 – Encryption algorithms and parameters must support flexible configuration and upgrades (crypto agility)
144
+ ### 📘 Rule S008 – Validate and sanitize SVG content
114
145
 
115
- - **Objective**: Avoid binding the system to outdated cryptographic algorithms or parameters (like MD5, SHA-1, DES...), ensuring easy upgrades when standards change or new vulnerabilities emerge.
146
+ - **Objective**: Ensure user-supplied SVG (Scalable Vector Graphics) content is validated or sanitized to prevent script injection and other attacks.
116
147
  - **Details**:
117
- - Do not hardcode algorithms or encryption modes in source code.
118
- - Components like encryption algorithms, key size, hash rounds, cipher modes... should be configured via files or environment variables.
119
- - Prefer using modern algorithms like AES-GCM, SHA-256, Argon2, ChaCha20.
120
- - Algorithm changes should not require modifying core logic in code.
148
+ - SVG files can contain embedded scripts and potentially dangerous elements.
149
+ - **Allowed elements** (safe for graphics):
150
+ - Drawing elements: `svg`, `path`, `rect`, `circle`, `ellipse`, `line`, `polyline`, `polygon`
151
+ - Grouping: `g`, `defs`, `use`, `symbol`
152
+ - Styling: `style` (with restrictions), `linearGradient`, `radialGradient`
153
+ - **Prohibited elements** (must be removed/rejected):
154
+ - `script` tags
155
+ - `foreignObject` (can embed arbitrary HTML)
156
+ - Event handlers (`onclick`, `onload`, `onerror`, etc.)
157
+ - External references (`xlink:href` to external URLs)
158
+ - Use SVG sanitization libraries (e.g., DOMPurify with SVG profile).
159
+ - Consider converting SVGs to raster images for untrusted sources.
121
160
  - **Applies to**: All languages
122
- - **Tools**: Manual Review, Semgrep (custom rule), Secret Scanners, SonarQube (custom rule)
123
- - **Principles**: CODE_QUALITY, MAINTAINABILITY, SECURITY
124
- - **Version**: 1.1
125
- - **Status**: draft
126
- - **Severity**: low
161
+ - **Tools**: DOMPurify, svg-sanitizer, Manual Review, CSP Headers
162
+ - **Principles**: CODE_QUALITY, SECURITY
163
+ - **Version**: 2.0
164
+ - **Status**: activated
165
+ - **Severity**: high
127
166
 
128
- ### 📘 Rule S009 – Do not use insecure encryption modes, padding, or cryptographic algorithms
167
+ ### 📘 Rule S009 – Use only approved cryptographic algorithms, modes, and hash functions
129
168
 
130
- - **Objective**: Prevent security vulnerabilities from using outdated encryption or hash algorithms, insecure padding/encryption modes leading to data exposure, pattern leakage, or padding oracle attacks.
169
+ - **Objective**: Prevent cryptographic vulnerabilities by ensuring only secure block modes, padding schemes, ciphers, and hash functions are used throughout the application.
131
170
  - **Details**:
132
- - Do not use ECB mode in symmetric encryption (AES/3DES/Blowfish), as it reveals identical data patterns.
133
- - Avoid insecure padding like `PKCS#1 v1.5` in RSA, vulnerable to padding oracle attacks.
134
- - Do not use encryption algorithms with block size < 128-bit like `Triple-DES`, `Blowfish`, vulnerable to brute-force and collision attacks.
135
- - Do not use weak hash functions that have been broken like `MD5`, `SHA-1`.
136
- - In cases requiring backward compatibility (legacy), must isolate and clearly warn.
171
+ - Do not use insecure block modes (e.g., ECB) as they reveal identical data patterns and are vulnerable to pattern analysis attacks.
172
+ - Do not use weak padding schemes (e.g., `PKCS#1 v1.5`) which are vulnerable to padding oracle attacks.
173
+ - Use only approved ciphers and modes such as `AES` with `GCM` (Galois/Counter Mode) for authenticated encryption.
174
+ - Use only approved hash functions for general cryptographic use cases, including digital signatures, HMAC, KDF, and random bit generation.
175
+ - Disallowed hash functions such as `MD5` must not be used for any cryptographic purpose, including checksums, integrity verification, or password hashing.
176
+ - Do not use encryption algorithms with block size < 128-bit like `Triple-DES`, `Blowfish`.
177
+ - For legacy compatibility requirements, isolate the implementation and add clear security warnings.
137
178
  - **Applies to**: All languages
138
179
  - **Tools**: SonarQube (S2070, S4790, S5547), Semgrep (crypto rules), Manual Review
139
180
  - **Principles**: CODE_QUALITY, SECURITY
140
- - **Version**: 1.0
181
+ - **Version**: 2.0
141
182
  - **Status**: activated
142
183
  - **Severity**: medium
143
184
 
@@ -156,36 +197,58 @@
156
197
  - **Status**: activated
157
198
  - **Severity**: high
158
199
 
159
- ### 📘 Rule S011 – GUIDs used for security purposes must be generated according to UUID v4 standard with CSPRNG
200
+ ### 📘 Rule S011 – Enable Encrypted Client Hello (ECH) for TLS
160
201
 
161
- - **Objective**: Prevent guessing, recreation, or exploitation of GUIDs when used as identifiers for sensitive resources, by ensuring GUIDs are generated according to UUID v4 standard with cryptographically secure random number generators (CSPRNG).
202
+ - **Objective**: Prevent exposure of sensitive metadata during TLS handshake by enabling Encrypted Client Hello (ECH) to protect Server Name Indication (SNI) and other client hello fields.
162
203
  - **Details**:
163
- - Avoid using UUID v1 as it may leak MAC address and timestamp.
164
- - Do not use UUID v3/v5 as they are based on hash from input → can be recreated if input is known.
165
- - UUID v4 must be randomly generated (random-based), using CSPRNG.
166
- - Mandatory when GUID is used as: password reset ID, session ID, magic link, API key, authentication token...
204
+ - **Why ECH matters**:
205
+ - Standard TLS exposes SNI in plaintext during handshake
206
+ - Attackers can identify which sites users are visiting
207
+ - Network monitors can filter/block based on SNI
208
+ - **Required configuration**:
209
+ - Enable ECH in TLS settings (TLS 1.3 required)
210
+ - Configure ECH public keys properly
211
+ - Support HTTPS DNS records for ECH key distribution
212
+ - **Benefits**:
213
+ - Encrypts SNI and other sensitive handshake data
214
+ - Prevents traffic analysis based on destination
215
+ - Enhances user privacy
216
+ - Verify ECH is working using browser developer tools or TLS testing tools.
167
217
  - **Applies to**: All languages
168
- - **Tools**: Manual Review, Semgrep (uuid version rules), Static Analyzer, SonarQube (custom rule)
169
- - **Principles**: CODE_QUALITY, SECURITY
170
- - **Version**: 1.0
218
+ - **Tools**: SSL Labs, testssl.sh, Browser DevTools, Manual TLS Config Review
219
+ - **Principles**: SECURITY
220
+ - **Version**: 2.0
171
221
  - **Status**: activated
172
- - **Severity**: high
222
+ - **Severity**: medium
173
223
 
174
- ### 📘 Rule S012 – Protect secrets and encrypt sensitive data
224
+ ### 📘 Rule S012 – Use secrets management solution for backend secrets
175
225
 
176
- - **Objective**: Protect encryption keys, passwords, access tokens, API keys... from exposure through source code, `.env` files, or logs. Ensure sensitive data is always encrypted and keys are managed securely through Key Vault or HSM.
226
+ - **Objective**: Ensure all backend secrets are securely managed using a dedicated secrets management solution, never stored in source code or build artifacts.
177
227
  - **Details**:
178
- - Do not store private keys, JWT secrets, passwords in `.env` files, config JSON, YAML without encryption or strict access management.
179
- - Absolutely do not hardcode secrets in source code (even test keys).
180
- - Must use secure secret management systems like AWS Secrets Manager, HashiCorp Vault, Azure Key Vault, GCP Secret Manager, or HSM.
181
- - Sensitive data like payment information, passwords, PII must be encrypted before storing in database or storage.
182
- - Logs must exclude or obfuscate secret information.
228
+ - **Must use a secrets management solution** (key vault) to:
229
+ - Create secrets securely
230
+ - Store secrets with encryption at rest
231
+ - Control access with fine-grained permissions
232
+ - Rotate and destroy secrets safely
233
+ - **Types of secrets to manage**:
234
+ - Passwords and credentials
235
+ - Cryptographic key material
236
+ - Database connection strings
237
+ - Third-party system integrations
238
+ - TOTP seeds and internal secrets
239
+ - API keys
240
+ - **Prohibited practices**:
241
+ - Secrets in application source code
242
+ - Secrets in build artifacts or container images
243
+ - Secrets in environment files committed to repos
244
+ - **For L3 (high-security) applications**: Must use hardware-backed solution (HSM).
245
+ - Recommended tools: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager.
183
246
  - **Applies to**: All languages
184
- - **Tools**: SonarQube (S2068, S5547), GitLeaks, TruffleHog, Semgrep (hardcoded-secrets), Secret Scanner CI/CD
185
- - **Principles**: SECURITY
186
- - **Version**: 1.0
247
+ - **Tools**: Vault, AWS Secrets Manager, Azure Key Vault, GitLeaks, TruffleHog, HSM
248
+ - **Principles**: CODE_QUALITY, SECURITY
249
+ - **Version**: 2.0
187
250
  - **Status**: activated
188
- - **Severity**: medium
251
+ - **Severity**: critical
189
252
 
190
253
  ### 📘 Rule S013 – Always use TLS for all connections
191
254
 
@@ -272,32 +335,33 @@
272
335
  - **Status**: activated
273
336
  - **Severity**: critical
274
337
 
275
- ### 📘 Rule S018 – Prefer Allow List for Input Validation
338
+ ### 📘 Rule S018 – Do not store sensitive data in browser storage
276
339
 
277
- - **Objective**: Ensure all user inputs or external data sources are strictly validated by accepting only known good values. This reduces the risk of attacks like XSS, SQL Injection, and other security issues caused by malformed or unexpected input.
340
+ - **Objective**: Prevent sensitive data exposure by ensuring browser storage mechanisms do not contain sensitive information, except for session tokens.
278
341
  - **Details**:
279
- - Always use an **Allow List** to validate input values – only allow explicitly defined values or types (e.g., positive integers, valid emails, safe strings).
280
- - Avoid using **Deny Lists** because:
281
- - They are prone to bypass due to incomplete coverage.
282
- - They fail to catch new or unknown attack patterns.
283
- - Apply to all input sources, including:
284
- - HTML form fields
285
- - URL parameters, HTTP headers, cookies
286
- - REST API payloads or batch file inputs
287
- - RSS feeds, webhook payloads, etc.
288
- - Validation should be based on:
289
- - Data types (number, string, boolean)
290
- - Specific patterns (regex, enums)
291
- - Range or length restrictions
292
- - Use standard validation libraries where available:
293
- - `class-validator`, `joi`, `yup`, `express-validator` (JavaScript)
294
- - `javax.validation` (Java), `FluentValidation` (C#), `Cerberus` (Python), etc.
342
+ - **Browser storage types covered**:
343
+ - `localStorage` (persistent, accessible by JavaScript)
344
+ - `sessionStorage` (tab-scoped, accessible by JavaScript)
345
+ - `IndexedDB` (client-side database)
346
+ - Cookies (when not HttpOnly)
347
+ - **Prohibited data in browser storage**:
348
+ - Passwords or credentials
349
+ - Personal Identifiable Information (PII)
350
+ - Financial data (credit cards, bank accounts)
351
+ - API keys or secrets
352
+ - Encryption keys
353
+ - **Exception**: Session tokens may be stored, but:
354
+ - Use `HttpOnly` cookies when possible
355
+ - Apply short expiration times
356
+ - Implement proper token rotation
357
+ - XSS attacks can access all JavaScript-readable storage.
358
+ - Use server-side sessions for sensitive data instead.
295
359
  - **Applies to**: All languages
296
- - **Tools**: Static Analysis (Semgrep, SonarQube), Manual Review, Input Validation Libraries
297
- - **Principles**: SECURITY
298
- - **Version**: 1.1
299
- - **Status**: draft
300
- - **Severity**: medium
360
+ - **Tools**: Browser DevTools, Static Analysis (Semgrep, ESLint), Manual Code Review, Security Audit
361
+ - **Principles**: CODE_QUALITY, SECURITY
362
+ - **Version**: 2.0
363
+ - **Status**: activated
364
+ - **Severity**: high
301
365
 
302
366
  ### 📘 Rule S019 – Sanitize input before sending emails to prevent SMTP Injection
303
367
 
@@ -333,21 +397,28 @@
333
397
  - **Status**: activated
334
398
  - **Severity**: high
335
399
 
336
- ### 📘 Rule S021 – Sanitize user-generated Markdown, CSS, and XSL content
400
+ ### 📘 Rule S021 – Set Referrer-Policy to prevent sensitive data leakage
337
401
 
338
- - **Objective**: Prevent script injection via user-generated content in Markdown, CSS, or XSL.
402
+ - **Objective**: Prevent leakage of sensitive URL data (path, query parameters, hostname) to third-party services via the `Referer` HTTP header.
339
403
  - **Details**:
340
- - Attackers may abuse Markdown parser or render engine to inject JS, malicious links, or dangerous attributes (`onload`, `style=...`).
341
- - For XSL, non-sandboxed processing or external entity access can lead to XXE or XSLT injection.
342
- - Prevention:
343
- - Use libraries like `marked.js`, `markdown-it` with `sanitize: true` or XSS filter plugins.
344
- - Avoid rendering tags like `style`, `script`, `iframe`, or `javascript:` URLs.
345
- - For CSS/XSL, use sandboxed rendering engines and escape output before rendering.
404
+ - **Why it matters**:
405
+ - `Referer` header can expose sensitive data in URLs to external sites
406
+ - Internal application hostnames may reveal infrastructure details
407
+ - Query parameters may contain tokens, IDs, or PII
408
+ - **Implementation methods**:
409
+ - HTTP response header: `Referrer-Policy: strict-origin-when-cross-origin`
410
+ - HTML meta tag: `<meta name="referrer" content="strict-origin-when-cross-origin">`
411
+ - HTML element attributes: `rel="noreferrer"` on links
412
+ - **Recommended policies**:
413
+ - `strict-origin-when-cross-origin` (default, balanced)
414
+ - `same-origin` (stricter, only same-origin gets referrer)
415
+ - `no-referrer` (strictest, never send referrer)
416
+ - For internal non-public applications, use stricter policies to protect hostnames.
346
417
  - **Applies to**: All languages
347
- - **Tools**: DOMPurify, sanitize-html, markdown-it, Bandit (Python), Manual Review, SonarQube (custom rule)
418
+ - **Tools**: Browser DevTools, Security Headers Scanner, OWASP ZAP, Manual Review
348
419
  - **Principles**: CODE_QUALITY, SECURITY
349
- - **Version**: 1.1
350
- - **Status**: draft
420
+ - **Version**: 2.0
421
+ - **Status**: activated
351
422
  - **Severity**: medium
352
423
 
353
424
  ### 📘 Rule S022 – Escape data properly based on output context
@@ -369,21 +440,27 @@
369
440
  - **Status**: activated
370
441
  - **Severity**: medium
371
442
 
372
- ### 📘 Rule S023 – Prevent JSON Injection and JSON eval attacks
443
+ ### 📘 Rule S023 – Use output encoding when building dynamic JavaScript/JSON
373
444
 
374
- - **Objective**: Prevent JavaScript execution via unsafe JSON handling or injection attacks.
445
+ - **Objective**: Prevent JavaScript and JSON injection by applying proper output encoding when dynamically building JavaScript content or JSON data.
375
446
  - **Details**:
376
- - Never use `eval()` to process JSON from users.
377
- - Use proper JSON parsers:
378
- - JavaScript: `JSON.parse()`
379
- - Python: `json.loads()`
380
- - Java: `Gson`, `Jackson`, `ObjectMapper`
381
- - When rendering raw JSON into HTML, escape dangerous sequences like `</script>` or `</`.
382
- - Validate data before embedding JSON into `<script>` tags.
447
+ - **When building dynamic JavaScript**:
448
+ - Encode data before inserting into JS strings
449
+ - Escape characters: `\`, `'`, `"`, `<`, `>`, `&`, newlines
450
+ - Never use `eval()` or `new Function()` with user data
451
+ - **When building JSON responses**:
452
+ - Use native JSON serializers (`JSON.stringify()`, `json.dumps()`)
453
+ - Escape `</script>` sequences when embedding in HTML
454
+ - Validate JSON structure before parsing
455
+ - **Dangerous patterns to avoid**:
456
+ - String concatenation to build JS: `"var x = '" + userInput + "'"`
457
+ - Inline event handlers with user data
458
+ - Template literals with unescaped user input
459
+ - Use Content Security Policy (CSP) as defense-in-depth.
383
460
  - **Applies to**: All languages
384
- - **Tools**: ESLint (`no-eval`), Semgrep (`eval-dynamic`, `json-injection`), Bandit, SonarQube (S1523), Manual Review
461
+ - **Tools**: ESLint (`no-eval`), Semgrep (json-injection), SonarQube (S1523, S5334), Manual Review
385
462
  - **Principles**: CODE_QUALITY, SECURITY
386
- - **Version**: 1.0
463
+ - **Version**: 2.0
387
464
  - **Status**: activated
388
465
  - **Severity**: high
389
466
 
@@ -425,47 +502,59 @@
425
502
  - **Status**: activated
426
503
  - **Severity**: medium
427
504
 
428
- ### 📘 Rule S026 – Apply JSON Schema Validation to input data
505
+ ### 📘 Rule S026 – Use TLS encryption for all inbound and outbound connections
429
506
 
430
- - **Objective**: Ensure all incoming JSON is fully validated by schema (structure, types, constraints) before processing.
507
+ - **Objective**: Ensure all application connections use encrypted TLS protocol, with no fallback to insecure or unencrypted protocols.
431
508
  - **Details**:
432
- - JSON schema can enforce:
433
- - Required fields, type enforcement
434
- - Constraints like length, min/max values, format checks
435
- - Reduce injection risk or logic bugs from malformed JSON
436
- - Language-specific tools:
437
- - Java: use Jackson + Hibernate Validator (`@Valid`, `@Email`, `@Min`)
438
- - JavaScript: use `ajv`, `joi`
439
- - Python: use `jsonschema`, `pydantic`
440
- - Go: use `gojsonschema`
441
- - C#: use `NJsonSchema`
509
+ - **All connections must use TLS**:
510
+ - Inbound: API endpoints, web interfaces, webhooks
511
+ - Outbound: external APIs, databases, partner systems
512
+ - **Connection types covered**:
513
+ - Monitoring systems and health checks
514
+ - Management tools and admin interfaces
515
+ - Remote access and SSH connections
516
+ - Middleware and message queues
517
+ - Database connections (PostgreSQL, MySQL, MongoDB)
518
+ - Mainframe and legacy system integrations
519
+ - Partner and external API calls
520
+ - **Requirements**:
521
+ - TLS 1.2 minimum, prefer TLS 1.3
522
+ - No fallback to HTTP, unencrypted protocols
523
+ - Certificate validation enabled
524
+ - Strong cipher suites only
525
+ - Disable debug modes that bypass TLS in production.
442
526
  - **Applies to**: All languages
443
- - **Tools**: AJV, jsonschema, Joi, Pydantic, Hibernate Validator, SonarQube (custom rule), Manual Review
527
+ - **Tools**: SSL Labs, testssl.sh, nmap, Network Traffic Analysis, Manual Config Review
444
528
  - **Principles**: CODE_QUALITY, SECURITY
445
- - **Version**: 1.0
529
+ - **Version**: 2.0
446
530
  - **Status**: activated
447
- - **Severity**: medium
531
+ - **Severity**: critical
448
532
 
449
- ### 📘 Rule S027 – Never expose secrets in source code or Git
533
+ ### 📘 Rule S027 – Validate mTLS client certificates before authentication
450
534
 
451
- - **Objective**: Prevent leakage of credentials, API keys, tokens, or sensitive config via source code or version control.
535
+ - **Objective**: Ensure mTLS client certificates are properly validated and trusted before using certificate identity for authentication or authorization decisions.
452
536
  - **Details**:
453
- - Common leak sources:
454
- - `.env`, `config.yaml`, `secrets.json`, or hardcoded values like `API_KEY`, `JWT_SECRET`
455
- - Mitigation:
456
- - Use `.gitignore` to exclude secret files
457
- - Scan commits with GitLeaks, TruffleHog, detect-secrets
458
- - Add pre-commit hooks to block secret-containing files
459
- - If leaked, rotate keys, revoke tokens, and clean Git history
460
- - Additional notes:
461
- - Avoid plaintext secrets in CI/CD pipelines
462
- - Store secrets in a secure vault (e.g., AWS Secrets Manager, HashiCorp Vault)
537
+ - **Before trusting certificate identity**:
538
+ - Verify certificate is signed by trusted CA
539
+ - Check certificate has not expired
540
+ - Validate certificate is not revoked (CRL/OCSP)
541
+ - Confirm certificate subject/SAN matches expected identity
542
+ - **Certificate validation requirements**:
543
+ - Full chain validation up to root CA
544
+ - Check Extended Key Usage for client authentication
545
+ - Verify certificate purpose and constraints
546
+ - **Common mistakes to avoid**:
547
+ - Accepting any valid certificate without identity check
548
+ - Skipping revocation checks
549
+ - Trusting self-signed certificates without explicit pinning
550
+ - Using certificate CN without proper validation
551
+ - Log all certificate validation failures for security monitoring.
463
552
  - **Applies to**: All languages
464
- - **Tools**: GitLeaks, TruffleHog, detect-secrets, git-secrets, SonarQube (custom rule)
553
+ - **Tools**: OpenSSL, mTLS Testing Tools, Certificate Validator, Manual Config Review
465
554
  - **Principles**: CODE_QUALITY, SECURITY
466
- - **Version**: 1.0
555
+ - **Version**: 2.0
467
556
  - **Status**: activated
468
- - **Severity**: medium
557
+ - **Severity**: critical
469
558
 
470
559
  ### 📘 Rule S028 – Limit upload file size and number of files per user
471
560
 
@@ -620,43 +709,60 @@
620
709
  - **Status**: activated
621
710
  - **Severity**: medium
622
711
 
623
- ### 📘 Rule S035 – Set the `Path` attribute for Session Cookies to limit access scope
712
+ ### 📘 Rule S035 – Host separate applications on different hostnames
624
713
 
625
- - **Objective**: Reduce the risk of session cookie leaks or abuse across multiple apps under the same domain (e.g., `/app1` and `/app2`) by limiting cookie scope via the `Path` attribute.
714
+ - **Objective**: Leverage same-origin policy restrictions by hosting separate applications on different hostnames to isolate resources, cookies, and prevent cross-application attacks.
626
715
  - **Details**:
627
- - Cookies with `Path=/` are sent with **all requests under the same domain**, including unrelated applications.
628
- - Risk in shared domain environments:
629
- - Example: `example.com/app1`, `example.com/app2`
630
- - Cookie from `app1` will also be sent to `app2` unless `Path` is restricted.
631
- - Best practices:
632
- - Set specific `Path` (e.g., `/app1/`) so cookies only work within that path.
633
- - Avoid empty `Path` (`""`) – which defaults to `/`.
716
+ - **Same-origin policy benefits**:
717
+ - Prevents scripts from one origin accessing resources from another
718
+ - Isolates cookies and storage per hostname
719
+ - Limits impact of XSS to single application
720
+ - **Hosting requirements**:
721
+ - Each application should have its own hostname/subdomain
722
+ - Example: `app1.example.com`, `app2.example.com` (good)
723
+ - Avoid: `example.com/app1`, `example.com/app2` (shared origin)
724
+ - **Restrictions enforced**:
725
+ - Document/script isolation between origins
726
+ - Cookie isolation (with proper domain settings)
727
+ - localStorage/sessionStorage separation
728
+ - CORS enforcement for cross-origin requests
729
+ - Use subdomains or separate domains for:
730
+ - Admin panels vs public sites
731
+ - API servers vs frontend apps
732
+ - Multi-tenant applications
634
733
  - **Applies to**: All languages
635
- - **Tools**: Static Analysis, Manual Review, Chrome DevTools, Postman, SonarQube (custom rule)
734
+ - **Tools**: Manual Architecture Review, DNS Configuration Audit, Browser DevTools
636
735
  - **Principles**: CODE_QUALITY, SECURITY
637
- - **Version**: 1.0
736
+ - **Version**: 2.0
638
737
  - **Status**: activated
639
738
  - **Severity**: medium
640
739
 
641
- ### 📘 Rule S036 – Prevent LFI and RFI using path validation and allow-lists
740
+ ### 📘 Rule S036 – Use internal data for file paths, validate user filenames strictly
642
741
 
643
- - **Objective**: Block Local File Inclusion (LFI) and Remote File Inclusion (RFI) attacks where attackers access sensitive files (e.g., `/etc/passwd`, `C:\Windows\system32`) or execute code from external URLs.
742
+ - **Objective**: Prevent path traversal, LFI, RFI, and SSRF attacks by using internally generated file paths instead of user-submitted filenames, with strict validation when user input is unavoidable.
644
743
  - **Details**:
645
- - **LFI**: The app accepts unchecked file paths → attacker reads internal files.
646
- - **RFI**: The app includes external files from user input leads to Remote Code Execution.
647
- - Preventive measures:
648
- - Use **Allow List** of valid filenames/paths.
649
- - Never include/load user input directly.
650
- - Disallow URL usage in include/require/load/open.
651
- - Disable remote includes (e.g., `allow_url_include=Off` in PHP).
652
- - Normalize paths to remove `../` (path traversal).
653
- - Restrict permissions via sandboxing.
744
+ - **Preferred approach** - Use internal data:
745
+ - Generate file paths from internal IDs or UUIDs
746
+ - Map user selections to predefined safe paths
747
+ - Store file metadata in database, not in filenames
748
+ - **When user filenames are required**:
749
+ - Strip path separators (`/`, `\`, `..`)
750
+ - Validate against allow-list of characters
751
+ - Limit filename length
752
+ - Sanitize file extensions
753
+ - Normalize paths before validation
754
+ - **Attacks prevented**:
755
+ - Path traversal (`../../etc/passwd`)
756
+ - Local File Inclusion (LFI)
757
+ - Remote File Inclusion (RFI)
758
+ - Server-Side Request Forgery (SSRF)
759
+ - Never use user input directly in: `include()`, `require()`, `open()`, `readFile()`, file download paths.
654
760
  - **Applies to**: All languages
655
- - **Tools**: Static Analysis, OWASP ZAP, Burp Suite, Manual Review, SonarQube (custom rule)
761
+ - **Tools**: Static Analysis, OWASP ZAP, Burp Suite, Semgrep (path-traversal), Manual Review
656
762
  - **Principles**: CODE_QUALITY, SECURITY
657
- - **Version**: 1.0
763
+ - **Version**: 2.0
658
764
  - **Status**: activated
659
- - **Severity**: high
765
+ - **Severity**: critical
660
766
 
661
767
  ### 📘 Rule S037 – Set anti-cache headers to prevent sensitive data leakage
662
768
 
@@ -700,23 +806,30 @@
700
806
  - **Status**: activated
701
807
  - **Severity**: medium
702
808
 
703
- ### 📘 Rule S039 – Never transmit Session Tokens via URL parameters
809
+ ### 📘 Rule S039 – TLS clients must validate server certificates
704
810
 
705
- - **Objective**: Prevent session hijacking by ensuring session tokens are not stored in browser history, server logs, proxy logs, or leaked via Referrer headers.
811
+ - **Objective**: Ensure TLS clients validate certificates received from servers before establishing secure communication to prevent MITM attacks.
706
812
  - **Details**:
707
- - Risks of token in URL (e.g., `https://example.com/dashboard?sessionId=abc123`):
708
- - Saved in browser history
709
- - Logged on server/load balancer
710
- - Leaked via `Referer` to third parties
711
- - Best practices:
712
- - Use `Secure`, `HttpOnly` cookies for token storage
713
- - Use headers or body for API auth – never query string
813
+ - **Required certificate validation**:
814
+ - Verify certificate is signed by trusted CA
815
+ - Check certificate chain up to root CA
816
+ - Validate certificate has not expired
817
+ - Confirm hostname matches certificate CN/SAN
818
+ - **Do NOT disable validation**:
819
+ - Never set `rejectUnauthorized: false` (Node.js)
820
+ - Never set `verify=False` (Python requests)
821
+ - Never set `InsecureSkipVerify: true` (Go)
822
+ - Never ignore SSL errors in production
823
+ - **Certificate revocation**:
824
+ - Check CRL or OCSP when possible
825
+ - Consider OCSP stapling for performance
826
+ - For development/testing only: use self-signed certs with explicit trust, not disabled validation.
714
827
  - **Applies to**: All languages
715
- - **Tools**: Static Analysis, Manual Review, Burp Suite, Postman, SonarQube (custom rule)
716
- - **Principles**: SECURITY
717
- - **Version**: 1.0
828
+ - **Tools**: SSL Labs, testssl.sh, Static Analysis, Manual Code Review
829
+ - **Principles**: CODE_QUALITY, SECURITY
830
+ - **Version**: 2.0
718
831
  - **Status**: activated
719
- - **Severity**: high
832
+ - **Severity**: critical
720
833
 
721
834
  ### 📘 Rule S040 – Regenerate Session Token after login to prevent Session Fixation
722
835
 
@@ -734,7 +847,7 @@
734
847
  - **Tools**: Static Analysis, Manual Review, OWASP ZAP, Burp Suite, SonarQube (custom rule)
735
848
  - **Principles**: SECURITY
736
849
  - **Version**: 1.1
737
- - **Status**: draft
850
+ - **Status**: activated
738
851
  - **Severity**: high
739
852
 
740
853
  ### 📘 Rule S041 – Session Tokens must be invalidated after logout or expiration
@@ -787,7 +900,7 @@
787
900
  - **Tools**: Manual Review, Static Analysis (Token Revocation Logic), SonarQube (custom rule)
788
901
  - **Principles**: CODE_QUALITY, SECURITY
789
902
  - **Version**: 1.1
790
- - **Status**: draft
903
+ - **Status**: activated
791
904
  - **Severity**: medium
792
905
 
793
906
  ### 📘 Rule S044 – Require re-authentication before modifying critical information
@@ -823,61 +936,86 @@
823
936
  - **Status**: activated
824
937
  - **Severity**: medium
825
938
 
826
- ### 📘 Rule S046 – Notify users of critical account changes
939
+ ### 📘 Rule S046 – Use algorithm allowlist for self-contained tokens
827
940
 
828
- - **Objective**: Alert users to sensitive actions to detect potential compromise and allow timely intervention.
941
+ - **Objective**: Prevent algorithm confusion and downgrade attacks by restricting token signing/verification to an explicit allowlist of algorithms.
829
942
  - **Details**:
830
- - Notify users when performing actions such as:
831
- - Password reset
832
- - Changing email or phone number
833
- - Login from new devices or suspicious IPs
834
- - Notification channels: Email, Push Notification, or SMS
835
- - **Do not include sensitive info** (e.g., password, token, unencrypted links)
836
- - Log these events for security audit purposes
943
+ - **Must use algorithm allowlist**:
944
+ - Define permitted algorithms explicitly for each context
945
+ - Validate algorithm before processing token
946
+ - Reject tokens using algorithms not in allowlist
947
+ - **Critical requirement**:
948
+ - **Never** allow the `none` algorithm
949
+ - Prefer either symmetric OR asymmetric algorithms, not both
950
+ - **If both symmetric and asymmetric needed**:
951
+ - Implement key type validation
952
+ - Prevent key confusion attacks (using symmetric key as asymmetric)
953
+ - Use separate key stores for different algorithm types
954
+ - **Recommended algorithms**:
955
+ - Symmetric: HS256, HS384, HS512
956
+ - Asymmetric: RS256, RS384, RS512, ES256, ES384, ES512
957
+ - Validate algorithm in token header matches expected algorithm before verification.
837
958
  - **Applies to**: All languages
838
- - **Tools**: Manual Review, Security Test, Notification Audit, SonarQube (custom rule)
959
+ - **Tools**: JWT Debugger, Static Analysis, Manual Code Review, Security Test
839
960
  - **Principles**: CODE_QUALITY, SECURITY
840
- - **Version**: 1.1
841
- - **Status**: draft
842
- - **Severity**: medium
961
+ - **Version**: 2.0
962
+ - **Status**: activated
963
+ - **Severity**: critical
843
964
 
844
- ### 📘 Rule S047 – Secure temporary passwords and activation codes
965
+ ### 📘 Rule S047 – Protect OAuth code flow against CSRF attacks
845
966
 
846
- - **Objective**: Ensure that temporary passwords and activation codes are secure, unpredictable, single-use, and time-limited.
967
+ - **Objective**: Prevent browser-based CSRF attacks that could trigger unauthorized OAuth token requests by implementing PKCE or state parameter validation.
847
968
  - **Details**:
848
- - Temporary credentials must:
849
- - Be randomly generated using CSPRNG
850
- - Be at least **6 characters long**, and contain **letters and numbers**
851
- - Have short validity: **15 minutes to 24 hours**
852
- - Be **one-time use only**
853
- - **Must not** be used as permanent passwords
854
- - Additional protection:
855
- - Store only hashed values if persisted
856
- - Invalidate after use
857
- - Disallow regeneration until expired
969
+ - **OAuth code flow CSRF protection methods**:
970
+ - **PKCE (Proof Key for Code Exchange)** - Recommended:
971
+ - Generate cryptographically random `code_verifier`
972
+ - Send `code_challenge` (hash of verifier) in authorization request
973
+ - Send `code_verifier` in token request
974
+ - Server validates challenge matches verifier
975
+ - **State parameter**:
976
+ - Generate unique, unpredictable `state` value
977
+ - Send `state` in authorization request
978
+ - Validate `state` in callback matches sent value
979
+ - Bind state to user session
980
+ - **Requirements**:
981
+ - Use PKCE for all public clients (SPAs, mobile apps)
982
+ - Use state parameter as minimum for confidential clients
983
+ - Never reuse state or PKCE values
984
+ - Reject authorization responses without valid state/PKCE.
858
985
  - **Applies to**: All languages
859
- - **Tools**: Manual Review, Static Analysis, Audit Flow, SonarQube (custom rule)
986
+ - **Tools**: OAuth Security Testing, Manual Code Review, OWASP ZAP
860
987
  - **Principles**: CODE_QUALITY, SECURITY
861
- - **Version**: 1.0
988
+ - **Version**: 2.0
862
989
  - **Status**: activated
863
990
  - **Severity**: high
864
991
 
865
- ### 📘 Rule S048 – Do not expose current password during reset flow
992
+ ### 📘 Rule S048 – Validate OAuth redirect URIs with exact string comparison
866
993
 
867
- - **Objective**: Ensure the current user password is never revealed or sent in any step of the password reset process.
994
+ - **Objective**: Prevent OAuth redirect attacks by validating redirect URIs against a client-specific allowlist using exact string comparison, not pattern matching.
868
995
  - **Details**:
869
- - **Never display or send the current password** to the user
870
- - Do not email or SMS old passwords
871
- - During password reset:
872
- - Only ask for new password (with confirmation)
873
- - Use OTP/email/token for verification, not current password
874
- - If changing password while logged in, require **manual entry of current password**, never show it
996
+ - **Redirect URI validation requirements**:
997
+ - Use exact string comparison (no wildcards, no patterns)
998
+ - Validate against pre-registered URIs only
999
+ - Each OAuth client must have its own allowlist
1000
+ - **Do NOT allow**:
1001
+ - Wildcard redirects (`*.example.com`)
1002
+ - Partial matching (`example.com/callback*`)
1003
+ - Open redirects to any URL
1004
+ - Localhost in production (except for development clients)
1005
+ - **Pre-registration process**:
1006
+ - Register all valid redirect URIs during client creation
1007
+ - Require admin approval for URI changes
1008
+ - Audit redirect URI changes
1009
+ - **Common attack patterns blocked**:
1010
+ - Subdomain takeover (`attacker.example.com`)
1011
+ - Path traversal in redirect
1012
+ - Parameter injection in URI
875
1013
  - **Applies to**: All languages
876
- - **Tools**: Manual Review, Penetration Test, SonarQube (custom rule)
877
- - **Principles**: SECURITY
878
- - **Version**: 1.0
1014
+ - **Tools**: OAuth Security Testing, Manual Config Review, Penetration Testing
1015
+ - **Principles**: CODE_QUALITY, SECURITY
1016
+ - **Version**: 2.0
879
1017
  - **Status**: activated
880
- - **Severity**: medium
1018
+ - **Severity**: critical
881
1019
 
882
1020
  ### 📘 Rule S049 – Authentication codes must expire quickly
883
1021
 
@@ -896,26 +1034,32 @@
896
1034
  - **Status**: activated
897
1035
  - **Severity**: medium
898
1036
 
899
- ### 📘 Rule S050 – Session tokens must have minimum 64-bit entropy and use secure algorithms
1037
+ ### 📘 Rule S050 – Reference tokens must be unique with 128-bit entropy using CSPRNG
900
1038
 
901
- - **Objective**: Prevent attackers from predicting or forging session tokens by ensuring sufficient length, entropy, and cryptographic safety.
1039
+ - **Objective**: Ensure reference tokens (session tokens, opaque tokens) are unpredictable and resistant to brute-force attacks by using cryptographically secure generation.
902
1040
  - **Details**:
903
- - Session tokens must have at least **64-bit entropy**, recommended: **128-bit or 256-bit**
904
- - Use approved cryptographic algorithms:
905
- - HMAC-SHA-256
906
- - AES-256
907
- - ChaCha20
908
- - Avoid weak algorithms:
909
- - MD5
910
- - SHA-1
911
- - Do not generate tokens using `Math.random()` or short guessable strings
912
- - Always use CSPRNG for token generation
1041
+ - **Token requirements**:
1042
+ - Generated using CSPRNG (Cryptographically Secure Pseudo-Random Number Generator)
1043
+ - Minimum **128 bits of entropy** (recommended: 256 bits)
1044
+ - Must be unique across all active sessions
1045
+ - **Secure generation methods**:
1046
+ - Node.js: `crypto.randomBytes(32)`
1047
+ - Python: `secrets.token_hex(32)`
1048
+ - Java: `SecureRandom`
1049
+ - Go: `crypto/rand`
1050
+ - **Do NOT use**:
1051
+ - `Math.random()` or similar non-cryptographic RNG
1052
+ - Sequential or predictable patterns
1053
+ - User-derivable values (username, timestamp alone)
1054
+ - Short tokens (< 128 bits)
1055
+ - Store tokens securely (hashed if possible) and transmit only over TLS.
1056
+ - Implement token rotation and expiration policies.
913
1057
  - **Applies to**: All languages
914
- - **Tools**: Manual Review, Static Analysis, SonarQube (custom rule)
1058
+ - **Tools**: Static Analysis, Security Audit, CSPRNG Verification, Manual Code Review
915
1059
  - **Principles**: CODE_QUALITY, SECURITY
916
- - **Version**: 1.0
1060
+ - **Version**: 2.0
917
1061
  - **Status**: activated
918
- - **Severity**: medium
1062
+ - **Severity**: high
919
1063
 
920
1064
  ### 📘 Rule S051 – Support 12–64 character passwords; reject >128 characters
921
1065
 
@@ -949,25 +1093,31 @@
949
1093
  - **Status**: activated
950
1094
  - **Severity**: medium
951
1095
 
952
- ### 📘 Rule S053 – Only use secure OTP algorithms like HOTP/TOTP
1096
+ ### 📘 Rule S053 – Return generic error messages, hide internal details
953
1097
 
954
- - **Objective**: Ensure OTPs are secure against spoofing and replay attacks by using safe, standard algorithms.
1098
+ - **Objective**: Prevent exposure of sensitive internal system data by returning generic error messages to consumers when unexpected or security-sensitive errors occur.
955
1099
  - **Details**:
956
- - **Do not use**:
957
- - Weak algorithms like `MD5`, `SHA-1` (deprecated)
958
- - OTPs without expiration or usage limits
959
- - **Use standards**:
960
- - `HOTP` (HMAC-based OTP [RFC 4226](https://datatracker.ietf.org/doc/html/rfc4226))
961
- - `TOTP` (Time-based OTP [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238))
962
- - Recommended libraries:
963
- - `PyOTP` (Python), `otplib` (Node.js), `Google Authenticator` SDK (Java)
964
- - Always enforce time-based expiration (typically 30–300 seconds)
1100
+ - **Never expose to consumers**:
1101
+ - Stack traces or exception details
1102
+ - Database queries or SQL errors
1103
+ - Secret keys, tokens, or credentials
1104
+ - Internal file paths or system configuration
1105
+ - Server version or technology stack details
1106
+ - **Return generic messages**:
1107
+ - "An unexpected error occurred. Please try again later."
1108
+ - "Request could not be processed."
1109
+ - Use error codes for support reference (e.g., `ERR-12345`)
1110
+ - **Internal handling**:
1111
+ - Log full error details server-side for debugging
1112
+ - Include correlation IDs in logs for traceability
1113
+ - Use structured logging with proper log levels
1114
+ - Differentiate between client errors (4xx) and server errors (5xx) without leaking details.
965
1115
  - **Applies to**: All languages
966
- - **Tools**: Manual Review, Unit Test, Static Analysis, SonarQube (custom rule)
1116
+ - **Tools**: Static Analysis, Penetration Testing, Error Response Audit, Manual Code Review
967
1117
  - **Principles**: CODE_QUALITY, SECURITY
968
- - **Version**: 1.0
1118
+ - **Version**: 2.0
969
1119
  - **Status**: activated
970
- - **Severity**: medium
1120
+ - **Severity**: high
971
1121
 
972
1122
  ### 📘 Rule S054 – Avoid using default accounts like "admin", "root", "sa"
973
1123
 
@@ -1050,19 +1200,57 @@
1050
1200
  - **Status**: activated
1051
1201
  - **Severity**: medium
1052
1202
 
1053
- ### 📘 Rule S059 – Configure Allow List for server-side outbound requests
1203
+ ### 📘 Rule S059 – Disable debug modes in production environments
1054
1204
 
1055
- - **Objective**: Reduce risks from the server making outbound requests to untrusted systems (SSRF, malicious downloads, data leaks).
1205
+ - **Objective**: Prevent exposure of debugging features and information leakage by ensuring all debug modes are disabled in production environments.
1056
1206
  - **Details**:
1057
- - All outbound connections (HTTP, FTP, DNS, etc.) must be restricted via allow lists.
1058
- - Do not let the server freely access the internet or unknown domains by default.
1059
- - Example restrictions:
1060
- - Only allow sending files to trusted storage or domains like `https://trusted.example.com`.
1061
- - Containers may only use DNS for allowed addresses.
1062
- - In cloud/serverless environments, restrict outbound traffic using IAM policies, security groups, or network ACLs.
1207
+ - **Debug features to disable in production**:
1208
+ - Framework debug modes (Django `DEBUG=False`, Flask `debug=False`)
1209
+ - Detailed error pages with stack traces
1210
+ - Debug endpoints (`/debug`, `/trace`, `/actuator`)
1211
+ - SQL query logging to responses
1212
+ - Verbose logging that exposes sensitive data
1213
+ - **Common debug indicators to check**:
1214
+ - `DEBUG=true` in environment variables
1215
+ - Development server warnings in logs
1216
+ - Source maps exposed in frontend
1217
+ - Test/mock endpoints accessible
1218
+ - **Verification steps**:
1219
+ - Audit configuration files for debug settings
1220
+ - Test error responses for information leakage
1221
+ - Check HTTP headers for debug information
1222
+ - Review CI/CD pipelines for proper environment separation
1223
+ - Use environment-specific configurations, never deploy development configs to production.
1063
1224
  - **Applies to**: All languages
1064
- - **Tools**: Manual Config Review, Firewall/Proxy Logs, CloudTrail, Burp Suite Test, SonarQube (custom rule)
1065
- - **Principles**: SECURITY
1066
- - **Version**: 1.1
1067
- - **Status**: draft
1068
- - **Severity**: low
1225
+ - **Tools**: Configuration Audit, Penetration Testing, OWASP ZAP, Environment Checker
1226
+ - **Principles**: CODE_QUALITY, SECURITY
1227
+ - **Version**: 2.0
1228
+ - **Status**: activated
1229
+ - **Severity**: high
1230
+
1231
+ ### 📘 Rule S060 – Enforce minimum password length of 8 characters, recommend 15+
1232
+
1233
+ - **Objective**: Ensure user-set passwords meet minimum length requirements to provide adequate security against brute-force and dictionary attacks.
1234
+ - **Details**:
1235
+ - **Minimum requirements**:
1236
+ - Passwords must be at least **8 characters** in length
1237
+ - A minimum of **15 characters is strongly recommended** for better security
1238
+ - **Implementation guidelines**:
1239
+ - Enforce 8-character minimum at registration and password change
1240
+ - Display strength indicator encouraging longer passwords
1241
+ - Show recommendation for 15+ characters without blocking shorter valid passwords
1242
+ - **Rationale**:
1243
+ - 8 characters: baseline protection against common attacks
1244
+ - 15+ characters: significantly increases resistance to brute-force
1245
+ - Longer passwords (passphrases) are easier to remember and more secure
1246
+ - **User experience considerations**:
1247
+ - Provide real-time feedback on password strength
1248
+ - Suggest passphrase approach (e.g., "correct horse battery staple")
1249
+ - Do not impose complex character requirements that reduce usability
1250
+ - Combine with other password policies (breach detection, no common passwords).
1251
+ - **Applies to**: All languages
1252
+ - **Tools**: Static Analysis, Unit Test, Password Strength Libraries (zxcvbn), Manual Review
1253
+ - **Principles**: CODE_QUALITY, SECURITY
1254
+ - **Version**: 2.0
1255
+ - **Status**: activated
1256
+ - **Severity**: medium