-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdrupal-logging-failures.mdc
More file actions
105 lines (89 loc) · 6 KB
/
Copy pathdrupal-logging-failures.mdc
File metadata and controls
105 lines (89 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
description: Detect and prevent security logging and monitoring failures in Drupal as defined in OWASP Top 10:2021-A09
globs: *.php, *.install, *.module, *.inc, *.theme, *.yml
alwaysApply: false
---
# Drupal Security Logging and Monitoring Failures Standards (OWASP A09:2021)
This rule enforces security best practices to prevent logging and monitoring failures in Drupal applications, as defined in OWASP Top 10:2021-A09.
## Rule Details
- **Name:** drupal_logging_failures
- **Description:** Detect and prevent security logging and monitoring failures in Drupal as defined in OWASP Top 10:2021-A09
## Filters
- file extension pattern: `\\.(php|inc|module|install|theme|yml)$`
- file path pattern: `.*`
## Enforcement Checks
- Conditions:
- pattern `(delete|update|create|execute|grant|revoke|config|schema).*function[^}]*\\{(?![^}]*(log|watchdog|logger))` – Critical operations should include logging. Implement proper logging for security-relevant actions.
- Pattern 1: Missing critical event logging
- pattern `@include|@require|@eval|error_reporting\\(0\\)|ini_set\\(['\"](mdc:display_errors|log_errors)['\"],\\s*['\"]0['\"]\\)` – Avoid suppressing errors and warnings. Implement proper error handling and logging instead.
- Pattern 2: Suppressed error logging
- pattern `catch\\s*\\([^{]*\\)\\s*\\{(?![^}]*log|[^}]*watchdog|[^}]*logger)` – Exceptions should be properly logged, especially in security-critical sections.
- Pattern 3: Improper exception handling without logging
- pattern `dblog\\.settings\\.yml|syslog\\.settings\\.yml|logging\\.settings\\.yml` – Ensure logging is properly configured and not disabled. Verify log verbosity and retention policies.
- Pattern 4: Disabled watchdog
- pattern `(login|authenticate|logout|password).*function[^}]*\\{(?![^}]*(log|watchdog|logger))` – Authentication events should always be logged for security monitoring and auditing.
- Pattern 5: Missing authentication event logging
- pattern `AccessResult::(allowed|forbidden|neutral)\\([^)]*\\)(?![^;]*(log|watchdog|logger))` – Consider logging significant access control decisions, especially denials, for security monitoring.
- Pattern 6: Failure to log access control decisions
- pattern `(file_save|file_delete|file_move|file_copy)[^;]*;(?![^;]*(log|watchdog|logger))` – File operations should be logged, especially for security-sensitive files.
- Pattern 7: Missing logging in file operations
- pattern `(\\->log|watchdog)\\([^,)]*,[^,)]*\\)` – Log messages should include sufficient context and detail for effective security monitoring.
- Pattern 8: Insufficient detail in log messages
- pattern `\\$config->set\\([^;]*;(?![^;]*(log|watchdog|logger))` – Configuration changes should be logged to maintain an audit trail and detect unauthorized changes.
- Pattern 9: Failure to log configuration changes
- pattern `class\\s+[a-zA-Z0-9_]+Resource.+\\{[^}]*function\\s+[a-zA-Z0-9_]+\\([^{]*\\)\\s*\\{(?![^}]*(log|watchdog|logger))` – API endpoint access should be logged for security monitoring, especially for sensitive operations.
- Pattern 10: Missing logs for API access
## Suggestions
- Guidance:
**Drupal Security Logging & Monitoring Best Practices:**
1. **Comprehensive Logging Implementation:**
- Use Drupal's Logger Factory service: `\Drupal::logger('module_name')`
- Implement proper log levels: emergency, alert, critical, error, warning, notice, info, debug
- Include context in log messages with relevant identifiers and information
- Log security-relevant events consistently across the application
- Structure log messages to facilitate automated analysis
2. **Critical Events to Log:**
- Authentication events (login attempts, failures, logouts)
- Access control decisions (particularly denials)
- All administrative actions
- Data modification operations on sensitive information
- Configuration and settings changes
- File operations (uploads, downloads of sensitive content)
- API access and usage
3. **Logging Configuration:**
- Configure appropriate log retention periods based on security requirements
- Implement log rotation to maintain performance
- Consider using syslog for centralized logging
- Protect log files from unauthorized access and modification
- Configure appropriate verbosity for different environments
4. **Monitoring Implementation:**
- Define security-relevant log patterns to monitor
- Implement log aggregation and analysis
- Set up alerts for suspicious activity patterns
- Establish response procedures for security events
- Consider integration with SIEM solutions
5. **Error Handling:**
- Log exceptions with appropriate error levels
- Include stack traces in development but not production
- Implement custom error handlers that ensure proper logging
- Avoid suppressing errors that might indicate security issues
- Monitor for patterns in error logs that could indicate attacks
## Validation Checks
- Conditions:
- pattern `\\\\Drupal::logger\\([^)]+\\)->\\w+\\(|\\$this->logger->\\w+\\(` – Using Drupal's logger service correctly.
- Check 1: Proper logger usage
- pattern `->\\w+\\([^,]+,\\s*[^,]+,\\s*\\[` – Including context information in log messages.
- Check 2: Context in log messages
- pattern `dblog\\.settings|syslog\\.settings|logging\\.yml` – Configuring logging appropriately.
- Check 3: Logging configuration
- pattern `catch[^{]*\\{[^}]*logger|catch[^{]*\\{[^}]*watchdog|catch[^{]*\\{[^}]*log` – Properly logging exceptions.
- Check 4: Exception logging
## Metadata
- Priority: high
- Version: 1.1
- Tags: security, drupal, logging, monitoring, owasp, language:php, framework:drupal, category:security, subcategory:logging, standard:owasp-top10, risk:a09-logging-monitoring
## References
- https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/
- https://www.drupal.org/docs/8/api/logging-api/overview
- https://www.drupal.org/docs/develop/security-in-drupal/writing-secure-code-for-drupal
- https://www.drupal.org/docs/8/modules/syslog