Repository navigation
Batch 1: correctness & key hygiene (error-response caching, namespace injection, key-encoding docs) - #12
Merged
Conversation
A raw POCO action return produces an ObjectResult with a null StatusCode that the framework serializes as 200. IsSuccessStatusCode now treats null as success so success-gated caching (Task 2) keeps caching POCO returns.
Previously any non-null IActionResult was cached, so NotFound()/BadRequest() error bodies were cached and replayed for the whole TTL. Gate the cache write on IsSuccessfulResult().
IStatusCodeHttpResult results (e.g. TypedResults.NotFound) are now checked against the 2xx range before caching; status-less results (raw objects) are treated as 200 and remain cacheable.
Bound namespace values were URL-decoded, letting a ':' in a user-supplied route value merge into namespace structure (cross-namespace collision / eviction). Re-escape the resolved value instead. BREAKING: changes the on-the-wire namespace format for templated namespaces; existing entries under templated namespaces age out via TTL after upgrade.
Correct the false 'AES encryption' claim and 'decrypt' wording; document that keys embed route values and action arguments in cleartext and are not confidential.
The tests slept exactly on the 5s expiry boundary and flaked. Use a 2s expiration with a 4s wait for a comfortable margin, and replace blocking Thread.Sleep with await Task.Delay in these async tests.
Supersedes the whole-string escaping from the prior Task 4 commit (fa1207e), which escaped the entire resolved namespace and broke the equivalence between a templated namespace (e.g. "Teams:{id}") and its literal form (e.g. "Teams:42"). That regression caused Test_ActionCacheRefreshFilter_WithRouteTemplateParameter to find 0 cached keys instead of 10, because factory.Create("Teams:<id>") no longer matched the escaped, templated-resolved namespace. Now each route VALUE is escaped with Uri.EscapeDataString before TemplateBinder.BindValues runs, and a single HttpUtility.UrlDecode is applied after. Empirically verified against BindValues' actual encoding behavior: the template's own structural ':' is single-encoded by BindValues and is restored to a raw ':' by the single decode (preserving literal/templated equivalence), while a ':' embedded in a user-supplied value is escaped before binding, so BindValues double-encodes it and the single decode leaves it singly-escaped and inert (injection stays neutralized).
Broadens the MVC cache gate from ObjectResult/StatusCodeResult to any successful (2xx / status-less) IActionResult - JsonResult, ContentResult, FileResult - so it no longer silently drops caching for them and stays symmetric with the Minimal API filter's IsSuccessfulEndpointResult. The refresh filter's IsSuccessfulResult is unchanged.
jzills
force-pushed
the
fix/batch-1-correctness-key-hygiene
branch
from
July 6, 2026 21:21
071fc76 to
2f30a8f
Compare
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.
Batch 1 — Correctness & Key Hygiene
First of four themed batches addressing findings from a full repository recon. This batch fixes correctness and key-handling issues; later batches cover resilience/startup, concurrency, and serialization/refresh.
What's fixed
1. Stop caching (and replaying) error responses
The read-through filters cached any non-null result, so
NotFound()/BadRequest()bodies were cached and served asHitfor the whole TTL. Both the MVC (ActionCacheFilter) and Minimal API (ActionCacheEndpointFilter) filters now cache only successful (2xx / status-less → 200) responses. A supporting fix makes a null-statusObjectResult(a raw POCO return) count as 200. The MVC gate usesIStatusCodeActionResultsoJsonResult/ContentResult/FileResultsuccesses are still cached — symmetric with the Minimal API path.2. Neutralize namespace / key injection from route values
Templated namespaces (e.g.
Teams:{id}) bound user-controlled route values and URL-decoded them, letting a:inside a value merge into the namespace's structural separators (cross-namespace collision / eviction). Route values are now escaped before binding while the template's own separators are preserved, so an injected:becomes%3A(inert) and a clean value still resolves to the same namespace as the equivalent literal (factory.Create("Teams:<id>")).3. Correct the false "AES encryption" claim (docs-only)
Cache keys use reversible hex encoding, not encryption. XML docs and the README now state this plainly and note keys are not confidential (secure the cache store; don't put secrets in route values/args). Real key encryption is fundamentally at odds with deterministic cache hits + refresh reversibility — see the spec for the rationale.
4. De-flake the absolute-expiration tests
They slept exactly on the 5s expiry boundary (observed ~1-in-3 flake). Now use a 2s expiration with a 4s wait and
await Task.Delayinstead ofThread.Sleep.:) change, and any affected existing entries age out via TTL after upgrade.Testing
net8.0andnet10.0; Release build clean (0 warnings/errors).factory.Createequivalence) was caught by the integration suite and fixed by escaping values only.InternalServerError (500)failures on expiration tests this branch does not touch — pre-existing emulator flakiness, unrelated to these changes.Follow-ups (non-blocking review notes)
AttachRouteValues.ObjectResultExtensions,IActionResultExtensionssummaries).🤖 Generated with Claude Code