security: CWE-94: Prevent YAML injection via environment variables — VC-53766#657
Open
torresashjiancyber wants to merge 1 commit into
Open
security: CWE-94: Prevent YAML injection via environment variables — VC-53766#657torresashjiancyber wants to merge 1 commit into
torresashjiancyber wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix CWE-94 vulnerability that allowed YAML structure injection through unsanitized environment variables in playbook template parsing.
Finding
CWE-94 / CWE-74: Improper Control of Generation of Code
CVSS: 7.3 (CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N)
The
parseConfigTemplate()function inpkg/playbook/app/parser/reader.gosubstituted raw environment variable values fromos.LookupEnv()directly into YAML byte streams before unmarshalling, without YAML-escaping. This allowed an attacker who controls a referenced environment variable to inject newlines, close the enclosing scalar, and append arbitrary YAML structure that could reachutil.ExecuteScript()→exec.Command("sh","-c", afterAction)as the playbook process user.Remediation
Added
yamlSafeScalar()helper function that strips carriage returns (\r) and newlines (\n) from all values before they are substituted into the YAML template:Envtemplate function withyamlSafeScalar()Verification
Changes limited to
pkg/playbook/app/parser/reader.go:The fix applies minimal sanitization focused solely on preventing YAML structure injection via the
Envtemplate function.