-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cache: "bounded"
configuration option
#6536
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 5c299de:
|
0e5ec97
to
e67c2ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good otherwise
docs/source/api/apollo-server.mdx
Outdated
</td> | ||
<td> | ||
|
||
It is recommended that you set this option to `"bounded"` if you otherwise would not have it configured. By default, the cache is unbounded. The APQ feature will use this cache by default (if you don't configure it otherwise). The default bounded cache is an [`InMemoryLRUCache`](https://www.npmjs.com/package/@apollo/utils.keyvaluecache) with a default size of roughly 30MiB. This can be configured by passing in your own cache instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would start by saying what this does. This is the way you configure a cache backend that can be used by many features: APQs, full response cache, Data Sources, etc. Notably, it is made available to all plugins.
Then after that say that the default is an unbounded cache; this default is not recommended because clients can cause servers to crash by filling memory with APQs. If you don't want to choose a specific implementation, we recommend "bounded"
.
(And link to the new cache backend page but that's another PR right? So this can be left til that PR as long as it happens...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good feedback, that's much better
packages/apollo-server-integration-testsuite/src/ApolloServer.ts
Outdated
Show resolved
Hide resolved
Issue a warning in production mode if neither the cache nor the APQ cache (persistedQueries.cache) are configured. We've provided a simple path to using a bounded cache via: #6536 The current default for AS3 is an unbounded in memory cache, which is susceptible to a DOS attack since APQs can fill up the server's memory with no limit. This warning provides an actionable recommendation to update their configuration in order to prevent this.
This commit introduces the `cache: "bounded"` option. AS3 has an unbounded cache by default, which means that a malicious client can take an open-ended amount of memory in the cache, crashing the server. Rather than breaking what has been the status quo since the beginning of the project, we've chosen to add an opt-in option in order to use a bounded cache with very little configuration. Similar to `csrfPrevention`, we've updated all examples in our docs to use this `bounded` option. This option will go away in AS4 when a bounded cache becomes the default.
Issue a warning in production mode if neither the cache nor the APQ cache (persistedQueries.cache) are configured. We've provided a simple path to using a bounded cache via: #6536 The current default for AS3 is an unbounded in memory cache, which is susceptible to a DOS attack since APQs can fill up the server's memory with no limit. This warning provides an actionable recommendation to update their configuration in order to prevent this.
@trevor-scheer if this issue only affects apollo-server-core v3.x? or is the v1.x v2.x version also affected? |
@ttmotly The issue exists in Apollo Server 2 as well. If you are still using Apollo Server 2, you can make your own InMemoryLRUCache with a chosen size ( None of the relevant features existed in Apollo Server 1. |
Right now, when the APQ cache isn't configured, the APQ feature uses Apollo Server's cache which is unbounded by default.
csrfPrevention
).cache: "bounded"
as typical usage in all docs examplescache: "bounded"
in AS4 will be to simply delete that configuration since it will be the default.