Stack

How to security test a SvelteKit app

Updated

Test SvelteKit at +page.server.ts load functions and +page.server.ts actions: a load returns data straight into the page payload, and an action receives whatever the form posts. Then confirm hooks.server.ts covers every route it claims to.

Where this class of bug actually lives in a SvelteKit app

  • Load over-fetching. Returning a whole row from a load serializes every field into the page data, including columns the UI never renders.
  • Form actions. The action is a POST endpoint. Reading formData.get('orgId') instead of deriving the tenant from locals is the bug.
  • hooks.server.ts coverage. A handle hook runs for every request, but its matcher logic decides what it protects — and a path added after the regex was written is not covered.
  • Public env. Anything in $env/static/public is shipped to the browser and readable in the bundle.

What to try first

  1. View source on a logged-in page and read the serialized __sveltekit data for fields the UI hides.
  2. Replay each form action with a changed id from the body.
  3. Request every route with no cookie and confirm the hook redirects.
  4. Grep the build output for anything in the public env module that looks like a key.

A reproduction you can keep

The data payload is the first read, the action replay is the proof:

Read the load payload, replay the action
# what the page ships
curl -sS https://staging.example.com/dashboard -H 'Cookie: session=***' \
  | grep -o '__sveltekit[^<]*' | head -c 600

# replay the action as another tenant
curl -sS -i 'https://staging.example.com/account?/update' \
  -X POST -H 'Cookie: session=***' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data 'name=Alice&orgId=org_victim'

# vulnerable: payload carries adminNote; the action writes to org_victim
# fixed: payload carries only rendered fields; action ignores orgId

What "fixed" has to look like

Load must return a projection, not the row, and actions must read the tenant from event.locals set by the hook. The fixed result is a payload containing only what the page renders, and an action that returns 403 when the body names another tenant.

Where people get this wrong

  • A +page.ts load runs in the browser as well as on the server; putting a database call there fails or leaks depending on the adapter.
  • SvelteKit's use:enhance posts to the action from the client, so a browser-only permission check is decoration.
  • The __sveltekit payload is not stripped by the framework. Whatever load returns is public to that user.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Is a SvelteKit form action an API endpoint?

Yes. It is a POST target that any client can call directly, so it has to authorize its own inputs.

Why does hiding a field in the UI not protect it?

Because load already serialized the value into the page payload. Hiding is a render decision.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.