Skip to content

OutputCaching: Avoid locking request with invalid cache key when another request is in-flight - #68629

Merged
Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/output-cache-invalid-key
Aug 19, 2026
Merged

OutputCaching: Avoid locking request with invalid cache key when another request is in-flight#68629
Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/output-cache-invalid-key

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Aug 18, 2026

Copy link
Copy Markdown
Member

Fixes #67763

Previously, an invalid cache key (surfaced as string.Empty) would let two concurrent requests to serve the same response (var cacheEntry = await _requestDispatcher.ScheduleAsync(context.CacheKey, key => ExecuteResponseAsync());)

We shouldn't call ScheduleAsync with empty CacheKey.

Copilot AI lite review requested due to automatic review settings August 18, 2026 18:59

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

This pull request fixes a security-sensitive concurrency issue in OutputCaching where requests with an invalid/empty cache key could still participate in response locking, causing unrelated in-flight responses to be coalesced under the empty dispatcher key.

Changes:

  • Skip response locking when CacheKey is null/empty to prevent invalid-key coalescing.
  • Add a regression test to ensure concurrent requests with an invalid key execute independently.

Reviewed changes

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

File Description
src/Middleware/OutputCaching/src/OutputCacheMiddleware.cs Prevents scheduling response-locking work under an invalid/empty cache key.
src/Middleware/OutputCaching/test/OutputCacheMiddlewareTests.cs Adds a concurrent regression test covering invalid-key locking behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Middleware/OutputCaching/test/OutputCacheMiddlewareTests.cs
@Youssef1313
Youssef1313 merged commit c42d4c8 into main Aug 19, 2026
28 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/output-cache-invalid-key branch August 19, 2026 06:25
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 20, 2026
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.

OutputCaching invalid cache keys can coalesce unrelated concurrent responses

3 participants