-
Notifications
You must be signed in to change notification settings - Fork 2.5k
backport of #15477- fix(security): Replace YAML.load_stream to prevent deserialization attacks (CHEF-3854) #15466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…(CHEF-3854) Replaced insecure YAML.load_stream calls with safe text pattern matching to prevent arbitrary code execution via YAML deserialization attacks. The vulnerability allowed malicious YAML files with deserialization gadgets Changes: - knife/lib/chef/knife/yaml_convert.rb: Count '---' separators with regex - lib/chef/recipe.rb: Count '---' separators with regex This maintains all existing functionality (multi-document detection, error messages) while eliminating the deserialization attack vector. The actual YAML parsing already uses YAML.safe_load() which is secure. Issue: CHEF-3854 Signed-off-by: nikhil2611 <nikhilgupta2102@gmail.com>
Signed-off-by: nikhil2611 <nikhilgupta2102@gmail.com>
|
jaymzh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make changes on main and backport, per standard policy. Do not change chef-18 directly unless the bug only affects Chef 18.
|
Hey @jaymzh , We added this security fix in chef-18 to get the Knife security update released, so we can ship the latest Knife version in Chef Workstation. |
jaymzh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Would be really silly if we fixed a security issue that then regressed in 19. :)



Summary
This PR fixes a security vulnerability (CHEF-3854) where
YAML.load_stream()was used to check for multi-document YAML files, allowing arbitrary code execution via deserialization attacks.Issue
CHEF-3854 - Chef/Knife YAML Insecure Deserialization through YAML.load_stream
Changes
knife/lib/chef/knife/yaml_convert.rb- ReplacedYAML.load_stream()with safe regex pattern matchinglib/chef/recipe.rb- ReplacedYAML.load_stream()with safe regex pattern matchingSecurity Impact
Fix: Replaced with
yaml_contents.scan(/^---\s*$/).lengthwhich simply counts document separator patterns without any deserialization, eliminating the attack vector.Tests & Coverage
Changed lines: 4; Existing tests verify multi-document detection still works correctly.
Functionality Preserved
---separators)Risk & Mitigations
Risk Classification: Low
Rationale: Localized change to YAML parsing validation logic. The actual parsing already used
YAML.safe_load()which is secure - we only fixed the pre-check that was vulnerable.Mitigation: Change only affects the multi-document detection mechanism, not the core YAML parsing functionality.
Rollback Strategy:
git revert 0cb36ea0ecAI Assistance
This work was completed with AI assistance following Progress AI policies.
DCO
All commits include Developer Certificate of Origin sign-off.