[code-scanning-fix] Fix go/unsafe-quoting: Remove unused environment variable with unsafe JSON embedding #11424
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: Unsafe JSON Quoting in YAML Environment Variable
Alert Number: #538
Severity: Critical
Rule: go/unsafe-quoting
CWE: CWE-78, CWE-89, CWE-94
Vulnerability Description
CodeQL detected unsafe quoting in
pkg/workflow/update_project_job.goat line 47. The code was embedding JSON data into a YAML environment variable usingfmt.Sprintfwith%qformatting:JSON encoding does not escape single quotes, which could break YAML parsing or be exploited for injection attacks if the JSON contains malicious quote characters.
Location
pkg/workflow/update_project_job.gobuildUpdateProjectJobRoot Cause Analysis
The vulnerability existed in code that created an unused environment variable
GH_AW_PROJECT_VIEWS. Investigation revealed:GH_AW_PROJECT_VIEWSenvironment variable was never consumed by any JavaScript codeGH_AW_SAFE_OUTPUTS_PROJECT_HANDLER_CONFIG(seecompiler_safe_outputs_config.go:602-608)%qescaping at line 638Fix Applied
Removed the unused code entirely (lines 42-52 in
update_project_job.go):Changes Made:
GH_AW_PROJECT_VIEWSenvironment variable generationencoding/jsonimportWhy This Fix is Correct:
GH_AW_SAFE_OUTPUTS_PROJECT_HANDLER_CONFIGSecurity Best Practices
GH_AW_SAFE_OUTPUTS_PROJECT_HANDLER_CONFIG) instead of scattered environment variablesTesting Considerations
GH_AW_SAFE_OUTPUTS_PROJECT_HANDLER_CONFIGVerification
After merging, verify:
Automated by: Code Scanning Fixer Workflow
Run ID: 21271253990
Commit: 315dfd1