Skip to content

Harden interaction file uploads - #19488

Merged
James Newton-King (JamesNK) merged 11 commits into
mainfrom
jamesnk/validate-interaction-file-uploads
Aug 20, 2026
Merged

James Newton-King (JamesNK) merged 11 commits into
mainfrom
jamesnk/validate-interaction-file-uploads

Conversation

@JamesNK

@JamesNK James Newton-King (JamesNK) commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Description

Interaction file uploads previously had inconsistent enforcement and lifetime management across clients:

  • The Dashboard limited a single file-picker selection to 100 files, but the CLI and custom clients had no equivalent limit.
  • The AppHost accepted unbounded uploads and did not enforce AllowMultipleFiles during upload or submission.
  • Client-provided filenames were used when allocating temporary files.
  • .NET callers had no deterministic way to release uploaded temporary files after processing them.

This PR makes upload validation and file ownership consistent across the Dashboard, CLI, custom clients, and the AppHost.

File-count validation

  • Adds a shared maximum of 100 files for inputs with AllowMultipleFiles = true.
  • Limits single-file inputs to one file.
  • Registers trusted per-input limits when an interaction starts.
  • Enforces limits before Dashboard gRPC or CLI JSON-RPC upload content is written.
  • Counts in-progress uploads as reserved slots so concurrent requests cannot exceed the limit.
  • Rejects uploads for unknown interaction inputs.
  • Revalidates the submitted file count as defense in depth.
  • Uses the shared maximum in the Dashboard file picker.
  • Documents that each client submits one file selection per input during an interaction; multi-file selections upload sequentially as part of that selection.

Filename and temporary-file handling

  • Always allocates uploaded content with an OS-generated temporary filename.
  • Never uses the client-provided filename in the disk path.
  • Retains only the separator-stripped leaf filename as authoritative display metadata and ignores client-supplied names during submission.
  • Covers Unix and Windows traversal names, wildcard characters, ADS-like names, reserved Windows names, and embedded NUL characters.
  • Keeps the existing per-file size limits and AppHost shutdown cleanup.

Uploaded-file ownership

  • Adds InteractionInput.GetFiles().
  • Adds InteractionFileCollection, which implements IReadOnlyList<InteractionFile> and IDisposable.
  • Marks InteractionInput.Files obsolete in favor of GetFiles().
  • Disposing InteractionFileCollection removes its upload-store entries and deletes the temporary files from disk.
  • Disposal is idempotent.
  • After disposal, InteractionFile.OpenRead() and ReadAllBytesAsync() throw ObjectDisposedException.
  • Assigning an InteractionFileCollection to an input does not implicitly dispose a previously assigned collection; ownership remains with the caller that received it.
  • Migrates first-party Stress and Publishers AppHost samples to use and dispose GetFiles().

ATS / polyglot behavior

  • Keeps the existing ATS file metadata projection for polyglot AppHosts.
  • Excludes the .NET-only disposable collection API from ATS generation because it owns server-local files and implements IDisposable.
  • Projects file metadata through a non-owning collection so ATS projection does not share or consume the .NET caller's cleanup ownership.

User-facing usage

using var files = input.GetFiles();
foreach (var file in files)
{
    var content = await file.ReadAllBytesAsync(cancellationToken);
    // Process content.
}

The uploaded temporary files are deleted when files is disposed. Attempts to read an InteractionFile after its owning collection is disposed throw ObjectDisposedException.

Security considerations

File uploads contain untrusted names and content and are written to the operating system temporary directory. This change:

  • Prevents client-provided filenames from being used in disk paths.
  • Removes path components from retained filename metadata.
  • Ignores client-supplied filename metadata during submission in favor of the trusted stored name.
  • Rejects uploads for unknown inputs.
  • Bounds file counts per input, including concurrent in-progress uploads.
  • Preserves existing upload-size limits.
  • Gives .NET callers deterministic cleanup ownership.

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

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19488

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19488"

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 19, 2026
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Name is still taken from the completion payload when present, so a client can upload safe.txt and then submit the same ID with a name such as ../../target. This bypasses the leaf-name sanitization and exposes an unsafe InteractionFile.Name to 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 CreateEntry calls 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)

Copilot AI review requested due to automatic review settings August 19, 2026 07:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • fileName still comes from the submitted JSON reference, so a custom client can upload a safely named file and then submit Name: "../../target"; that unsanitized value becomes InteractionFile.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. ProcessInputs populates it before RunValidationAsync invokes ValidationCallback, so a callback that follows the new guidance and disposes GetFiles() 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;

