GUIDE 06 · WEB APPLICATIONS AND APIs
Next.js security: check APIs, Server Actions and secrets
Next.js security depends on server-side identity, object permissions and the data sent to the browser. Review Route Handlers and Server Actions as exposed entry points, keep secrets out of client bundles and test private caching behavior. The included fixture is pinned to the Next.js version recorded in its protocol.
Check your Next.js applicationSign-in, ownership verification and consent are required. Authorized scenarios, monitoring and CI require Pro or Business.
On this page
Locate the trust boundary
Client code is controlled by the caller. A server component or server action can use trusted server data, but its location does not automatically enforce authorization. Identify every entry point that accepts user input or returns private information, including endpoints called outside the rendered UI.
Authorize Server Actions and Route Handlers
Verify the session and object permissions inside each relevant server operation. The executable fixture uses a local synthetic identity header solely for testing; production must use a verified session. Its Route Handler invokes a server function and compares cross-owner access before and after an ownership check.
const actor = await requireSession();
const document = await db.document.findUnique({ where: { id } });
if (!document || document.ownerId !== actor.id) throw new Error("Forbidden");Primary sources: Primary reference 1 · Primary reference 2
Continue: Exposed .env, .git or API keys: contain the leak and verify the fix
Return only the data the browser needs
Build a minimal response DTO after authorization. Do not return internal notes, secrets or a full database record merely because a client ignores those fields. Inspect serialized responses and page data, not just visible text. Our fixture verifies that its synthetic internal field never appears in a response.
Treat NEXT_PUBLIC variables as public
Values intentionally exposed through NEXT_PUBLIC belong in client builds. Server-only environment variables must not leak through a DTO, rendered HTML, logs or error messages. Changing an environment variable may require rebuilding or redeploying the component that embeds it; verify the actual release artifact.
| Data | Destination | Rule |
|---|---|---|
| NEXT_PUBLIC_* | Client build | Public values only |
| Server secret | Server environment | Keep out of DTOs, logs and HTML |
| Server Action response | Can reach the client | Return the minimal authorized DTO |
Primary sources: Primary reference 1 · Primary reference 2
Continue: IDOR and BOLA: test access to another user’s data
Check your Next.js applicationTest private caching behavior
Test consecutive requests from A and B and an anonymous client. Private responses must not be served across identities through an inappropriate shared cache. Review the exact framework APIs and deployment configuration in use, and inspect cache-related headers alongside returned content.
Track framework and dependency versions
Record the actual deployed Next.js version and dependency inventory. A framework advisory is relevant only when its version and preconditions match. Updating a manifest without deploying the new build does not fix the running service. Retest the original scenario after the release.
Primary sources: Primary reference 1 · Primary reference 2
Use a reproducible release checklist
Build the supplied isolated fixture, run the documented requests and verify 200 for the vulnerable cross-owner branch, 403 after the fix, 200 for an owner and 401 without a recognized test identity. This checks a Route Handler calling a server function; it does not claim full browser Server Action protocol coverage.
Keep the checks in your workflow
Preserve the tested commit, fixture identities and expected outcomes. Add the supported HTTP scenarios to staging and release checks. Separate source review from dynamic scanning, and review skipped checks when a deployment changes routes, responses or authorization behavior.
Reproducible examples and downloads
All example data is synthetic. Downloads contain no active keys or customer records. Run examples only in your own isolated test environment.
Example verification record: versions, actions and observations

Questions and answers
Are Server Actions automatically private?
No. They still need appropriate authentication, authorization and input handling.
Can middleware be the only permission check?
Enforce the relevant permission in the server operation itself, using the framework’s current guidance.
Can I put a secret in NEXT_PUBLIC?
No. Treat values exposed that way as public client data.
Is a correct page UI enough?
No. Inspect direct requests, serialized responses and alternate entry points.
Does this scan inspect all source files?
No. Supported HTTP checks and dependency matching are distinct from source-code auditing.
Which Next.js version was tested?
The protocol and downloadable fixture record the actual installed version, including its limitations.
Editorial team and sources
Scantelio editorial team: methodology and limitations. Example verified: 2026-11-02.
Apply the check to your own project
Check your Next.js applicationChoose your project after signing in. No scan runs without verification and consent.
