Fix path traversal vulnerability in file operations#2851
Merged
Kvarkas merged 2 commits intoOct 7, 2025
v1.78.2-devmRemoteNG/mRemoteNG:v1.78.2-devfrom
copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621mRemoteNG/mRemoteNG:copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621Copy head branch name to clipboard
Merged
Fix path traversal vulnerability in file operations#2851Kvarkas merged 2 commits intov1.78.2-devmRemoteNG/mRemoteNG:v1.78.2-devfrom copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621mRemoteNG/mRemoteNG:copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621Copy head branch name to clipboard
Kvarkas merged 2 commits into
v1.78.2-devmRemoteNG/mRemoteNG:v1.78.2-devfrom
copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621mRemoteNG/mRemoteNG:copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621Copy head branch name to clipboard
Conversation
Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Path traversal attack possible
Fix path traversal vulnerability in file operations
Oct 7, 2025
Kvarkas
marked this pull request as ready for review
October 7, 2025 15:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a critical security vulnerability where malicious actors could use path traversal sequences (
../or..\) to access or modify files outside the intended directory scope in file operation methods.Vulnerability Details
The following files were vulnerable to path traversal attacks:
FileDataProvider.cs- Constructor,FilePathproperty setter, andMoveTo()methodFileBackupPruner.cs-PruneBackupFiles()methodFileBackupCreator.cs-CreateBackupFile()methodAn attacker could potentially exploit this by providing malicious file paths like:
Solution
Implemented a centralized
PathValidatorutility class that validates file paths before any file operations. The validator detects and blocks:../sequences..\sequences (Windows-style)%2e%2esequences (case-insensitive)Example Protection
Changes Made
New Files
mRemoteNG/Tools/PathValidator.cs- Centralized path validation utility with two methods:IsValidPath(string path)- Returns validation resultValidatePathOrThrow(string path, string parameterName)- ThrowsArgumentExceptionfor invalid pathsModified Files
FileDataProvider.cs- Added validation to constructor,FilePathsetter, andMoveTo()methodFileBackupPruner.cs- Added validation toPruneBackupFiles()methodFileBackupCreator.cs- Replaced inline validation checks with centralizedPathValidatorInherited Protection
FileDataProviderWithRollingBackup.cs- Automatically protected through base class inheritanceTest Coverage
Added 21 comprehensive test cases across 4 test files:
PathValidatorTests.cs(13 tests) - Validates all detection scenarios including forward/backslash traversal, URL-encoded sequences, null/empty paths, and exception handlingFileDataProviderTests.cs(+3 tests) - Tests constructor, property setter, and MoveTo validationFileBackupCreatorTests.cs(+2 tests) - Tests path traversal rejection in backup creationFileBackupPrunerTests.cs(3 tests) - Tests path traversal rejection in backup pruningBackward Compatibility
✅ All changes are backward compatible
Security Impact
Before: Potential unauthorized file access/modification anywhere on the filesystem
After: All file paths validated, path traversal attacks blocked with
ArgumentExceptionCode Metrics
Fixes vulnerability reported in issue regarding path traversal attacks in file operations.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.