Skip to content

fix: Prevent path traversal in nested stack TemplateURL resolution - #4640

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
kddejong:fix/nested-stack-path-traversal
Aug 18, 2026
Merged

fix: Prevent path traversal in nested stack TemplateURL resolution#4640
kddejong merged 1 commit into
aws-cloudformation:mainfrom
kddejong:fix/nested-stack-path-traversal

Conversation

@kddejong

Copy link
Copy Markdown
Contributor

Summary

Add path confinement checks 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 (e.g., /etc/passwd)
  • Ensure resolved paths stay within os.getcwd() after normalization
  • Add unit tests for path traversal scenarios

Behavior

When a TemplateURL path would resolve outside the current working directory, cfn-lint gracefully falls back to the default Outputs.* 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.

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

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.59%. Comparing base (0ce7cfd) to head (98967d2).
⚠️ Report is 1 commits behind head on main.

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              
Flag Coverage Δ
unittests 94.59% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 2790418 into aws-cloudformation:main Aug 18, 2026
21 checks passed
@kddejong
kddejong deleted the fix/nested-stack-path-traversal branch August 18, 2026 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant