Mitigation Strategy: Data Scrubbing/Masking Hooks
Mitigation Strategy: Implement Data Scrubbing/Masking Hooks
- Description:
- Identify Sensitive Data: List all types of sensitive data your application might log.
- Create a Custom Logrus Hook: Develop a Go struct that implements the
logrus.Hook
interface. - Implement Scrubbing Logic in Hook: Within the
Fire
method of your hook, iterate throughlogrus.Fields
, identify sensitive fields by name or value patterns, and redact or remove them. - Register the Hook with Logrus: Add your custom hook to
logrus
usinglogrus.AddHook(&YourCustomHook{})
. - Test Thoroughly: Verify the hook correctly scrubs sensitive data in development/staging.
- Threats Mitigated:
- Sensitive Data Exposure in Logs (High Severity)
- Impact:
- Sensitive Data Exposure in Logs (High Reduction)
- Currently Implemented: Yes, implemented in production logging pipeline with a custom hook redacting specific fields and patterns.
- Missing Implementation: Needs full implementation in development and staging environments. Regular review and update of sensitive field lists and patterns are required across all environments.
Mitigation Strategy: Structured Logging with Field-Level Control
Mitigation Strategy: Employ Structured Logging with Field-Level Control
- Description:
- Use
logrus.WithFields()
Consistently: Train developers to uselogrus.WithFields(logrus.Fields{...})
for logging events with dynamic data. - Log Only Necessary Fields: Select and log only essential fields from complex objects, avoiding logging entire objects directly.
- Sanitize Field Values (logrus context): Sanitize field values before adding them to
logrus.WithFields()
if needed for consistency or basic cleaning within the logging context. - Avoid String Formatting for Dynamic Data in Log Messages: Discourage
fmt.Sprintf
or similar for log messages with dynamic data to prevent log injection risks withinlogrus
usage.
- Use
- Threats Mitigated:
- Sensitive Data Exposure in Logs (Medium Severity)
- Log Injection Vulnerabilities (Medium Severity)
- Impact:
- Sensitive Data Exposure in Logs (Medium Reduction)
- Log Injection Vulnerabilities (Medium Reduction)
- Currently Implemented: Partially implemented. Developers are generally aware of
logrus.WithFields()
, but consistent enforcement is lacking. - Missing Implementation: Enforce
logrus.WithFields()
usage via code review guidelines and linters. Developer training on securelogrus
practices is needed.
Mitigation Strategy: Control Log Levels in Production
Mitigation Strategy: Control Log Levels in Production
- Description:
- Set Production Log Level: Configure
logrus
log level in production toINFO
,WARN
,ERROR
, orFATAL
. AvoidDEBUG
orTRACE
in production unless temporarily needed for specific debugging. - Externalize Log Level Configuration (logrus context): Use environment variables or configuration files to set the
logrus
log level, allowing adjustments without code changes. - Monitor Production Log Volume (logrus context): Monitor log volume and adjust
logrus
log levels or logging logic if volume is unexpectedly high. - Document Log Level Policy (logrus context): Create and document a policy for
logrus
log levels in different environments.
- Set Production Log Level: Configure
- Threats Mitigated:
- Sensitive Data Exposure in Logs (Medium Severity)
- Excessive Logging and Resource Exhaustion (Medium Severity)
- Impact:
- Sensitive Data Exposure in Logs (Medium Reduction)
- Excessive Logging and Resource Exhaustion (Medium Reduction)
- Currently Implemented: Yes, implemented in production. Log level is set to
INFO
via environment variable forlogrus
in production. - Missing Implementation: Ensure consistent
logrus
log level configuration across all services. Educate developers on the implications ofDEBUG
/TRACE
levels in production within thelogrus
context.
Mitigation Strategy: Parameterize Log Messages with Structured Logging (logrus specific)
Mitigation Strategy: Parameterize Log Messages with Structured Logging (logrus specific)
- Description:
- Always Use
logrus.WithFields()
(logrus context): Reinforce usinglogrus.WithFields()
for all log messages with dynamic data. - Separate Message Template from Data (logrus context): Ensure the core log message string is static, and dynamic data is passed as fields to
logrus.WithFields()
. - Prohibit String Concatenation in Log Messages (logrus context): Explicitly prohibit string concatenation or formatting functions directly within
logrus
log message strings when including dynamic data.
- Always Use
- Threats Mitigated:
- Log Injection Vulnerabilities (High Severity)
- Impact:
- Log Injection Vulnerabilities (High Reduction)
- Currently Implemented: Partially implemented. Developers are generally aware of
logrus.WithFields()
, but consistent enforcement withinlogrus
usage is lacking. - Missing Implementation: Stricter code reviews, linters to detect insecure
logrus
logging patterns (string concatenation inlogrus
messages), and developer training focused on log injection prevention withinlogrus
usage.
Mitigation Strategy: Configure Appropriate Log Levels (Resource Exhaustion - logrus specific)
Mitigation Strategy: Configure Appropriate Log Levels (Resource Exhaustion - logrus specific)
- Description:
- Environment-Specific Log Levels (logrus context): Define different
logrus
log levels for development, staging, and production. Use more verbose levels in development and less verbose in production. - Application Component Log Levels (logrus context): If possible, configure
logrus
log levels at a granular level, per application component, to fine-tune verbosity. - Regular Review and Adjustment (logrus context): Periodically review
logrus
log levels and adjust based on monitoring, performance, and debugging needs related tologrus
logging volume.
- Environment-Specific Log Levels (logrus context): Define different
- Threats Mitigated:
- Excessive Logging and Resource Exhaustion (Medium Severity) - specifically related to
logrus
output volume
- Excessive Logging and Resource Exhaustion (Medium Severity) - specifically related to
- Impact:
- Excessive Logging and Resource Exhaustion (Medium Reduction) - specifically related to
logrus
output volume
- Excessive Logging and Resource Exhaustion (Medium Reduction) - specifically related to
- Currently Implemented: Partially implemented. Environment-specific
logrus
log levels are used for production and staging, but development environments are less consistent. - Missing Implementation: Standardize
logrus
log level configurations across all environments. Explore granular component-levellogrus
log level settings. Monitor log volume and resource usage related tologrus
to proactively address excessive logging.
Mitigation Strategy: Externalize Log Configuration (logrus specific)
Mitigation Strategy: Externalize Log Configuration (logrus specific)
- Description:
- Use Environment Variables or Configuration Files (logrus context): Configure
logrus
settings (log level, formatter, output destination, hooks) using environment variables, configuration files, or a configuration management system. - Avoid Hardcoding Configuration (logrus context): Remove hardcoded
logrus
configuration from the application code. - Centralized Configuration Management (Optional - logrus context): For larger deployments, consider centralized configuration management to manage
logrus
configuration across services.
- Use Environment Variables or Configuration Files (logrus context): Configure
- Threats Mitigated:
- Configuration Management Issues (Low Severity) - specifically related to
logrus
configuration - Inconsistent Logging (Low Severity) - specifically related to
logrus
configuration across environments
- Configuration Management Issues (Low Severity) - specifically related to
- Impact:
- Configuration Management Issues (Low Reduction) - specifically related to
logrus
configuration - Inconsistent Logging (Low Reduction) - specifically related to
logrus
configuration
- Configuration Management Issues (Low Reduction) - specifically related to
- Currently Implemented: Yes, implemented for log level in production and staging using environment variables for
logrus
. - Missing Implementation: More comprehensive externalization is needed for
logrus
. Currently, only log level is fully externalized forlogrus
. Externalize formatter, output destination, and hook configurations forlogrus
for greater flexibility and consistency.