[security-fix] Security Fix: Sanitize validation results to prevent clear-text logging of sensitive information (Alert #71) #7329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Security Fix: Clear-text Logging of Sensitive Information
Alert Number: #71
Severity: High
Rule: go/clear-text-logging
CWE: CWE-312, CWE-315, CWE-359
Vulnerability Description
CodeQL detected a data flow vulnerability where sensitive information (secret key names) from the
secretKeysvariable inpkg/workflow/jobs.go:328could flow to JSON output atpkg/cli/compile_orchestrator.go:586.When compilation errors occur, error messages may inadvertently contain secret key names. These error messages are collected in
ValidationResultstructures and marshaled to JSON output without sanitization, potentially exposing sensitive infrastructure details in logs.Root Cause Analysis
The vulnerability exists at the JSON output boundary in
compile_orchestrator.go:fmt.Println(string(jsonBytes))outputs validation results as JSONvalidationResultsstructure contains error and warning messages from various sourcesGITHUB_TOKEN,API_KEY, etc.)Previous fix attempts targeted individual error generation sites but didn't address the root cause at the JSON output boundary.
Fix Applied
Added comprehensive sanitization at the JSON output boundary:
sanitizeErrorMessage()function: Redacts potential secret key names using regex patterns:GITHUB_TOKEN,MY_SECRET_KEY)GitHubToken,ApiKey)[REDACTED]to prevent information disclosuresanitizeValidationResults()function: Applies sanitization to all error and warning messages in validation results before JSON marshalingApplied at both JSON output locations: Lines 644 and 1040 in
compile_orchestrator.goSecurity Best Practices Applied
Testing
Examples
Error message sanitization:
"error with GITHUB_TOKEN"→"error with [REDACTED]""invalid API_KEY secret"→"invalid [REDACTED] secret""GET request failed"→"GET request failed"(common word preserved)"JSON parsing error"→"JSON parsing error"(common word preserved)Why This Fix Will Succeed
This fix addresses the root cause identified in previous attempts (cache memory entry #101):
secretKeysto JSON marshalingFiles Modified
pkg/cli/compile_orchestrator.go:sanitizeErrorMessage()functionsanitizeValidationResults()functionjson.MarshalIndent()callsReferences
Related Issues
This is the comprehensive fix for alert #71 which has been challenging due to CodeQL's sophisticated taint tracking. Previous attempts focused on specific error generation sites, but this fix addresses the root cause by sanitizing at the JSON output boundary where all validation results are marshaled.