Repository navigation
Batch 4a — Response envelope (drops polymorphic deserialization from the value path) - #19
Merged
Merged
Conversation
This was referenced Aug 21, 2026
jzills
force-pushed
the
fix/batch-5-layering-api-surface
branch
from
August 23, 2026 02:47
b4ba089 to
676c230
Compare
jzills
force-pushed
the
fix/batch-4a-response-envelope
branch
from
August 23, 2026 02:47
c1d88ef to
1bd57c1
Compare
jzills
force-pushed
the
fix/batch-5-layering-api-surface
branch
from
August 23, 2026 03:12
676c230 to
844d30d
Compare
Cached values were IActionResult object graphs serialized by Newtonsoft with TypeNameHandling.Auto, so a cache entry named the types deserialization should construct and the only defense was a deny-list of five gadget namespaces. Deny-lists lose. Values are now a CachedResponse of primitives — status code, content type, already-rendered body — serialized with System.Text.Json through a source-generated context. There is no $type and no type resolution, so the vulnerability class is removed rather than filtered, and the hot path is trim/AOT friendly. A regression test asserts no type discriminator survives serialization. Bodies are rendered with the application's own JsonSerializerOptions, so a cached body is byte-identical to what the action would have written; a test proves the app's camelCase policy is honored rather than serializer defaults. JsonResult is handled explicitly — it is not an ObjectResult, and treating it generically would have silently stopped caching a result IsCacheableResult accepts. Scope note: cache *keys* still use Newtonsoft, now behind KeyComponentSerializer. Reflection-based refresh reverses a key into typed action arguments and needs the type information to do it, so the binder stays there until 4b replays real requests and deletes the reverse path. #5 is not fully closed until then. BREAKING: existing cache entries are unreadable — expect a cold cache on deploy. BREAKING: results that do work at execution time (FileStreamResult, RedirectResult) are no longer cacheable. The previous code "cached" a file result by type name and rebuilt an object holding a disposed stream. BREAKING: filter and abstract-factory constructors take a CachedResponseFactory. Claude-Session: https://claude.ai/code/session_01VUPTqPh5w79mfa18fLnMLz
jzills
force-pushed
the
fix/batch-4a-response-envelope
branch
from
August 23, 2026 03:20
1bd57c1 to
a95a8ee
Compare
jzills
changed the base branch from
fix/batch-5-layering-api-surface
to
develop
August 23, 2026 03:20
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.
First half of Batch 4. Splitting it because the replayable request travels inside the envelope, so the envelope has to land first — and two reviewable PRs beat one mega-change.
What was wrong
Cached values were
IActionResultobject graphs serialized by Newtonsoft withTypeNameHandling.Auto. A cache entry therefore named the types deserialization should construct, and the only defense wasSafeSerializationBinder— a deny-list of five known gadget namespaces. Deny-lists lose; that is the whole problem with them.What replaces it
A
CachedResponseof primitives — status code, content type, already-rendered body — serialized with System.Text.Json through a source-generated context. No$type, no type resolution, nothing in a cached payload that can influence which types get constructed. The vulnerability class is removed, not filtered. A regression test asserts no type discriminator survives serialization.Bodies are rendered with the application's own
JsonSerializerOptions, so a cached body is byte-identical to what the action would have written. A test proves this by configuring a camelCase policy and asserting the body is camelCase rather than serializer defaults.The envelope also carries
VariesByRequestand the recordedCachedRequest(method, path, query) — unused here, consumed by 4b. Headers are deliberately not recorded: they routinely carry credentials, and a cache entry is no place for them.One thing I found while implementing
JsonResultis not anObjectResult. Handling results generically would have silently stopped caching a result thatIsCacheableResultaccepts, so it gets an explicit case.Scope note — #5 is not fully closed by this PR
Cache keys still use Newtonsoft, now isolated behind
KeyComponentSerializerwith the binder attached. Reflection-based refresh reverses a key back into typed action arguments and needsTypeNameHandlingto do it, so it cannot go until refresh stops reflecting. 4b deletes the reverse path, the binder, and the Newtonsoft dependency together. Saying so plainly rather than claiming a clean sweep.Breaking changes (pre-1.0)
FileStreamResult,RedirectResult,PhysicalFileResult) are no longer cacheable. They arguably never were: the previous code serialized a file result by type name and rebuilt an object holding a disposed stream.ActionCacheFilter/ActionCacheEndpointFilterand both abstract factories take aCachedResponseFactory.Verification
Unit 517/517, integration 49/49, both on
net8.0andnet10.0. Release build 0 warnings.https://claude.ai/code/session_01VUPTqPh5w79mfa18fLnMLz