fix: follow symlinks when iterating entries directory#1642
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Cli::content method to follow symlinks during directory iteration and introduces new test cases to verify symlink resolution for desktop files. A security concern was identified regarding the use of QDirIterator::FollowSymlinks, which could expose the system to path traversal attacks if symlinks point outside the package's layer directory. It is recommended to validate that all resolved paths remain within the intended directory scope.
| QDirIterator it(entriesDir.absolutePath(), | ||
| QDir::AllEntries | QDir::NoDot | QDir::NoDotDot | QDir::System, | ||
| QDirIterator::Subdirectories); | ||
| QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); |
There was a problem hiding this comment.
Enabling QDirIterator::FollowSymlinks allows the iterator to descend into symlinked directories. This introduces a potential security risk if a package contains malicious symlinks pointing to sensitive host files (e.g., /etc/shadow).
When FollowSymlinks is active, it.fileInfo().absoluteFilePath() returns the path of the symlink target. If that target is outside the entriesDir, entriesDir.relativeFilePath(entryPath) will produce a path starting with ... It is highly recommended to validate that the resolved entryPath is still within the package's layer directory to prevent path traversal vulnerabilities during the export process.
1. Add QDirIterator::FollowSymlinks flag to directory iterator in Cli::content method 2. This enables proper resolution of desktop files from symlinked entries/share directories 3. Previously, symlinks in the entries directory were not being followed, causing desktop files pointed to by symbolic links to be missed 4. Add two test cases to verify symlink resolution works correctly: - contentResolvesDesktopFromSymlinkedEntriesShareDir: tests resolving desktop from symlinked entries - contentResolvesOverlayDesktopFromSymlinkedEntriesShareDir: tests overlay desktop resolution with symlinks Influence: 1. Test content command with applications that have symlinked entries/ share directories 2. Verify desktop file discovery works correctly when entries/share is a symlink to files/share 3. Test both default directory fallback and overlay directory scenarios with symlinked paths 4. Verify no regression in normal (non-symlinked) directory traversal 5. Test that symlinked directories pointing outside expected paths are handled safely
27fbc4a to
71b94b5
Compare
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengbo11, reddevillg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Influence: