-
Notifications
You must be signed in to change notification settings - Fork 0
Add explicit symlink handling in tarball creation #36
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
base: main
Are you sure you want to change the base?
Conversation
Test Coverage Reporttotal: (statements) 77.0% Coverage by function |
Skip symlinks during tarball walk to avoid security risks (symlinks pointing outside repo) and issues with broken symlinks or loops. Log a warning to stderr for each skipped symlink.
ea6d163 to
03449a7
Compare
Add comprehensive test coverage for symlink scenarios: - Symlinks pointing to directories - Broken symlinks pointing to non-existent targets These tests ensure the symlink skip logic handles all edge cases correctly.
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.
Pull request overview
This pull request adds explicit symlink detection and skipping during tarball creation to prevent security risks from symlinks pointing outside the repository, avoid errors from broken symlinks, and prevent potential infinite loops from circular symlinks. Symlinks are now logged with a warning to stderr when encountered.
Changes:
- Added symlink detection check in
tarGzDirectoryto skip symlinks during tarball creation - Added warning message to stderr when symlinks are skipped
- Added comprehensive test coverage for file symlinks, directory symlinks, and broken symlinks
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/scan/repo/repo.go | Added symlink detection logic to skip symlinks during tarball creation with warning message |
| internal/scan/repo/repo_test.go | Added three comprehensive test cases covering file symlinks, directory symlinks, and broken symlinks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Skip symlinks to avoid security risks (symlinks pointing outside repo) | ||
| // and potential issues (broken symlinks, loops) | ||
| if info.Mode()&os.ModeSymlink != 0 { | ||
| fmt.Fprintf(os.Stderr, "Warning: skipping symlink %s\n", relPath) | ||
| return nil | ||
| } |
Copilot
AI
Jan 12, 2026
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.
The calculateDirSize function should also skip symlinks for consistency with tarGzDirectory. Currently, tarGzDirectory explicitly skips symlinks (lines 184-189), but calculateDirSize does not. While filepath.Walk doesn't follow symlinks by default, calculateDirSize may still count the symlink's metadata size, which could lead to a mismatch between the calculated size and the actual tarball size. Add the same symlink check after line 248 in calculateDirSize to ensure consistent behavior.
The calculateDirSize function now skips symlinks to match the behavior of tarGzDirectory. This ensures the calculated size matches the actual tarball size and maintains consistent symlink handling throughout the codebase. Addresses review comment from @copilot-pull-request-reviewer.
Description
Add explicit symlink detection and skipping in the tarball creation process to prevent security risks and extraction errors. Symlinks are now logged with a warning to stderr when encountered.
Type of Change
Testing
Checklist
Additional Notes
Symlinks are now skipped during tarball creation to avoid: