Rhys Profile picture
SWE @ Vercel on Domains | In my free time building https://t.co/gaRhpx9lkW to Google-index Discord content

Jul 2, 2024, 5 tweets

If you care about security for your NextJS app, stop using top level "use server" - it's way too easy to leak data

Top level "use server" creates endpoints for all exported functions, even if they are never used on the client

One accidental export can cause a ton of damage

Pretty much all NextJS sites that I've seen which use actions have had some form of this vulnerability on them. I've yet to find a major security issue with this yet but imo it's a matter of time

Here's an example from Buildspace's sage site where it's leaking their AI prompt

Full details in this GitHub issue -

imo creating endpoints should be a very intentional action, using top level "use server" results in it being way too easy to accidentally create endpointsgithub.com/vercel/next.js…

Additional notes:
- Actions with no parameters are far more vulnerable than ones w/ parameters due to them being encoded
- This isn't about not protecting server actions, it's about accidentally creating endpoints
- Tree shaking fixes this, although I'd still be careful about it

In scenarios where you have to use top level “use server” I’d try to limit it to one action per file so that way it is explicit that is the endpoint that’s being created

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling