fix: Prevent path traversal in nested stack TemplateURL resolution - #4640
Merged
kddejong merged 1 commit intoAug 18, 2026
Merged
Conversation
Add path confinement checks to _nested_stack_get_atts to prevent reading arbitrary files outside the current working directory when resolving relative TemplateURL paths for nested CloudFormation stacks. Changes: - Block absolute paths specified in TemplateURL - Ensure resolved paths stay within os.getcwd() - Add unit tests for path traversal scenarios This is a defense-in-depth measure. When a path escapes the allowed boundary, cfn-lint gracefully falls back to the default Outputs.* pattern rather than attempting to read the file.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4640 +/- ##
==========================================
+ Coverage 94.58% 94.59% +0.01%
==========================================
Files 432 432
Lines 15417 15422 +5
Branches 2986 2988 +2
==========================================
+ Hits 14582 14589 +7
+ Misses 456 454 -2
Partials 379 379
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Add path confinement checks to prevent reading arbitrary files outside the current working directory when resolving relative
TemplateURLpaths for nested CloudFormation stacks.Changes
TemplateURL(e.g.,/etc/passwd)os.getcwd()after normalizationBehavior
When a
TemplateURLpath would resolve outside the current working directory, cfn-lint gracefully falls back to the defaultOutputs.*pattern rather than attempting to read the file. This maintains compatibility while adding defense-in-depth.Allowed:
./nested/child.yaml../sibling/child.yaml(if result is still under cwd)Blocked:
../../../../etc/passwd(escapes cwd)/etc/passwd(absolute path)User Impact
Users running cfn-lint with nested stacks in sibling directories should run from the common parent directory to ensure all templates are within the cwd boundary.