feat(cache): scope GET caching by public/private API#26
Merged
Conversation
Cache responses were keyed only by tenant id, so two users in the same tenant hitting a private GET shared one entry, allowing one user to be served another user's response. Cache now resolves a scope per API: - public APIs (no access_token) -> "tenant" - private APIs -> "tenant_user" (key includes the URAC user id) Default is inferred from serviceParams.isAPIPublic and can be overridden per API via the custom registry "scope" field. A tenant_user request with no resolved user is not cached (safety: never leak across users). Also unref the periodic cleanup timers in the memory models (cache, idempotency, traffic) so they no longer hold the event loop open. Adds unit tests for public/private scoping and overrides; documents the scope field in docs/middleware/cache.md.
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.
Summary
GET response caching was keyed only by tenant id, so two users in the same tenant hitting a private GET shared one cache entry — allowing one user to be served another user's response (a cross-user data leak, not just staleness).
The cache now resolves a scope per API:
access_tokenrequired) →tenantscope (key = tenant id) — unchanged behaviortenant_userscope (key also includes the URAC user id)The default is inferred from
req.soajs.controller.serviceParams.isAPIPublic(already set upstream by themtmiddleware and used by the traffic middleware). It can be overridden per API in the custom registry via a newscopefield ("tenant"|"tenant_user").Safety: a
tenant_userrequest with no resolved user is not cached — a misconfiguration becomes a cache miss, never a cross-user leak.Also included
unref()the periodic cleanup timers in the three in-memory models (cache,idempotency,traffic) so they no longer hold the Node event loop open. The unit suite now self-terminates without mocha's--exit.Tests
isAPIPublic.Docs
docs/middleware/cache.mdupdated: newscopeconfig field, public-vs-private scope section, safety behavior, and corrected cache-key structure / examples.