Copilot AI review requested due to automatic review settings August 19, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Name is still trusted whenever it is non-empty, so a custom client can upload safe.txt and then submit a reference whose name is ../../other. The resulting public InteractionFile.Name bypasses 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 CreateEntry calls 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));

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Copilot AI review requested due to automatic review settings August 20, 2026 05:03
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated no new comments.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Copilot AI review requested due to automatic review settings August 20, 2026 07:42
@github-actions

Copy link
Copy Markdown
Contributor

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)

Aspire.Cli.EndToEnd.Tests, Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.GitHub.Models.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Managed.Tests, Aspire.Playground.Tests

Selected jobs (5)

cli-starter, deployment-e2e, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 37 of the 54 selected test projects come from a single change — src/Aspire.Hosting/Ats/InteractionExports.cs.

🔧 src/Aspire.Hosting/Ats/InteractionExports.cs (changed source)
→ 37 via the project graph

show 37

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Browsers.Tests (2 hops), Aspire.Hosting.Containers.Tests (2 hops), Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.Docker.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.GitHub.Models.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.Java.Tests (2 hops), Aspire.Hosting.JavaScript.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Kubernetes.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.OpenAI.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.Rust.Tests (2 hops), Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Hosting.Yarp.Tests (2 hops), Aspire.Playground.Tests

🔧 src/Aspire.Dashboard/Components/Dialogs/InteractionsInputDialog.razor.cs (changed source)
→ 4 via the project graph: Aspire.Dashboard.Tests, Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.Testing.Tests, Aspire.Managed.Tests (2 hops)

🧪 tests/Aspire.Hosting.Tests/Backchannel/AppHostRpcTargetUploadTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.EndToEnd.Tests

📦 affected project Aspire.Managed
→ 1 test: Aspire.Cli.EndToEnd.Tests

📄 playground/Stress/Stress.AppHost/InteractionCommands.cs (changed)
→ 1 directly: Aspire.Playground.Tests

📄 playground/publishers/Publishers.AppHost/DistributedApplicationBuilderExtensions.cs (changed)
→ 1 directly: Aspire.Playground.Tests

🧪 tests/Aspire.Dashboard.Components.Tests/Dialogs/InteractionsInputDialogTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Java.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Rust.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.RemoteHost.Tests/AtsExportsTests.cs (changed test)
→ 1 directly: Aspire.Hosting.RemoteHost.Tests

🧪 tests/Aspire.Hosting.Tests/Dashboard/DashboardServiceTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Dashboard/InteractionFileUploadStoreTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/InteractionServiceTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Publishing/PipelineActivityReporterTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter • affected project Aspire.Managed
• selected test Aspire.Cli.EndToEnd.Tests
deployment-e2e affected project Aspire.Managed
extension-e2e • src/Aspire.Dashboard/Components/Dialogs/InteractionsInputDialog.razor.cs, src/Aspire.Hosting/Ats/InteractionExports.cs, src/Aspire.Hosting/Dashboard/DashboardServiceData.cs, src/Aspire.Hosting/Dashboard/IInteractionFileUploadStore.cs, src/Aspire.Hosting/Dashboard/InteractionFileUploadStore.cs, src/Aspire.Hosting/IInteractionService.cs, src/Aspire.Hosting/InteractionService.cs, src/Aspire.Hosting/Pipelines/PipelineActivityReporter.cs, src/Aspire.Hosting/Utils/FileSystemService.cs
• affected project Aspire.Dashboard
polyglot affected project Aspire.Managed
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit b6e32c1.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@JamesNK
James Newton-King (JamesNK) merged commit 0b39431 into main Aug 20, 2026
754 of 757 checks passed
@JamesNK
James Newton-King (JamesNK) deleted the jamesnk/validate-interaction-file-uploads branch August 20, 2026 08:29
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.6 milestone Aug 20, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1554

Generated by PR Documentation Check · auto · 63.7 AIC · ⌖ 12.7 AIC · ⊞ 19.6K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1554 targeting release/17.0.

Updated extensibility/interaction-service.mdx to replace the obsolete result.Data.Files?[0] usage with using var files = result.Data.GetFiles();, explain InteractionFileCollection disposal/ownership semantics and that Files is now obsolete, and document the new 100-file (1-file if not AllowMultipleFiles) upload limit, including that in-progress uploads count toward it.

Note

This draft PR needs human review before merging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants