🐛 fix-sanitize plugin manifest name in plugin-manager add to prevent p… - #671
🐛 fix-sanitize plugin manifest name in plugin-manager add to prevent p…#671RanWurmbrand wants to merge 2 commits into
Conversation
…ath traversal and plugin override Signed-off-by: Ran Wurmbrand <rwurmbra@redhat.com>
📝 WalkthroughWalkthroughPlugin binary installation now validates manifest filenames for path traversal and existing targets before performing retrieval or filesystem writes. ChangesPlugin installation validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
Test Coverage ReportTotal: 49.1% Per-package coverage
Full function-level detailsPosted by CI |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@cmd/plugin-manager/add/add.go`:
- Around line 217-221: Update the file creation logic in downloadBinary to
include os.O_EXCL alongside the existing creation flags, so opening the target
fails atomically if a file or symlink appears during download; also use
executable mode 0755 instead of 0777.
- Around line 205-215: The validateFileInput function must use os.Lstat to
inspect the destination without following symlinks, and treat any error other
than os.ErrNotExist as a validation failure. Preserve the existing
duplicate-file error for an existing path, while rejecting broken symlinks and
propagating unexpected filesystem errors before installation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 407cee60-227b-49d0-9410-e2eae0785a98
📒 Files selected for processing (1)
cmd/plugin-manager/add/add.go
aufi
left a comment
There was a problem hiding this comment.
Thanks for finding this problem and creating PR! Left few comments.
Use filepath.Base pattern instead of a character blocklist, reject backslashes explicitly, use os.Lstat so symlinks are not followed, fail closed on unexpected stat errors, create the binary with O_EXCL and 0755 perms, and add unit tests for validateFileInput. Signed-off-by: Ran Wurmbrand <rwurmbra@redhat.com>
|
@aufi let me know if these changes is what you had in mind |
closes: #670
Summary
The
plugin-manager addcommand uses thenamefield from the plugin manifest as the binary filename without any sanitization. This allows a malicious plugin repository to:nameto an already-installed plugin (e.g.OpenShiftPlugin), silently replacing it with a trojanized versionnamecontaining../../sequences escapes the plugins directory, writing an executable (0777 permissions) to arbitrary pathsRoot Cause
In
downloadBinary(),value.Namefrom the manifest YAML is passed directly toos.OpenFileas the filename with no validation.Fix
Added a
validateFileInput()function that runs before any download:/,\, or..— blocks path traversalPoC
Full end-to-end proof of concept: https://github.com/RanWurmbrand/compromised-plugins
Test plan
crane plugin-manager add EvilPluginwith a manifest name containing../../is rejected with an errorcrane plugin-manager add CoolPluginwith a manifest name matching an existing plugin (OpenShiftPlugin) is rejected with an errorSummary by CodeRabbit