Rhys Sullivan Profile picture
Jul 2, 2024 5 tweets 2 min read Read on X
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 damageImage
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 Image
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

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Rhys Sullivan

Rhys Sullivan Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(