.NET: Harness: Improve path validation#5404
Merged
westey-m merged 2 commits intomicrosoft:feature-harnessfrom Apr 22, 2026
Merged
.NET: Harness: Improve path validation#5404westey-m merged 2 commits intomicrosoft:feature-harnessfrom
westey-m merged 2 commits intomicrosoft:feature-harnessfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens and centralizes relative-path validation for the Harness file stores and the file-based memory provider, aiming to reduce path-traversal risk and normalize path inputs consistently across implementations.
Changes:
- Introduces a shared
AgentFileStore.NormalizeRelativePathhelper and updates in-memory/file-system stores to use it. - Updates
FileSystemAgentFileStoreto normalize before combining with the root directory. - Adjusts unit tests to reflect new normalization behavior for trailing slashes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/AgentFileStore.cs | Adds centralized relative-path normalization/validation helper. |
| dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/InMemoryAgentFileStore.cs | Switches to shared normalization helper for all operations. |
| dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileSystemAgentFileStore.cs | Uses normalized relative paths during safe path resolution. |
| dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileMemoryProvider.cs | Refactors and tightens filename validation before combining paths. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/FileMemory/FileSystemAgentFileStoreTests.cs | Updates test expectation: trailing slashes normalize instead of throwing. |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI/Harness/FileMemory/FileSystemAgentFileStore.cs:250
- The root-escape check uses
fullPath.StartsWith(this._rootPath, StringComparison.Ordinal). On Windows, paths are case-insensitive andPath.GetFullPathcan normalize drive-letter casing, soOrdinalcomparisons can incorrectly reject valid paths (denial of service) depending on the casing ofrootDirectory. Use an OS-appropriate comparison (e.g.,OrdinalIgnoreCaseon Windows) or compare viaPath.GetRelativePath(_rootPath, fullPath)and ensure it doesn’t start with...
string fullPath = Path.GetFullPath(combined);
if (!fullPath.StartsWith(this._rootPath, StringComparison.Ordinal))
{
throw new ArgumentException(
$"Invalid path: '{relativePath}'. The resolved path escapes the root directory.",
nameof(relativePath));
lokitoth
reviewed
Apr 21, 2026
lokitoth
approved these changes
Apr 21, 2026
SergeyMenshykh
approved these changes
Apr 22, 2026
pull Bot
pushed a commit
to nagyist/ms-agent-framework
that referenced
this pull request
May 1, 2026
* .NET: Add a TODO AIContextProvider (microsoft#5233) * Add a TODO AIContextProvider * Add unit tests * Address PR comments * Address PR comments * Fix test after removing one tool * .NET: Add a ModeProvider for managing agent modes (microsoft#5247) * Add a ModeProvider for managing agent modes * Fix typo * Fix typo * Fix typo * Address PR comments * .NET: Add sample to show how to build a harness (microsoft#5268) * Add sample to show how to build a harness * Improve sample * Sample max output tokens and model * Fix encoding * Fix model name in readme * Address PR comments * .NET: Add context window size compaction strategy for harness (microsoft#5304) * Add context window size compaction strategy for harness * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Address PR comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * .NET: Add a file memory provider (microsoft#5315) * Add a file memory provider * Address PR comments * Fix review comments. * Add additional unit tests * Addressing PR comments. * .NET: Harness: Improve prompts and add FileSystem store (microsoft#5365) * Harness: Improve prompts and add FileSystem store * Address PR comments * .NET: Harness: Improve path validation (microsoft#5404) * Harness: Improve path validation * Address PR comments * .NET: Add always approve helpers, improve sample and fix bug (microsoft#5451) * Add always approve helpers, improve sample and fix bug * Address PR comments * .NET: Make Todo, Mode and FileMemory providers more configurable (microsoft#5477) * Make Todo, Mode and FileMemory providers more configurable * Address PR comments. * .NET: Add subagents provider and sample (microsoft#5518) * Add subagents provider and sample * Addressing PR comments. * .NET: Harness filememory index plus instructions consistency (microsoft#5540) * Add FileMemoryProvider index and improve instruction consistency * Address PR comments. * Address PR comments * Address PR comments. * Apply suggestion from @rogerbarreto Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> --------- Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> * .NET: Refactor harness console to be more extensible and easy to understand with better UX (microsoft#5573) * Refactor harness console to be more extensible and easy to understand with better UX. * Fix formatting issues. * Allow multiple clarifications in one response * Address PR comments * .NET: Add FileAccessProvdider and concurrency fix for FileMemoryProvider (microsoft#5583) * Add FileAccessProvdider and concurrency fix for FileMemoryProvider * Address PR comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
This was referenced May 3, 2026
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.
Motivation and Context
Adding some further improvements and code consolidation to file path validation for the file stores and file based memory store.
Description
Adding some further improvements and code consolidation to file path validation for the file stores and file based memory store.
Contribution Checklist