Skip to content
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

feat: explicit cache: no-store in fetch #847

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export async function _request(
fetcher,
method,
url + queryString,
{ headers, noResolveJson: options?.noResolveJson },
{
headers,
noResolveJson: options?.noResolveJson,
},
{},
options?.body
)
Expand All @@ -138,7 +141,12 @@ async function _handleRequest(
let result: any

try {
result = await fetcher(url, requestParams)
result = await fetcher(url, {
...requestParams,
// UNDER NO CIRCUMSTANCE SHOULD THIS OPTION BE REMOVED, YOU MAY BE OPENING UP A SECURITY HOLE IN NEXT.JS APPS
// https://nextjs.org/docs/app/building-your-application/caching#opting-out-1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"YOU MAY BE OPENING UP A SECURITY HOLE IN NEXT.JS APPS"

there's nothing at all about that in the link provided. 🤔
maybe the comment can be expanded to actually explain what issue this would cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does in the context of NextJS, as the docs state:

The Data Cache is persistent across incoming requests and deployments unless you revalidate or opt-out.

So we have to forcefully opt-out of the cache, as it appears that GET /user may be cached just because. There's no docs on whether it's cached by the JWT, or not. We reached out to Vercel -- 0 information on that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add that to the comment? most users are likely going to do the same thing i did and look on that page you linked for something mentioning "security" directly.

cache: 'no-store',
})
} catch (e) {
console.error(e)

Expand Down
Loading