Skip to content

Honor custom policies allowing output caching for authenticated users - #69580

Merged
DeagleGross merged 1 commit into
dotnet:mainfrom
marcominerva:fix/outputcache-authenticated-servresponse
Oct 8, 2026
Merged

DeagleGross merged 1 commit into
dotnet:mainfrom
marcominerva:fix/outputcache-authenticated-servresponse

Conversation

@marcominerva

Copy link
Copy Markdown
Contributor

Since #67110, DefaultPolicy.ServeResponseAsync clears AllowCacheStorage for any authenticated user. That check is only needed when the user becomes authenticated after the output cache middleware ran. It also overrode custom policies that allow storage in CacheRequestAsync for users who were already authenticated, so those responses silently stopped being cached.

DefaultPolicy now records in CacheRequestAsync whether the user was already authenticated. ServeResponseAsync only clears storage for users who became authenticated after that point. Custom policies work again for users authenticated before the output cache middleware ran, and responses for users authenticated later are still never stored.

Fixes #69386

Copilot AI balanced review requested due to automatic review settings September 29, 2026 09:27
@github-actions github-actions Bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Sep 29, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 29, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @marcominerva. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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.

Copilot review overview

🟢 Approval recommended

The focused implementation preserves late-authentication protection and includes coverage for both affected middleware orderings.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes output caching so custom policies can cache responses for users authenticated before the caching middleware runs, while rejecting storage when authentication occurs afterward.

Changes:

  • Records the request’s initial authentication state.
  • Applies the response-stage authentication check only to newly authenticated users.
  • Adds unit and integration regression coverage.
File Description
src/​Middleware/​OutputCaching/​src/​Policies/​DefaultPolicy.cs Refines the authenticated-response storage check.
src/​Middleware/​OutputCaching/​src/​OutputCacheContext.cs Stores initial authentication state.
src/​Middleware/​OutputCaching/​test/​OutputCachePolicyProviderTests.cs Tests policy behavior for early and late authentication.
src/​Middleware/​OutputCaching/​test/​OutputCacheTests.cs Verifies end-to-end cache storage behavior.

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 6, 2026
@marcominerva marcominerva reopened this Oct 6, 2026
@DeagleGross
DeagleGross merged commit 2bb3dff into dotnet:main Oct 8, 2026
44 checks passed
@DeagleGross

Copy link
Copy Markdown
Member

/backport to release/10.0

@DeagleGross

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 07f5eb8a Deployed Sep 29, 2026 by dotnet-policy-service[bot] via pat_pool #1655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output caching: authenticated-user check added to DefaultPolicy.ServeResponseAsync in 10.0.9 silently disables custom policies

4 participants