Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix path traversal vulnerability in file operations#2851

Merged
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
Oct 7, 2025
Merged

Fix path traversal vulnerability in file operations#2851
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

Copilot AI commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

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, FilePath property setter, and MoveTo() method
  • FileBackupPruner.cs - PruneBackupFiles() method
  • FileBackupCreator.cs - CreateBackupFile() method

An attacker could potentially exploit this by providing malicious file paths like:

../../Windows/System32/config.xml
../../../etc/passwd
%2e%2e/sensitive-data.xml

Solution

Implemented a centralized PathValidator utility class that validates file paths before any file operations. The validator detects and blocks:

  • Direct ../ sequences
  • Direct ..\ sequences (Windows-style)
  • URL-encoded %2e%2e sequences (case-insensitive)
  • Null/empty paths

Example Protection

// Before: No validation
public FileDataProvider(string filePath) 
{
    FilePath = filePath; // Vulnerable!
}

// After: Path validated
public FileDataProvider(string filePath)
{
    PathValidator.ValidatePathOrThrow(filePath, nameof(filePath)); // Secure ✓
    _filePath = filePath;
}

Changes Made

New Files

  • mRemoteNG/Tools/PathValidator.cs - Centralized path validation utility with two methods:
    • IsValidPath(string path) - Returns validation result
    • ValidatePathOrThrow(string path, string parameterName) - Throws ArgumentException for invalid paths

Modified Files

  • FileDataProvider.cs - Added validation to constructor, FilePath setter, and MoveTo() method
  • FileBackupPruner.cs - Added validation to PruneBackupFiles() method
  • FileBackupCreator.cs - Replaced inline validation checks with centralized PathValidator

Inherited Protection

  • FileDataProviderWithRollingBackup.cs - Automatically protected through base class inheritance

Test 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 handling
  • FileDataProviderTests.cs (+3 tests) - Tests constructor, property setter, and MoveTo validation
  • FileBackupCreatorTests.cs (+2 tests) - Tests path traversal rejection in backup creation
  • FileBackupPrunerTests.cs (3 tests) - Tests path traversal rejection in backup pruning

Backward Compatibility

All changes are backward compatible

  • Legitimate file operations continue to work normally
  • Only malicious path traversal attempts are blocked
  • No breaking changes to existing API
  • Clear error messages for debugging

Security Impact

Before: Potential unauthorized file access/modification anywhere on the filesystem
After: All file paths validated, path traversal attacks blocked with ArgumentException

Code Metrics

  • 8 files changed
  • 261 lines added, 6 lines removed
  • Net change: +255 lines
  • Minimal, surgical changes focused only on security fixes

Fixes vulnerability reported in issue regarding path traversal attacks in file operations.

Original prompt

This section details on the original issue you should resolve

<issue_title>Path traversal attack possible</issue_title>
<issue_description>Find more live information in Aikido here: https://app.aikido.dev/queue?sidebarIssue=16286729&groupId=38189&sidebarIssueTask=1328865&sidebarTab=tasks

Scope

This task includes issues in the following code repository:

TLDR

A malicious actor could control the location of this file, to include going backwards up a directory by adding '../' to the input.

How to fix

To address this, ensure that user-controlled variables in file paths are sanitized at least to not contain '..' or forward slashes.</issue_description>

<agent_instructions>could you review and propouse a fix </agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #2819

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

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
Copilot AI requested a review from Kvarkas October 7, 2025 14:10
@Kvarkas
Kvarkas marked this pull request as ready for review October 7, 2025 15:04
@Kvarkas
Kvarkas merged commit c987ee9 into v1.78.2-dev Oct 7, 2025
@Kvarkas
Kvarkas deleted the copilot/fix-3efd67f4-15e3-43e9-9b58-50941b183621 branch November 27, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path traversal attack possible

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.