Skip to content

fix(nextjs): tie forwarded machine auth to the verified token - #10947

Closed
wobsoriano wants to merge 3 commits into
mainfrom
rob/machine-auth-token-binding
Closed

wobsoriano wants to merge 3 commits into
mainfrom
rob/machine-auth-token-binding

Conversation

@wobsoriano

@wobsoriano wobsoriano commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Description

auth() used the machine auth object forwarded by clerkMiddleware() whenever the request's bearer token had a machine token prefix. It didn't check that the bearer was the token middleware verified, so getToken() could return a token middleware never saw.

Middleware now adds the token's signature to the forwarded data. It's the same HmacSHA1(token, secretKey) value middleware already sends for session tokens. auth() checks the bearer against it and throws auth_signature_invalid on a mismatch, like the session token path.

const { isAuthenticated, getToken } = await auth({ acceptsToken: 'm2m_token' });
// getToken() now always returns the token clerkMiddleware() verified

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

🤖 Generated with Claude under Rob's supervision.

auth() used the machine auth object forwarded by clerkMiddleware() for any
bearer that looked like a machine token. Include the token signature in the
encrypted request data and check the bearer against it before using an
authenticated machine auth object.
@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 990191f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clerk/nextjs Patch
@clerk/swingset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Nov 23, 2026 11:03pm UTC
mosaic-docs Ready Ready Preview Nov 23, 2026 11:03pm UTC
swingset Ready Ready Preview Nov 23, 2026 11:03pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@10947

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@10947

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@10947

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@10947

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@10947

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@10947

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@10947

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@10947

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@10947

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@10947

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@10947

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@10947

@clerk/express

npm i https://pkg.pr.new/@clerk/express@10947

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@10947

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@10947

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@10947

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@10947

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@10947

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@10947

@clerk/react

npm i https://pkg.pr.new/@clerk/react@10947

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@10947

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@10947

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@10947

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@10947

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@10947

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@10947

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@10947

commit: 990191f

This branch was successfully deployed

2 active deployments
Preview – swingset — 990191f9 Deployed Nov 23, 2026 by vercel[bot]
Preview – clerk-js-sandbox — 990191f9 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant