@sun-asterisk/sunlint 1.3.26 → 1.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/rules/enhanced-rules-registry.json +101 -17
- package/config/rules/rules-registry-generated.json +22 -22
- package/origin-rules/security-en.md +351 -338
- package/package.json +1 -1
- package/rules/common/C003_no_vague_abbreviations/analyzer.js +73 -21
- package/rules/common/C017_constructor_logic/symbol-based-analyzer.js +206 -2
- package/rules/common/C024_no_scatter_hardcoded_constants/symbol-based-analyzer.js +553 -58
- package/rules/common/C029_catch_block_logging/analyzer.js +47 -12
- package/rules/common/C033_separate_service_repository/symbol-based-analyzer.js +35 -15
- package/rules/common/C041_no_sensitive_hardcode/symbol-based-analyzer.js +9 -5
- package/rules/security/S003_open_redirect_protection/README.md +371 -0
- package/rules/security/S003_open_redirect_protection/analyzer.js +135 -0
- package/rules/security/S003_open_redirect_protection/config.json +58 -0
- package/rules/security/S003_open_redirect_protection/symbol-based-analyzer.js +884 -0
- package/rules/security/S004_sensitive_data_logging/analyzer.js +135 -0
- package/rules/security/S004_sensitive_data_logging/config.json +62 -0
- package/rules/security/S004_sensitive_data_logging/symbol-based-analyzer.js +592 -0
- package/rules/security/S005_no_origin_auth/analyzer.js +97 -148
- package/rules/security/S005_no_origin_auth/config.json +28 -67
- package/rules/security/S005_no_origin_auth/symbol-based-analyzer.js +708 -0
- package/rules/security/S006_no_plaintext_recovery_codes/symbol-based-analyzer.js +170 -31
- package/rules/security/S010_no_insecure_encryption/analyzer.js +8 -2
- package/rules/security/S012_hardcoded_secrets/analyzer.js +149 -0
- package/rules/security/S012_hardcoded_secrets/config.json +75 -0
- package/rules/security/S012_hardcoded_secrets/symbol-based-analyzer.js +1204 -0
- package/rules/security/S013_tls_enforcement/symbol-based-analyzer.js +87 -0
- package/rules/security/S017_use_parameterized_queries/analyzer.js +11 -78
- package/rules/security/S017_use_parameterized_queries/symbol-based-analyzer.js +1146 -1
- package/rules/security/S019_smtp_injection_protection/analyzer.js +120 -0
- package/rules/security/S019_smtp_injection_protection/config.json +35 -0
- package/rules/security/S019_smtp_injection_protection/symbol-based-analyzer.js +687 -0
- package/rules/security/S020_no_eval_dynamic_code/analyzer.js +55 -130
- package/rules/security/S020_no_eval_dynamic_code/symbol-based-analyzer.js +4 -19
- package/rules/security/S022_escape_output_context/README.md +254 -0
- package/rules/security/S022_escape_output_context/analyzer.js +510 -0
- package/rules/security/S022_escape_output_context/config.json +229 -0
- package/rules/security/S023_no_json_injection/analyzer.js +15 -0
- package/rules/security/S023_no_json_injection/ast-analyzer.js +18 -3
- package/rules/security/S023_no_json_injection/config.json +133 -0
- package/rules/security/S024_xpath_xxe_protection/regex-based-analyzer.js +41 -0
- package/rules/security/S027_no_hardcoded_secrets/analyzer.js +67 -8
- package/rules/security/S027_no_hardcoded_secrets/categorized-analyzer.js +29 -6
- package/rules/security/S029_csrf_protection/config.json +127 -0
- package/rules/security/S030_directory_browsing_protection/regex-based-analyzer.js +160 -28
- package/rules/security/S030_directory_browsing_protection/symbol-based-analyzer.js +81 -19
- package/rules/security/S031_secure_session_cookies/analyzer.js +20 -2
- package/rules/security/S031_secure_session_cookies/regex-based-analyzer.js +100 -0
- package/rules/security/S031_secure_session_cookies/symbol-based-analyzer.js +8 -1
- package/rules/security/S032_httponly_session_cookies/analyzer.js +2 -2
- package/rules/security/S032_httponly_session_cookies/regex-based-analyzer.js +115 -0
- package/rules/security/S032_httponly_session_cookies/symbol-based-analyzer.js +39 -10
- package/rules/security/S036_lfi_rfi_protection/analyzer.js +224 -0
- package/rules/security/S036_lfi_rfi_protection/config.json +20 -0
- package/rules/security/S040_session_fixation_protection/analyzer.js +153 -0
- package/rules/security/S040_session_fixation_protection/config.json +20 -0
- package/rules/security/S042_require_re_authentication_for_long_lived/README.md +83 -0
- package/rules/security/S042_require_re_authentication_for_long_lived/analyzer.js +153 -0
- package/rules/security/S042_require_re_authentication_for_long_lived/config.json +41 -0
- package/rules/security/S042_require_re_authentication_for_long_lived/symbol-based-analyzer.js +1139 -0
- package/rules/security/S043_password_changes_invalidate_all_sessions/README.md +107 -0
- package/rules/security/S043_password_changes_invalidate_all_sessions/analyzer.js +153 -0
- package/rules/security/S043_password_changes_invalidate_all_sessions/config.json +41 -0
- package/rules/security/S043_password_changes_invalidate_all_sessions/symbol-based-analyzer.js +541 -0
- package/docs/COMMAND-EXAMPLES.md +0 -390
- package/docs/FILE_LIMITS_COMPLETION_REPORT.md +0 -151
- package/docs/FOLDER_STRUCTURE.md +0 -59
- package/docs/SIMPLIFIED_USAGE_GUIDE.md +0 -208
- package/rules/security/S017_use_parameterized_queries/regex-based-analyzer.js +0 -541
- package/rules/security/S020_no_eval_dynamic_code/regex-based-analyzer.js +0 -307
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
- **Applies to**: All languages
|
|
14
14
|
- **Tools**: SonarQube (S4524), PMD (SecurityCodeGuidelines), Manual Review, Unit Test
|
|
15
15
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
16
|
-
- **Version**: 1.
|
|
17
|
-
- **Status**:
|
|
16
|
+
- **Version**: 1.1
|
|
17
|
+
- **Status**: draft
|
|
18
18
|
- **Severity**: critical
|
|
19
19
|
|
|
20
20
|
### 📘 Rule S002 – Avoid IDOR vulnerabilities in CRUD operations
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
- **Applies to**: All languages
|
|
29
29
|
- **Tools**: SonarQube (S6142, S2076), Semgrep (custom rule), Manual Review
|
|
30
30
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
31
|
-
- **Version**: 1.
|
|
32
|
-
- **Status**:
|
|
31
|
+
- **Version**: 1.1
|
|
32
|
+
- **Status**: draft
|
|
33
33
|
- **Severity**: critical
|
|
34
34
|
|
|
35
35
|
### 📘 Rule S003 – URL redirects must be within an allow list
|
|
@@ -121,8 +121,8 @@
|
|
|
121
121
|
- **Applies to**: All languages
|
|
122
122
|
- **Tools**: Manual Review, Semgrep (custom rule), Secret Scanners, SonarQube (custom rule)
|
|
123
123
|
- **Principles**: CODE_QUALITY, MAINTAINABILITY, SECURITY
|
|
124
|
-
- **Version**: 1.
|
|
125
|
-
- **Status**:
|
|
124
|
+
- **Version**: 1.1
|
|
125
|
+
- **Status**: draft
|
|
126
126
|
- **Severity**: low
|
|
127
127
|
|
|
128
128
|
### 📘 Rule S009 – Do not use insecure encryption modes, padding, or cryptographic algorithms
|
|
@@ -276,38 +276,39 @@
|
|
|
276
276
|
|
|
277
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.
|
|
278
278
|
- **Details**:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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.
|
|
295
295
|
- **Applies to**: All languages
|
|
296
296
|
- **Tools**: Static Analysis (Semgrep, SonarQube), Manual Review, Input Validation Libraries
|
|
297
297
|
- **Principles**: SECURITY
|
|
298
|
-
- **Version**: 1.
|
|
299
|
-
- **Status**:
|
|
298
|
+
- **Version**: 1.1
|
|
299
|
+
- **Status**: draft
|
|
300
300
|
- **Severity**: medium
|
|
301
301
|
|
|
302
302
|
### 📘 Rule S019 – Sanitize input before sending emails to prevent SMTP Injection
|
|
303
|
+
|
|
303
304
|
- **Objective**: Prevent SMTP/IMAP injection by removing control characters and ensuring proper formatting of user input used in email sending.
|
|
304
305
|
- **Details**:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
- SMTP Injection occurs when input contains `\r`, `\n` which can inject new lines or alter email content.
|
|
307
|
+
- Risks: hidden email sending, modified content, header spoofing, or spam.
|
|
308
|
+
- Prevention:
|
|
309
|
+
- Strip or reject control characters (`\n`, `\r`) in `to`, `subject`, `cc`, `bcc`, `reply-to`.
|
|
310
|
+
- Validate email format strictly before use.
|
|
311
|
+
- Prefer using secure email APIs like SendGrid, Amazon SES, Mailgun instead of direct SMTP protocol.
|
|
311
312
|
- **Applies to**: All languages
|
|
312
313
|
- **Tools**: Semgrep (regex match), Manual Review, Static Analysis, SonarQube (custom rule)
|
|
313
314
|
- **Principles**: SECURITY
|
|
@@ -316,14 +317,15 @@
|
|
|
316
317
|
- **Severity**: medium
|
|
317
318
|
|
|
318
319
|
### 📘 Rule S020 – Avoid using `eval()` or executing dynamic code
|
|
320
|
+
|
|
319
321
|
- **Objective**: Prevent Remote Code Execution (RCE) by disallowing use of dynamic code execution functions like `eval()`, `Function()`, `exec()`, `Runtime.exec()` with user-controlled input.
|
|
320
322
|
- **Details**:
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
323
|
+
- Functions like `eval()`, `exec()`, `new Function()`, or `setTimeout(..., string)` allow arbitrary code execution, dangerous with untrusted input.
|
|
324
|
+
- Attackers can execute system commands, read files, or manipulate databases remotely.
|
|
325
|
+
- Alternatives to `eval`:
|
|
326
|
+
- Object mapping or switch-case for dynamic logic
|
|
327
|
+
- JSON parsing for data structures
|
|
328
|
+
- `safe-eval` library (only within a sandboxed scope)
|
|
327
329
|
- **Applies to**: All languages
|
|
328
330
|
- **Tools**: Semgrep (eval-detection rules), ESLint (`no-eval`), SonarQube (S1523), Static Analyzer
|
|
329
331
|
- **Principles**: SECURITY
|
|
@@ -332,32 +334,34 @@
|
|
|
332
334
|
- **Severity**: high
|
|
333
335
|
|
|
334
336
|
### 📘 Rule S021 – Sanitize user-generated Markdown, CSS, and XSL content
|
|
337
|
+
|
|
335
338
|
- **Objective**: Prevent script injection via user-generated content in Markdown, CSS, or XSL.
|
|
336
339
|
- **Details**:
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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.
|
|
343
346
|
- **Applies to**: All languages
|
|
344
347
|
- **Tools**: DOMPurify, sanitize-html, markdown-it, Bandit (Python), Manual Review, SonarQube (custom rule)
|
|
345
348
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
346
|
-
- **Version**: 1.
|
|
347
|
-
- **Status**:
|
|
349
|
+
- **Version**: 1.1
|
|
350
|
+
- **Status**: draft
|
|
348
351
|
- **Severity**: medium
|
|
349
352
|
|
|
350
353
|
### 📘 Rule S022 – Escape data properly based on output context
|
|
354
|
+
|
|
351
355
|
- **Objective**: Prevent XSS, Header Injection, Email Injection by escaping output data according to context (HTML, JS, URL, Header, Email, etc).
|
|
352
356
|
- **Details**:
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
- Use the correct escaping strategy for each context:
|
|
358
|
+
- **HTML content**: escape `&`, `<`, `>`, `"`, `'`
|
|
359
|
+
- **HTML attributes**: escape `"` and `'` values
|
|
360
|
+
- **JavaScript inline**: escape strings to avoid arbitrary execution
|
|
361
|
+
- **URL params**: use `encodeURIComponent()`
|
|
362
|
+
- **HTTP headers**: strip `\r`, `\n` to prevent injection
|
|
363
|
+
- **SMTP email**: filter control characters like `\r`, `\n`, `bcc:` from content
|
|
364
|
+
- Avoid using a single escape function for all cases.
|
|
361
365
|
- **Applies to**: All languages
|
|
362
366
|
- **Tools**: ESLint (`no-script-url`, `react/no-danger`), Bandit, SonarQube (S2076), DOMPurify, Manual Review
|
|
363
367
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -366,15 +370,16 @@
|
|
|
366
370
|
- **Severity**: medium
|
|
367
371
|
|
|
368
372
|
### 📘 Rule S023 – Prevent JSON Injection and JSON eval attacks
|
|
373
|
+
|
|
369
374
|
- **Objective**: Prevent JavaScript execution via unsafe JSON handling or injection attacks.
|
|
370
375
|
- **Details**:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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.
|
|
378
383
|
- **Applies to**: All languages
|
|
379
384
|
- **Tools**: ESLint (`no-eval`), Semgrep (`eval-dynamic`, `json-injection`), Bandit, SonarQube (S1523), Manual Review
|
|
380
385
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -383,34 +388,36 @@
|
|
|
383
388
|
- **Severity**: high
|
|
384
389
|
|
|
385
390
|
### 📘 Rule S024 – Protect against XPath Injection and XML External Entity (XXE)
|
|
391
|
+
|
|
386
392
|
- **Objective**: Prevent XPath injection and XXE vulnerabilities that can expose files, trigger SSRF, or run malicious code.
|
|
387
393
|
- **Details**:
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
+
- **XPath Injection**:
|
|
395
|
+
- Never inject user data directly into XPath queries.
|
|
396
|
+
- Use parameterized APIs or safe XPath binding mechanisms.
|
|
397
|
+
- **XXE**:
|
|
398
|
+
- Disable external entity processing in XML parsers to prevent local file access or SSRF.
|
|
399
|
+
- Disable general and parameter entity processing in DOM/SAX/lxml parsers.
|
|
394
400
|
- **Applies to**: All languages
|
|
395
401
|
- **Tools**: Semgrep (xpath injection), Bandit (Python), SonarQube (S2755), Manual Config Review
|
|
396
402
|
- **Principles**: SECURITY
|
|
397
|
-
- **Version**:
|
|
398
|
-
- **Status**:
|
|
403
|
+
- **Version**: 1.1
|
|
404
|
+
- **Status**: activated
|
|
399
405
|
- **Severity**: medium
|
|
400
406
|
|
|
401
407
|
### 📘 Rule S025 – Always validate client-side data on the server
|
|
408
|
+
|
|
402
409
|
- **Objective**: Ensure all data from clients is validated server-side to prevent attacks from forged or malicious input.
|
|
403
410
|
- **Details**:
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
- Client-side validation is only for UX – it can be bypassed.
|
|
412
|
+
- Server-side validation is the last defense before DB writes or API calls.
|
|
413
|
+
- Benefits:
|
|
414
|
+
- Blocks SQLi, XSS, Buffer Overflow, SSRF
|
|
415
|
+
- Preserves data integrity (valid enums, length limits, etc.)
|
|
416
|
+
- Testable via unit tests
|
|
417
|
+
- Recommended libraries:
|
|
418
|
+
- Java: Hibernate Validator, Spring `@Valid`
|
|
419
|
+
- Node.js: Joi, express-validator
|
|
420
|
+
- Python: pydantic, marshmallow
|
|
414
421
|
- **Applies to**: All languages
|
|
415
422
|
- **Tools**: SonarQube (S5334), ESLint (`require-validate`), Bandit (Python), Static Analysis
|
|
416
423
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -419,18 +426,19 @@
|
|
|
419
426
|
- **Severity**: medium
|
|
420
427
|
|
|
421
428
|
### 📘 Rule S026 – Apply JSON Schema Validation to input data
|
|
429
|
+
|
|
422
430
|
- **Objective**: Ensure all incoming JSON is fully validated by schema (structure, types, constraints) before processing.
|
|
423
431
|
- **Details**:
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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`
|
|
434
442
|
- **Applies to**: All languages
|
|
435
443
|
- **Tools**: AJV, jsonschema, Joi, Pydantic, Hibernate Validator, SonarQube (custom rule), Manual Review
|
|
436
444
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -439,18 +447,19 @@
|
|
|
439
447
|
- **Severity**: medium
|
|
440
448
|
|
|
441
449
|
### 📘 Rule S027 – Never expose secrets in source code or Git
|
|
450
|
+
|
|
442
451
|
- **Objective**: Prevent leakage of credentials, API keys, tokens, or sensitive config via source code or version control.
|
|
443
452
|
- **Details**:
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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)
|
|
454
463
|
- **Applies to**: All languages
|
|
455
464
|
- **Tools**: GitLeaks, TruffleHog, detect-secrets, git-secrets, SonarQube (custom rule)
|
|
456
465
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -459,21 +468,22 @@
|
|
|
459
468
|
- **Severity**: medium
|
|
460
469
|
|
|
461
470
|
### 📘 Rule S028 – Limit upload file size and number of files per user
|
|
471
|
+
|
|
462
472
|
- **Objective**: Prevent resource abuse and protect against DoS attacks by limiting file size, number of files, and user storage usage.
|
|
463
473
|
- **Details**:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
474
|
+
- Must enforce limits on:
|
|
475
|
+
- **Maximum file size** (e.g., ≤ 10MB)
|
|
476
|
+
- **Total number of files** per user or per upload
|
|
477
|
+
- **Total storage quota per user** (if applicable)
|
|
478
|
+
- Limits should be:
|
|
479
|
+
- Enforced on both client-side and server-side (server is mandatory)
|
|
480
|
+
- Handled via HTTP layer or upload middleware
|
|
481
|
+
- Logged when violations occur for abuse tracking
|
|
482
|
+
- Technology examples:
|
|
483
|
+
- Node.js: `multer` (`limits.fileSize`, `fileFilter`)
|
|
484
|
+
- Python: `Flask-Limiter`, request body size limit
|
|
485
|
+
- Java: Spring's `multipart.maxFileSize`, `maxRequestSize`
|
|
486
|
+
- Nginx/nginx-ingress: `client_max_body_size`
|
|
477
487
|
- **Applies to**: All languages
|
|
478
488
|
- **Tools**: Manual Review, Static Analysis, API Gateway Limit, Nginx Config, WAF, SonarQube (custom rule)
|
|
479
489
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -482,21 +492,22 @@
|
|
|
482
492
|
- **Severity**: medium
|
|
483
493
|
|
|
484
494
|
### 📘 Rule S029 – Apply CSRF protection for authentication-related features
|
|
495
|
+
|
|
485
496
|
- **Objective**: Prevent Cross-Site Request Forgery (CSRF) attacks where an attacker triggers unauthorized actions using the victim's authenticated session.
|
|
486
497
|
- **Details**:
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
498
|
+
- CSRF occurs when:
|
|
499
|
+
- Victim is logged in (cookies exist)
|
|
500
|
+
- Browser automatically sends cookies with attacker-forged requests
|
|
501
|
+
- **Protection mechanisms**:
|
|
502
|
+
- **CSRF Token**: Generate a unique token (per session/request), attach it in form or header, and validate server-side
|
|
503
|
+
- **SameSite Cookie**:
|
|
504
|
+
- `SameSite=Lax`: suitable for most form-based POST requests
|
|
505
|
+
- `SameSite=Strict`: most secure, may affect UX
|
|
506
|
+
- `SameSite=None; Secure`: required for cross-domain cookies (must use HTTPS)
|
|
507
|
+
- **2FA or re-authentication** for critical actions like changing email/password or performing transactions
|
|
508
|
+
- For API or SPA:
|
|
509
|
+
- Avoid storing access tokens in cookies
|
|
510
|
+
- Prefer using `Authorization: Bearer <token>` to eliminate CSRF risk
|
|
500
511
|
- **Applies to**: All languages
|
|
501
512
|
- **Tools**: Spring Security CSRF, Express `csurf`, Django CSRF middleware, Helmet.js, Manual Review, SonarQube (custom rule)
|
|
502
513
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -505,18 +516,19 @@
|
|
|
505
516
|
- **Severity**: high
|
|
506
517
|
|
|
507
518
|
### 📘 Rule S030 – Disable directory browsing and protect sensitive metadata files
|
|
519
|
+
|
|
508
520
|
- **Objective**: Prevent unauthorized access to file listings or metadata files such as `.git`, `.env`, `.DS_Store`, which can reveal sensitive system or source code information.
|
|
509
521
|
- **Details**:
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
522
|
+
- Directory browsing occurs if no `index.html` exists or misconfigured server
|
|
523
|
+
- Sensitive files may be exposed if not explicitly blocked, e.g.:
|
|
524
|
+
- `.git/config` → contains repo URL or credentials
|
|
525
|
+
- `.env` → secrets
|
|
526
|
+
- `.DS_Store`, `Thumbs.db`, `.svn` → folder structure leaks
|
|
527
|
+
- **Mitigation**:
|
|
528
|
+
- Disable `autoindex` or `Indexes` on the web server (Apache/Nginx)
|
|
529
|
+
- Deny access to metadata or dotfiles (`.git`, `.env`, etc.)
|
|
530
|
+
- Review default config of frameworks (Express, Spring, Django, etc.)
|
|
531
|
+
- Use `.gitignore` to exclude sensitive files from version control
|
|
520
532
|
- **Applies to**: All languages
|
|
521
533
|
- **Tools**: Static Analysis, Manual Review, Burp Suite, Nikto, SonarQube (custom rule)
|
|
522
534
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -525,17 +537,18 @@
|
|
|
525
537
|
- **Severity**: medium
|
|
526
538
|
|
|
527
539
|
### 📘 Rule S031 – Set the Secure flag on session cookies for HTTPS protection
|
|
540
|
+
|
|
528
541
|
- **Objective**: Prevent attackers from stealing session cookies via unencrypted HTTP, especially on public or monitored networks (MITM).
|
|
529
542
|
- **Details**:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
543
|
+
- If a **cookie lacks the `Secure` flag**, it may be sent over plain HTTP
|
|
544
|
+
- Attackers on public Wi-Fi or LAN may intercept session tokens
|
|
545
|
+
- Sensitive cookies should always include:
|
|
546
|
+
- `Secure`: only send via HTTPS
|
|
547
|
+
- `HttpOnly`: prevent JS access
|
|
548
|
+
- `SameSite`: control CSRF exposure
|
|
549
|
+
- **Best practices**:
|
|
550
|
+
- Use HTTPS in all environments (dev, staging, prod)
|
|
551
|
+
- Ensure web server enforces HTTP → HTTPS redirects
|
|
539
552
|
- **Applies to**: All languages
|
|
540
553
|
- **Tools**: OWASP ZAP, Burp Suite, Static Analysis, Manual Review, SonarQube (custom rule)
|
|
541
554
|
- **Principles**: SECURITY
|
|
@@ -586,20 +599,20 @@
|
|
|
586
599
|
|
|
587
600
|
- **Objective**: Prevent cookie theft between subdomains (e.g., `api.example.com` accessing cookies from `admin.example.com`) by using cookies prefixed with `__Host-`, which enforce strict security tied to the root domain.
|
|
588
601
|
- **Details**:
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
602
|
+
- The `__Host-` prefix enforces:
|
|
603
|
+
- Must include `Secure`
|
|
604
|
+
- Must not specify `Domain` (defaults to root domain)
|
|
605
|
+
- `Path` must be `/`
|
|
606
|
+
- Advantages:
|
|
607
|
+
- Cookie exists only on the root domain (e.g., `example.com`), cannot be overridden by subdomains.
|
|
608
|
+
- Prevents scenarios like:
|
|
609
|
+
- A malicious app on `sub1.example.com` sets a fake `sessionId`, which is then reused on `example.com`.
|
|
610
|
+
- Commonly used for:
|
|
611
|
+
- Session cookies
|
|
612
|
+
- CSRF tokens
|
|
613
|
+
- Auth tokens
|
|
614
|
+
- Limitation:
|
|
615
|
+
- Only applicable over **HTTPS** and must be set from the root domain.
|
|
603
616
|
- **Applies to**: All languages
|
|
604
617
|
- **Tools**: Manual Review, Static Analysis, Chrome DevTools Audit, SonarQube (custom rule)
|
|
605
618
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -611,13 +624,13 @@
|
|
|
611
624
|
|
|
612
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.
|
|
613
626
|
- **Details**:
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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 `/`.
|
|
621
634
|
- **Applies to**: All languages
|
|
622
635
|
- **Tools**: Static Analysis, Manual Review, Chrome DevTools, Postman, SonarQube (custom rule)
|
|
623
636
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -629,15 +642,15 @@
|
|
|
629
642
|
|
|
630
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.
|
|
631
644
|
- **Details**:
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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.
|
|
641
654
|
- **Applies to**: All languages
|
|
642
655
|
- **Tools**: Static Analysis, OWASP ZAP, Burp Suite, Manual Review, SonarQube (custom rule)
|
|
643
656
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -649,18 +662,18 @@
|
|
|
649
662
|
|
|
650
663
|
- **Objective**: Prevent browsers from caching sensitive data such as tokens, personal information, or financial content which could leak when users share devices or use back/forward navigation.
|
|
651
664
|
- **Details**:
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
665
|
+
- Modern browsers may cache:
|
|
666
|
+
- Filled-in forms
|
|
667
|
+
- Login results
|
|
668
|
+
- Rendered tokens or confidential data
|
|
669
|
+
- Recommended headers:
|
|
670
|
+
- `Cache-Control: no-store, no-cache, must-revalidate`
|
|
671
|
+
- `Pragma: no-cache`
|
|
672
|
+
- `Expires: 0`
|
|
673
|
+
- Use for:
|
|
674
|
+
- Profile lookups, dashboard pages
|
|
675
|
+
- Tokens, session content
|
|
676
|
+
- Check using DevTools → Network → Headers.
|
|
664
677
|
- **Applies to**: All languages
|
|
665
678
|
- **Tools**: Static Analysis, Postman, Chrome DevTools, Manual Review, SonarQube (custom rule)
|
|
666
679
|
- **Principles**: SECURITY
|
|
@@ -672,32 +685,32 @@
|
|
|
672
685
|
|
|
673
686
|
- **Objective**: Prevent attackers from discovering backend technologies (e.g., server, framework, OS) via HTTP response headers that can be used to target known vulnerabilities.
|
|
674
687
|
- **Details**:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
688
|
+
- Common leak examples:
|
|
689
|
+
- `Server: nginx/1.23.0`
|
|
690
|
+
- `X-Powered-By: Express`
|
|
691
|
+
- `X-AspNet-Version`, `X-Runtime`, etc.
|
|
692
|
+
- Preventive steps:
|
|
693
|
+
- Disable or override these headers.
|
|
694
|
+
- Use middleware or reverse proxy to strip response headers.
|
|
695
|
+
- Verify using DevTools, curl, or Postman.
|
|
683
696
|
- **Applies to**: All languages
|
|
684
697
|
- **Tools**: Static Analysis, curl, Postman, Chrome DevTools, Burp Suite, SonarQube (custom rule)
|
|
685
698
|
- **Principles**: SECURITY
|
|
686
|
-
- **Version**:
|
|
687
|
-
- **Status**:
|
|
699
|
+
- **Version**: 1.1
|
|
700
|
+
- **Status**: activated
|
|
688
701
|
- **Severity**: medium
|
|
689
702
|
|
|
690
703
|
### 📘 Rule S039 – Never transmit Session Tokens via URL parameters
|
|
691
704
|
|
|
692
705
|
- **Objective**: Prevent session hijacking by ensuring session tokens are not stored in browser history, server logs, proxy logs, or leaked via Referrer headers.
|
|
693
706
|
- **Details**:
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
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
|
|
701
714
|
- **Applies to**: All languages
|
|
702
715
|
- **Tools**: Static Analysis, Manual Review, Burp Suite, Postman, SonarQube (custom rule)
|
|
703
716
|
- **Principles**: SECURITY
|
|
@@ -709,34 +722,34 @@
|
|
|
709
722
|
|
|
710
723
|
- **Objective**: Prevent attackers from setting a session ID before login and taking over the session post-login if the ID remains unchanged.
|
|
711
724
|
- **Details**:
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
725
|
+
- Attack scenario:
|
|
726
|
+
- Attacker sets known session ID before login
|
|
727
|
+
- Victim logs in without regenerating session
|
|
728
|
+
- Attacker reuses the same ID for access
|
|
729
|
+
- Preventive actions:
|
|
730
|
+
- Invalidate old session after login and create a new one
|
|
731
|
+
- For JWT: issue new token on login
|
|
732
|
+
- For cookies: delete old session and set a new cookie
|
|
720
733
|
- **Applies to**: All languages
|
|
721
734
|
- **Tools**: Static Analysis, Manual Review, OWASP ZAP, Burp Suite, SonarQube (custom rule)
|
|
722
735
|
- **Principles**: SECURITY
|
|
723
|
-
- **Version**: 1.
|
|
724
|
-
- **Status**:
|
|
736
|
+
- **Version**: 1.1
|
|
737
|
+
- **Status**: draft
|
|
725
738
|
- **Severity**: high
|
|
726
739
|
|
|
727
740
|
### 📘 Rule S041 – Session Tokens must be invalidated after logout or expiration
|
|
728
741
|
|
|
729
742
|
- **Objective**: Prevent users from reusing old session tokens after logout or timeout, which could lead to session hijacking.
|
|
730
743
|
- **Details**:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
744
|
+
- Actions required:
|
|
745
|
+
- **Backend**:
|
|
746
|
+
- Remove session from memory (e.g., Redis)
|
|
747
|
+
- Revoke token or blacklist old JWT
|
|
748
|
+
- **Frontend**:
|
|
749
|
+
- Delete cookie (`document.cookie = ...`, `res.clearCookie(...)`)
|
|
750
|
+
- Remove tokens from localStorage
|
|
751
|
+
- Redirect/reload after logout
|
|
752
|
+
- Add `Cache-Control: no-store` to prevent old content reuse
|
|
740
753
|
- **Applies to**: All languages
|
|
741
754
|
- **Tools**: Static Analysis, Manual Review, Postman, DevTools, SonarQube (custom rule)
|
|
742
755
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -748,12 +761,12 @@
|
|
|
748
761
|
|
|
749
762
|
- **Objective**: Reduce the risk of session hijacking or privilege misuse by forcing re-authentication after long idle periods or before critical actions.
|
|
750
763
|
- **Details**:
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
764
|
+
- When using persistent login or "Remember Me":
|
|
765
|
+
- Require re-login after X hours (e.g., 12h, 24h)
|
|
766
|
+
- Re-authenticate after inactivity (e.g., 30 mins)
|
|
767
|
+
- Require password or 2FA for sensitive actions (password change, payments)
|
|
768
|
+
- For JWT:
|
|
769
|
+
- Use short-lived tokens with secure refresh logic
|
|
757
770
|
- **Applies to**: All languages
|
|
758
771
|
- **Tools**: Manual Review, Static Analysis (JWT expiry, session policy), Security Test, SonarQube (custom rule)
|
|
759
772
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -765,27 +778,27 @@
|
|
|
765
778
|
|
|
766
779
|
- **Objective**: Ensure attackers cannot continue using old session tokens after a password change. Enforce correct access control after sensitive updates.
|
|
767
780
|
- **Details**:
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
781
|
+
- On password change:
|
|
782
|
+
- Invalidate all other active sessions (except current if necessary)
|
|
783
|
+
- Clear all session tokens from DB, Redis, or memory
|
|
784
|
+
- For JWT: use token versioning or timestamp to revoke old tokens
|
|
785
|
+
- Require re-login across all devices
|
|
773
786
|
- **Applies to**: All languages
|
|
774
787
|
- **Tools**: Manual Review, Static Analysis (Token Revocation Logic), SonarQube (custom rule)
|
|
775
788
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
776
|
-
- **Version**: 1.
|
|
777
|
-
- **Status**:
|
|
789
|
+
- **Version**: 1.1
|
|
790
|
+
- **Status**: draft
|
|
778
791
|
- **Severity**: medium
|
|
779
792
|
|
|
780
793
|
### 📘 Rule S044 – Require re-authentication before modifying critical information
|
|
781
794
|
|
|
782
795
|
- **Objective**: Prevent unauthorized changes to critical information when the session is not fully authenticated. Protect users in half-open session states.
|
|
783
796
|
- **Details**:
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
797
|
+
- When updating sensitive information (password, email, payment method, access permissions, etc.):
|
|
798
|
+
- Require password re-entry or two-factor authentication (2FA)
|
|
799
|
+
- Do not store any information in session unless fully authenticated
|
|
800
|
+
- If the session is in a temporary state (e.g., OTP not completed or social login not finished), **block access to sensitive resources**
|
|
801
|
+
- On the frontend: redirect the user to the re-authentication screen
|
|
789
802
|
- **Applies to**: All languages
|
|
790
803
|
- **Tools**: Manual Review, Static Analysis (flow check), Security Test, SonarQube (custom rule)
|
|
791
804
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -797,12 +810,12 @@
|
|
|
797
810
|
|
|
798
811
|
- **Objective**: Prevent brute-force and credential stuffing attacks by limiting failed login attempts and introducing friction for suspicious behavior.
|
|
799
812
|
- **Details**:
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
813
|
+
- Implement one or more of the following:
|
|
814
|
+
- Limit failed login attempts by IP or account (Rate Limiting)
|
|
815
|
+
- Soft lockout: temporarily lock account (e.g., 15 minutes after 5 failed attempts)
|
|
816
|
+
- Trigger CAPTCHA or 2FA after multiple failed attempts
|
|
817
|
+
- Check passwords against breached password lists (e.g., HaveIBeenPwned, zxcvbn)
|
|
818
|
+
- Log all failed login attempts for monitoring and alerting
|
|
806
819
|
- **Applies to**: All languages
|
|
807
820
|
- **Tools**: Manual Review, Static Analysis, OWASP ZAP, Custom Logging, SonarQube (custom rule)
|
|
808
821
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -814,34 +827,34 @@
|
|
|
814
827
|
|
|
815
828
|
- **Objective**: Alert users to sensitive actions to detect potential compromise and allow timely intervention.
|
|
816
829
|
- **Details**:
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
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
|
|
824
837
|
- **Applies to**: All languages
|
|
825
838
|
- **Tools**: Manual Review, Security Test, Notification Audit, SonarQube (custom rule)
|
|
826
839
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
827
|
-
- **Version**: 1.
|
|
828
|
-
- **Status**:
|
|
840
|
+
- **Version**: 1.1
|
|
841
|
+
- **Status**: draft
|
|
829
842
|
- **Severity**: medium
|
|
830
843
|
|
|
831
844
|
### 📘 Rule S047 – Secure temporary passwords and activation codes
|
|
832
845
|
|
|
833
846
|
- **Objective**: Ensure that temporary passwords and activation codes are secure, unpredictable, single-use, and time-limited.
|
|
834
847
|
- **Details**:
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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
|
|
845
858
|
- **Applies to**: All languages
|
|
846
859
|
- **Tools**: Manual Review, Static Analysis, Audit Flow, SonarQube (custom rule)
|
|
847
860
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -853,12 +866,12 @@
|
|
|
853
866
|
|
|
854
867
|
- **Objective**: Ensure the current user password is never revealed or sent in any step of the password reset process.
|
|
855
868
|
- **Details**:
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
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
|
|
862
875
|
- **Applies to**: All languages
|
|
863
876
|
- **Tools**: Manual Review, Penetration Test, SonarQube (custom rule)
|
|
864
877
|
- **Principles**: SECURITY
|
|
@@ -870,12 +883,12 @@
|
|
|
870
883
|
|
|
871
884
|
- **Objective**: Ensure that OTPs, reset tokens, and activation links expire quickly to reduce risk of interception or reuse.
|
|
872
885
|
- **Details**:
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
886
|
+
- Authentication codes must:
|
|
887
|
+
- Expire quickly (⏱ recommended: **5–10 minutes**)
|
|
888
|
+
- Be **automatically invalidated** after expiration
|
|
889
|
+
- Be **one-time use only**
|
|
890
|
+
- Do not accept expired or reused codes
|
|
891
|
+
- For critical actions (reset password, email verification), require re-authentication after code validation
|
|
879
892
|
- **Applies to**: All languages
|
|
880
893
|
- **Tools**: Manual Review, Static Analysis, SonarQube (custom rule)
|
|
881
894
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -887,16 +900,16 @@
|
|
|
887
900
|
|
|
888
901
|
- **Objective**: Prevent attackers from predicting or forging session tokens by ensuring sufficient length, entropy, and cryptographic safety.
|
|
889
902
|
- **Details**:
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
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
|
|
900
913
|
- **Applies to**: All languages
|
|
901
914
|
- **Tools**: Manual Review, Static Analysis, SonarQube (custom rule)
|
|
902
915
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -908,12 +921,12 @@
|
|
|
908
921
|
|
|
909
922
|
- **Objective**: Allow users to use strong passphrases while preventing resource abuse from excessively long inputs.
|
|
910
923
|
- **Details**:
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
924
|
+
- Accept passwords with **12–64 characters**
|
|
925
|
+
- Support strong passphrases (e.g. `correct horse battery staple`)
|
|
926
|
+
- **Reject passwords >128 characters** to:
|
|
927
|
+
- Prevent DoS from large inputs
|
|
928
|
+
- Avoid poor hash performance on long strings
|
|
929
|
+
- Optionally warn users if password <12 characters
|
|
917
930
|
- **Applies to**: All languages
|
|
918
931
|
- **Tools**: Manual Review, Static Analysis, Unit Test, SonarQube (custom rule)
|
|
919
932
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -925,10 +938,10 @@
|
|
|
925
938
|
|
|
926
939
|
- **Objective**: Ensure OTPs are strong enough to resist brute-force or statistical guessing attacks.
|
|
927
940
|
- **Details**:
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
941
|
+
- OTP must have minimum **20-bit entropy**, equivalent to **6-digit random numbers** (`000000–999999`)
|
|
942
|
+
- Generate OTPs using **CSPRNG**
|
|
943
|
+
- Avoid using `Math.random()` or insecure generators
|
|
944
|
+
- Alphanumeric or longer OTPs increase entropy and are preferred
|
|
932
945
|
- **Applies to**: All languages
|
|
933
946
|
- **Tools**: Manual Review, Unit Test, Static Analysis, SonarQube (custom rule)
|
|
934
947
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -940,15 +953,15 @@
|
|
|
940
953
|
|
|
941
954
|
- **Objective**: Ensure OTPs are secure against spoofing and replay attacks by using safe, standard algorithms.
|
|
942
955
|
- **Details**:
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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)
|
|
952
965
|
- **Applies to**: All languages
|
|
953
966
|
- **Tools**: Manual Review, Unit Test, Static Analysis, SonarQube (custom rule)
|
|
954
967
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -960,10 +973,10 @@
|
|
|
960
973
|
|
|
961
974
|
- **Objective**: Prevent brute-force attacks and ensure traceability and accountability in auditing. Avoid predictable, shared accounts lacking identity association.
|
|
962
975
|
- **Details**:
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
976
|
+
- Do not use default or common account names (e.g., admin, root, sa, test, guest, etc.).
|
|
977
|
+
- Each user must have a separate account with role-based access control.
|
|
978
|
+
- Force password change on first use or system initialization.
|
|
979
|
+
- The system must log all login attempts and resource access per specific user.
|
|
967
980
|
- **Applies to**: All languages
|
|
968
981
|
- **Tools**: Manual Review, CI Security Audit, IAM Policy Scan, SonarQube (custom rule)
|
|
969
982
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -975,10 +988,10 @@
|
|
|
975
988
|
|
|
976
989
|
- **Objective**: Prevent attacks via malformed or improperly handled data by validating incoming data format (e.g., JSON, XML).
|
|
977
990
|
- **Details**:
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
991
|
+
- REST services must check the Content-Type HTTP header to ensure data format matches expectations (e.g., `application/json`, `application/xml`).
|
|
992
|
+
- Reject requests with incorrect or unsupported Content-Type.
|
|
993
|
+
- Avoid processing `text/plain`, `multipart/form-data` unless explicitly required.
|
|
994
|
+
- Log rejected requests due to invalid Content-Type to detect attacks or client issues early.
|
|
982
995
|
- **Applies to**: All languages
|
|
983
996
|
- **Tools**: Manual Review, API Gateway Config, Static Code Analysis (Semgrep), SonarQube (custom rule)
|
|
984
997
|
- **Principles**: SECURITY
|
|
@@ -990,10 +1003,10 @@
|
|
|
990
1003
|
|
|
991
1004
|
- **Objective**: Prevent attackers from injecting fake log entries that distort tracking or exploit log analysis systems.
|
|
992
1005
|
- **Details**:
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1006
|
+
- Do not log user input directly without sanitization.
|
|
1007
|
+
- Escape special characters like: `\n`, `\r`, `%`, `\t`, `"`, `'`, `[`, `]`, etc.
|
|
1008
|
+
- Use structured logging (e.g., JSON) to detect anomalies more easily.
|
|
1009
|
+
- Avoid `string concatenation` when writing log entries with user input.
|
|
997
1010
|
- **Applies to**: All languages
|
|
998
1011
|
- **Tools**: SonarQube, Semgrep, Manual Review
|
|
999
1012
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -1005,10 +1018,10 @@
|
|
|
1005
1018
|
|
|
1006
1019
|
- **Objective**: Ensure consistent, accurate log timestamps to support auditing, investigation, and cross-system comparison.
|
|
1007
1020
|
- **Details**:
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1021
|
+
- Always use UTC timezone for logging to avoid issues with local offsets or daylight saving.
|
|
1022
|
+
- Configure system time sync via NTP (Network Time Protocol).
|
|
1023
|
+
- Verify all backends, logging middleware, and log collectors use standard formats (`ISO 8601`, `UTC`, `RFC3339`, etc.).
|
|
1024
|
+
- Helps unify log data across services and regions.
|
|
1012
1025
|
- **Applies to**: All languages
|
|
1013
1026
|
- **Tools**: Manual Review, Audit Logging Middleware, Centralized Logging Tools (ELK, Fluentd, Datadog), SonarQube (custom rule)
|
|
1014
1027
|
- **Principles**: CODE_QUALITY, SECURITY
|
|
@@ -1020,16 +1033,16 @@
|
|
|
1020
1033
|
|
|
1021
1034
|
- **Objective**: Prevent Server-Side Request Forgery (SSRF) and protect internal networks or cloud metadata services from unauthorized access via untrusted input.
|
|
1022
1035
|
- **Details**:
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1036
|
+
- Always validate URLs or network addresses from client input or HTTP metadata.
|
|
1037
|
+
- Apply allow lists for:
|
|
1038
|
+
- Valid protocols: only allow `https`, `http`
|
|
1039
|
+
- Specific domains or trusted internal IP ranges
|
|
1040
|
+
- Allowed ports (avoid sensitive ones like 22, 3306, 6379, etc.)
|
|
1041
|
+
- Block access to:
|
|
1042
|
+
- `127.0.0.1`, `::1` (localhost)
|
|
1043
|
+
- `169.254.169.254` (AWS metadata)
|
|
1044
|
+
- `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` if not needed
|
|
1045
|
+
- Limit timeouts and disallow redirects unless required.
|
|
1033
1046
|
- **Applies to**: All languages
|
|
1034
1047
|
- **Tools**: SonarQube, Manual Review, Burp Suite Test
|
|
1035
1048
|
- **Principles**: SECURITY
|
|
@@ -1041,15 +1054,15 @@
|
|
|
1041
1054
|
|
|
1042
1055
|
- **Objective**: Reduce risks from the server making outbound requests to untrusted systems (SSRF, malicious downloads, data leaks).
|
|
1043
1056
|
- **Details**:
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
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.
|
|
1050
1063
|
- **Applies to**: All languages
|
|
1051
1064
|
- **Tools**: Manual Config Review, Firewall/Proxy Logs, CloudTrail, Burp Suite Test, SonarQube (custom rule)
|
|
1052
1065
|
- **Principles**: SECURITY
|
|
1053
|
-
- **Version**: 1.
|
|
1054
|
-
- **Status**:
|
|
1066
|
+
- **Version**: 1.1
|
|
1067
|
+
- **Status**: draft
|
|
1055
1068
|
- **Severity**: low
|