fix(scaffold): resolve relative write-target directories consistently - #2855
Conversation
validateWriteTarget compared an absolutized realBase against a still-relative realDir (filepath.EvalSymlinks on a relative path stays relative), so every write with a relative target directory (including the CLI's own default ./my-project) was rejected as a false-positive path traversal. Reuse ResolveAndCleanBasePath for both sides of the comparison. Closes #2851 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
📝 WalkthroughWalkthrough
ChangesRelative write-target handling
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2855 +/- ##
=======================================
Coverage 82.09% 82.10%
=======================================
Files 1802 1802
Lines 175133 175133
=======================================
+ Hits 143779 143786 +7
+ Misses 23589 23581 -8
- Partials 7765 7766 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
CodeRabbit (@coderabbitai) full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/generator/engine/templating_test.go (1)
644-676: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAdd a relative-target escape regression case.
The test proves that
./my-projectsucceeds. It does not prove that a relative target still rejects a symlinked directory outside the target. Add a case that assertserrors.Is(err, errUtils.ErrPathTraversal)and confirms that no file appears in the outside directory.As per coding guidelines, new Go features require comprehensive unit tests and negative-path coverage.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/generator/engine/templating_test.go` around lines 644 - 676, Extend TestProcessFile_RelativeTargetPath with a negative case where a directory inside the relative target points via symlink outside the target; assert ProcessFile returns an error matching errUtils.ErrPathTraversal and verify the expected file is not created in the outside directory. Preserve the existing successful relative-target assertions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/generator/engine/templating_test.go`:
- Around line 644-676: Extend TestProcessFile_RelativeTargetPath with a negative
case where a directory inside the relative target points via symlink outside the
target; assert ProcessFile returns an error matching errUtils.ErrPathTraversal
and verify the expected file is not created in the outside directory. Preserve
the existing successful relative-target assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7c9ac448-8679-4775-a88c-d755ec504941
📒 Files selected for processing (2)
pkg/generator/engine/templating.gopkg/generator/engine/templating_test.go
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
These changes were released in v1.225.0-rc.6. |
what
atmos scaffold generateso a relative target directory (e.g. the CLI's own default./my-project) works, instead of rejecting every file withpath traversal not allowed.validateWriteTargetinpkg/generator/engine/templating.gonow resolves the write directory (realDir) through the sameResolveAndCleanBasePathhelper already used for the target base (realBase), instead of a barefilepath.EvalSymlinksthat stays relative for relative inputs.TestProcessFile_RelativeTargetPath, covering a relativetargetPathend-to-end (previous tests only exercised absolutet.TempDir()targets, so this case was never caught).why
realBasewas always absolutized before comparison, butrealDirwas resolved with a barefilepath.EvalSymlinks, which returns a relative path unchanged when given a relative input. Comparing an absolute path against a relative one never matched the containment check, so it fired as a false-positive path traversal on every write whenever the target directory was relative — including the command's own default target.filepath.Dir(fullPath)was already absolute in that case, masking the bug.references
Summary by CodeRabbit
Bug Fixes
./my-project.Tests