Repository navigation
Harden interaction file uploads - #19488
James Newton-King (JamesNK) merged 11 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19488Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19488" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adds trusted server-side file-count enforcement and safer temporary-file naming across Dashboard and CLI interaction uploads.
Changes:
- Enforces single/multi-file limits during upload and submission.
- Uses random disk filenames while retaining sanitized metadata.
- Adds coverage for limits, unsafe filenames, cleanup, and UI selection.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tests/Shared/TestInteractionFileUploadStore.cs |
Captures registered file-input limits. |
tests/Aspire.Hosting.Tests/InteractionServiceTests.cs |
Tests submission count validation. |
tests/Aspire.Hosting.Tests/Dashboard/InteractionFileUploadStoreTests.cs |
Tests limits, metadata, and random paths. |
tests/Aspire.Hosting.Tests/Dashboard/DashboardServiceTests.cs |
Tests gRPC upload enforcement. |
tests/Aspire.Hosting.Tests/Backchannel/AppHostRpcTargetUploadTests.cs |
Tests CLI backchannel enforcement. |
tests/Aspire.Dashboard.Components.Tests/Dialogs/InteractionsInputDialogTests.cs |
Tests Dashboard selection limits. |
src/Shared/InteractionHelpers.cs |
Defines the shared 100-file limit. |
src/Aspire.Hosting/InteractionService.cs |
Registers and validates file limits. |
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs |
Enforces upload limits and random paths. |
src/Aspire.Hosting/Dashboard/IInteractionFileUploadStore.cs |
Extends interaction registration metadata. |
src/Aspire.Dashboard/Components/Dialogs/InteractionsInputDialog.razor.cs |
Uses the shared file-count constant. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs:282
- The resolved
Nameis still taken from the completion payload when present, so a client can uploadsafe.txtand then submit the same ID with a name such as../../target. This bypasses the leaf-name sanitization and exposes an unsafeInteractionFile.Nameto AppHost code. Use the name retained in the trusted upload-store entry after validating the ID and input.
files.Add(new InputFileDto(fileRef.Id, fileName, filePath, () => store.RemoveEntry(interactionId, fileRef.Id)));
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs:65
- The new tests exercise the limit only sequentially, so they do not verify the explicit guarantee that concurrent in-progress uploads reserve capacity atomically. Add a coordinated concurrency test with a limit of one that starts two
CreateEntrycalls together and asserts exactly one succeeds and only one entry is retained.
// Count uploads in progress as reserved slots so concurrent requests cannot exceed the input's limit.
var fileCount = interaction.Files.Values.Count(entry => string.Equals(entry.InputName, inputName, StringComparisons.InteractionInputName));
if (fileCount >= maxFileCount)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs:282
fileNamestill comes from the submitted JSON reference, so a custom client can upload a safely named file and then submitName: "../../target"; that unsanitized value becomesInteractionFile.Name. This bypasses the new upload-time leaf-name sanitization and can reintroduce path traversal in consumers that use the metadata as a filename. Always source the name from the trusted store entry.
files.Add(new InputFileDto(fileRef.Id, fileName, filePath, () => store.RemoveEntry(interactionId, fileRef.Id)));
src/Aspire.Hosting/IInteractionService.cs:463
- This returns the same owning collection before and after completion.
ProcessInputspopulates it beforeRunValidationAsyncinvokesValidationCallback, so a callback that follows the new guidance and disposesGetFiles()after inspecting uploaded content deletes and invalidates the files that the successful prompt result then returns. Validation needs non-owning access, or ownership must be transferred only to the completed result; add coverage for content validation followed by reading the result.
public InteractionFileCollection GetFiles() => _files;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs:282
- The submitted
Nameis still trusted whenever it is non-empty, so a custom client can uploadsafe.txtand then submit a reference whose name is../../other. The resulting publicInteractionFile.Namebypasses the leaf-name sanitization performed during upload, contrary to the new metadata guarantee. Resolve the name exclusively from the upload-store entry.
files.Add(new InputFileDto(fileRef.Id, fileName, filePath, () => store.RemoveEntry(interactionId, fileRef.Id)));
src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs:64
- This lock is the only protection that makes the new “in-progress uploads reserve capacity” guarantee atomic, but the added tests fill the store sequentially. Add a coordinated concurrent test with a limit of 1 that starts two
CreateEntrycalls together and verifies exactly one succeeds; otherwise a future change that separates the count and insertion would silently reintroduce the upload-limit bypass.
// Count uploads in progress as reserved slots so concurrent requests cannot exceed the input's limit.
var fileCount = interaction.Files.Values.Count(entry => string.Equals(entry.InputName, inputName, StringComparisons.InteractionInputName));
This comment has been minimized.
This comment has been minimized.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This comment has been minimized.
This comment has been minimized.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Tests selector (audit mode)The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement. 54 / 102 test projects · 5 jobs, from 25 changed files. Selected test projects (54 / 102)
Selected jobs (5)
How these were chosen — grouped by what changed
🔧 show 37
🔧 🧪 📦 affected project 📦 affected project 📄 📄 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Pull request created: #1554
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1554 targeting Updated Note This draft PR needs human review before merging. |
Description
Interaction file uploads previously had inconsistent enforcement and lifetime management across clients:
AllowMultipleFilesduring upload or submission.This PR makes upload validation and file ownership consistent across the Dashboard, CLI, custom clients, and the AppHost.
File-count validation
AllowMultipleFiles = true.Filename and temporary-file handling
Uploaded-file ownership
InteractionInput.GetFiles().InteractionFileCollection, which implementsIReadOnlyList<InteractionFile>andIDisposable.InteractionInput.Filesobsolete in favor ofGetFiles().InteractionFileCollectionremoves its upload-store entries and deletes the temporary files from disk.InteractionFile.OpenRead()andReadAllBytesAsync()throwObjectDisposedException.InteractionFileCollectionto an input does not implicitly dispose a previously assigned collection; ownership remains with the caller that received it.GetFiles().ATS / polyglot behavior
IDisposable.User-facing usage
The uploaded temporary files are deleted when
filesis disposed. Attempts to read anInteractionFileafter its owning collection is disposed throwObjectDisposedException.Security considerations
File uploads contain untrusted names and content and are written to the operating system temporary directory. This change:
No formal threat model or security review has been completed.
Validation
Aspire.Hosting.Tests: 176 passed, including upload limits, malicious filenames, authoritative filename metadata, submission validation, disk reads, deletion on disposal, and post-disposal exceptions.Aspire.Dashboard.Components.Tests: 4 passed, including the 100/101 selection boundary.Aspire.Dashboard.Tests: 1,561 passed.Aspire.Hosting.RemoteHost.Tests: ATS file metadata projection passed.Stress.AppHost: build succeeded with no warnings or errors.Publishers.AppHost: build succeeded with no warnings or errors.Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?