plugins/clerk-auth-master/skills/clerk-sessions-webhooks-security/SKILL.md
Use for Clerk sessions, tokens, webhooks, orgs, and security. PROACTIVELY activate for session tokens, JWT templates, getToken(), custom claims, pending sessions, multi-session UX, organizations, roles, permissions, system vs custom permissions, features/plans, MFA/passkeys/password policy/bot protection, Clerk webhooks, Svix signatures, verifyWebhook(), user/org sync, retries/replays, environment variables, custom domains, secret rotation, logs, and auth security reviews. Provides token semantics, webhook idempotency, authorization defaults, and hardening checklist.
npx skillsauth add JosiahSiegel/claude-plugin-marketplace clerk-sessions-webhooks-securityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill for Clerk's security-sensitive surfaces: sessions, JWTs, token retrieval, organizations and authorization, webhook synchronization, environment separation, and production hardening. Prioritize trust boundaries and replay-safe design.
Distinguish the token or session type before writing code:
| Surface | Use | |---|---| | Session token | Authenticates a signed-in user session | | Custom JWT template | Supplies custom claims for an external service integration | | API key | Authenticates an application/user-created key where Clerk supports API keys | | OAuth token | Authenticates OAuth access flows where enabled | | Machine-to-machine token | Authenticates service-to-service requests |
Use getToken() from the relevant Clerk auth object or hook to retrieve a session token or custom JWT template where supported. Always await it. Do not store tokens in localStorage, log them, embed them in URLs, or send them to origins that do not need them.
Treat pending sessions deliberately. Some Clerk APIs treat pending sessions as signed out by default (treatPendingAsSignedOut defaults to true in relevant server APIs). If a flow includes session tasks, MFA, verification, or other pending states, design UI and server behavior for “not fully signed in yet.”
Use custom JWT templates when an external service needs a token with particular claims, audience, or shape. Keep templates minimal. Include only claims the recipient needs, and avoid duplicating sensitive profile fields.
On the consuming service, validate according to Clerk's current docs and the service's expectations:
When a custom JWT contains organization or role context, ensure the active organization at token issuance matches the resource being accessed. Avoid long-lived authorization decisions based solely on stale claims when roles, memberships, plans, or permissions can change.
Clerk session tokens and custom JWT templates include iat, nbf, and exp. Verifiers reject tokens with reason token-not-active-yet when nbf is in the future, and token-expired when exp has passed. These failures are usually clock skew on the verifier, not real token problems. For full coverage (nbf/iat/exp semantics, Clerk's clockSkewInMs default of 5000 ms in verifyToken/authenticateRequest, multi-language leeway settings, container/WSL2/Docker Desktop time fix recipes, and a clock-skew-vs-real-expiry decision tree) load the dedicated clerk-clock-skew-jwt skill.
Authorization must be explicit and organization-scoped where relevant. A signed-in user is not automatically authorized for every organization resource.
Recommended defaults:
Important nuance: server-side has() works for Custom Permissions. Clerk System Permissions are not in session token claims, so check the user's Role where Clerk requires it. Do not assume every Dashboard permission string is valid in every server-side check.
Clerk user data can include multiple metadata categories. Define source of truth before syncing or authorizing:
Do not grant admin access from user-controlled metadata. For role and org authorization, use Clerk organization membership/role/permission state or trusted application records.
Clerk webhooks are delivered through Svix. Treat every incoming webhook as forged until verification succeeds. Use Clerk's verifyWebhook() helper or Svix verification libraries as documented for the runtime.
Webhook rules:
2xx only after the event has been safely accepted or durably queued; 4xx, 5xx, or no response can trigger retries.The event payload includes fields such as type, data, object, timestamp, and instance_id. For user.* events, data represents the Clerk User object. Billing events have their own docs and should be handled with the same verification and idempotency rules.
Use webhooks for asynchronous synchronization, not synchronous onboarding gates. Clerk documents webhooks as asynchronous and eventually consistent; delivery can fail, retry, or be replayed. A user should not be unable to proceed solely because a webhook has not populated an application database row yet.
Persist a durable processed-event record or deterministic checkpoint before side effects. Common patterns:
clerk_webhook_events(event_id unique, type, instance_id, received_at, processed_at, status) for event deduplication.user.created and user.updated.user.deleted instead of destructive cascades unless explicitly required and recoverable.(org_id, user_id) depending on payload guarantees.instance_id when multiple Clerk instances or environments can hit the same infrastructure.Design for out-of-order updates by storing Clerk updated_at/event timestamp checkpoints when available. Do not let an older replay overwrite newer application state.
Only sync data the application needs. Avoid cloning the entire Clerk user object into the database by default. Common useful fields:
Never sync secrets or tokens. Treat emails and profile data as personal data subject to deletion/export obligations.
Common Clerk environment categories:
pk_test_ or pk_live_).sk_test_ or sk_live_).whsec_...).Keep development, staging, preview, and production instances separate when the risk profile requires it. Never mix a production secret key with a development publishable key. Rotate secrets after accidental exposure and review logs for token leakage.
Rotation checklist:
Choose account security controls based on product risk:
Apply the strongest checks to endpoints that change roles, memberships, secrets, billing, API keys, or organization settings.
Monitor:
Log enough request context to debug without leaking secrets: route, environment, Clerk instance ID, user ID/org ID when verified, token type, status code, and correlation ID. Redact tokens, session IDs, cookies, webhook signatures, and secret keys.
For a Clerk security review:
tools
Use for Clerk in Next.js. PROACTIVELY activate for @clerk/nextjs setup, App Router auth()/currentUser(), clerkMiddleware(), proxy.ts/middleware.ts, createRouteMatcher(), protected pages/layouts/Route Handlers/Server Actions/API routes/tRPC, auth.protect() role/permission/token checks, ClerkProvider placement, server-only clerkClient, Link prefetch, redirects, 401/404 auth failures, custom domains, __clerk proxy paths, and deployment gotchas. Provides file patterns, server/client boundary rules, matcher templates, and production checks.
development
Use for Clerk frontend auth flows. PROACTIVELY activate for React, JavaScript, Vue, Nuxt, Astro, Expo, React Router, TanStack React Start, or SPA setup; ClerkProvider and publishable-key wiring; SignIn/SignUp/UserButton/UserProfile/OrganizationSwitcher; custom useUser/useAuth/useClerk/useSignIn/useSignUp/useSession/useOrganization flows; multi-session UX; cross-origin getToken() fetches; loading states, redirects, routing, CORS/cookies, or hydration bugs. Provides SDK selection, UI patterns, token-fetch templates, and frontend gotchas.
development
Use for Clerk dev/prod readiness, deployment, and multi-language implementation planning. PROACTIVELY activate for environment variables, pk_test/sk_test vs pk_live/sk_live, local dev, preview/staging/prod instances, domains/DNS, redirects, OAuth credentials, custom domains/proxy, authorizedParties, CSP, CORS/cookies, webhooks/tunnels, Vercel/Netlify/Cloudflare/API gateways, monitoring/troubleshooting, and backends in Node/Express/Fastify, Python/FastAPI/Django/Flask, Go, Ruby/Rails, Java/Spring, .NET, PHP/Laravel. Provides checklists, rollout plans, and language-portable patterns.
development
Use for Clerk JWT and session token clock-skew issues. PROACTIVELY activate for "token-not-active-yet", "JWT cannot be used prior to not before", token-expired, nbf/iat/exp claim failures, clockSkewInMs in verifyToken/authenticateRequest, local dev container/WSL2/Docker Desktop time drift, NTP misconfiguration, paused VM clock, serverless cold-start clock issues, custom JWT template verification leeway across Node/Python/Go/Ruby/Java/.NET/PHP, debugging iat vs server-time delta, and separating real expiry from clock skew. Provides nbf/iat/exp semantics, Clerk and library clock-tolerance defaults, container time fix recipes, multi-language leeway patterns, diagnostics, and gotchas.