fix(workos): mandate POST server-action sign-out in Next.js skill#33
Conversation
Sign-out mutates state, so a GET route handler is unsafe (CSRF + Next.js <Link> prefetch can trigger logout). The Next.js reference now documents a POST server-action pattern, a SIGNOUT_GET_HANDLER troubleshooting entry, and a verification-step grep that fails if a GET sign-out route is generated. This is the source-side fix for the installer scaffolding an insecure GET sign-out (workos doctor flags it as SIGNOUT_GET_HANDLER).
Greptile SummaryThis PR hardens the WorkOS AuthKit Next.js reference guide against a class of sign-out CSRF/prefetch vulnerabilities by mandating POST server actions over GET route handlers. It adds inline code examples for both Server Component and Client Component sign-out patterns, a new
Confidence Score: 4/5Safe to merge; the core security guidance is correct and the audit check logic is sound. Two minor documentation clarity issues exist but do not undermine the security intent. The security guidance itself (use POST server actions, delete the GET route) is correct and the rg audit command reliably catches the most common naming patterns. Two small rough edges: the server-component code snippet omits the signOut import (an LLM installer copying just that block would get a reference error), and a parenthetical in troubleshooting step 3 could lead someone to believe swapping the form method attribute alone is sufficient. plugins/workos/skills/workos/references/workos-authkit-nextjs.md — the server-component example and troubleshooting step 3 warrant a quick read-through. Important Files Changed
|
| ```tsx | ||
| <form action={async () => { 'use server'; await signOut(); }}> | ||
| <button type="submit">Sign out</button> | ||
| </form> | ||
| ``` |
There was a problem hiding this comment.
Missing import in server-component snippet
The inline-action code block calls signOut() without showing its import. An LLM installer agent (or a developer) copying only this block would produce ReferenceError: signOut is not defined. The import is shown later in the client-component section (app/auth/actions.ts) but not here. Adding import { signOut } from '@workos-inc/authkit-nextjs'; at the top of the snippet (or in a preceding comment) would make the example self-contained.
|
|
||
| 1. Move sign-out to a POST server action (see "Sign out with a POST server action, never a GET route" above). | ||
| 2. Delete the `GET` sign-out route entirely. | ||
| 3. Ensure the sign-out `<form>` uses a server-action `action={...}` (or `method="POST"`), not `method="GET"`. |
There was a problem hiding this comment.
The parenthetical
(or method="POST") is misleading: steps 1 and 2 already say to move sign-out to a server action and delete the GET route, so at this point the form's action should point to the server-action function — there is no remaining GET route to flip to POST. Leaving the hint in implies that simply changing the method attribute on the form is an acceptable alternative, but without a corresponding POST handler the form would 405. Removing the parenthetical keeps the fix unambiguous.
| 3. Ensure the sign-out `<form>` uses a server-action `action={...}` (or `method="POST"`), not `method="GET"`. | |
| 3. Ensure the sign-out `<form>` uses a server-action `action={...}`, not `method="GET"`. |
Picks up the Next.js sign-out POST server-action guidance (workos/skills#33), so the installer agent no longer scaffolds an unsafe GET sign-out route.
) * fix: gate install success on doctor's auth-pattern security checks The installer ran build/typecheck self-correction but never ran doctor's authPatterns checks, so an insecure GET sign-out (SIGNOUT_GET_HANDLER) could pass the build and ship as a "successful" install while `workos doctor` immediately flagged it. - Add src/lib/validation/security-checks.ts: runs doctor's security subset (GET sign-out, client-leaked/in-source API keys, ungitignored .env, mixed env) against the install dir with no network. - Wire into agent-runner: the self-correction loop now feeds security findings back to the agent, and a final gate throws on error-severity findings that survive retries (success: false, non-zero exit, commit step skipped). - Point the SIGNOUT_GET_HANDLER finding at a live docs URL (old /docs/authkit/sign-out 404s). * chore(deps): bump @workos/skills to 0.6.1 Picks up the Next.js sign-out POST server-action guidance (workos/skills#33), so the installer agent no longer scaffolds an unsafe GET sign-out route. * chore: formatting * test: cover API_KEY_LEAKED_TO_CLIENT blocking path; clarify warning comment Addresses Greptile review on #175: - Add a unit test for the API_KEY_LEAKED_TO_CLIENT blocking code (a NEXT_PUBLIC_-prefixed secret in .env.local), mirroring the API_KEY_IN_SOURCE test, so a regression in the prefix/key detection is caught. - Correct the self-correction comment: warning findings ride along only when a retry is already triggered by an error or build failure; they are otherwise surfaced in the final validation report. * fix: emit retry-summary telemetry only after the security gate passes Addresses Greptile review on #175: - Move the 'agent retry summary' (passed_after_retry: true) capture below the security gate so a blocked install no longer emits a contradictory pass-after-retry event alongside 'security gate blocked install'. - Use obviously-fake fixture key strings in the spec (still satisfy the detection regex) so secrets scanners and the no-hardcoded-secrets rule stay quiet.
Problem
The Next.js AuthKit reference (read by the
workos installLLM agent) didn't pin down the sign-out pattern, so the installer scaffolded an unsafeGET /auth/signoutroute +<form method="GET">. Sign-out mutates state, so a GET handler is CSRF-exposable (<img src="/auth/signout">) and triggered by Next.js<Link>prefetch on hover.workos doctorflags it asSIGNOUT_GET_HANDLER.Changes
plugins/workos/skills/workos/references/workos-authkit-nextjs.md:'use server'action for Server Components, separateapp/auth/actions.tsmodule for client components, and "delete the GET route, don't switch it to POST".SIGNOUT_GET_HANDLERtroubleshooting entry mapping the doctor finding to the fix.Release note
This reaches
npx workos@latestusers only after a@workos/skillsrelease + a CLI dep bump (currently@workos/skills@0.6.0).Related
🤖 Generated with Claude Code