Skip to content

Conversation

@wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Aug 13, 2025

Description

Follow up to #6536, we decided to just remove the secret from the response before we do the breaking change in the workers BAPI.

See https://clerkinc.slack.com/archives/C083Q5HRJM9/p1755117726714289

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:

Summary by CodeRabbit

  • Refactor

    • Renamed M2M token response field from secret to token across the backend package.
    • Removed deprecated secret field from public types and JSON responses.
    • Revoked token responses now return token as undefined instead of using secret.
  • Documentation

    • Updated examples to reference result.token instead of result.secret.
  • Tests

    • Adjusted tests to expect token in responses and mocks.
  • Chores

    • Added changeset for a minor release of the backend package.

@changeset-bot
Copy link

changeset-bot bot commented Aug 13, 2025

🦋 Changeset detected

Latest commit: b70046f

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

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Minor
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing 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
Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Preview Comment Aug 13, 2025 10:02pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

📝 Walkthrough

Walkthrough

The changes rename the M2M token response field from secret to token across the @clerk/backend package. Tests in M2MTokenApi.test.ts are updated to expect token instead of secret, including revoked and deprecated paths. The public JSON interface M2MTokenJSON removes the secret property. The M2MToken resource drops the secret constructor parameter and no longer maps data.secret. A changeset marks a minor release and documents the public API change with before/after examples.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the "Integrations" page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 13, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6542

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6542

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6542

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6542

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6542

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6542

@clerk/upgrade

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

@clerk/vue

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

commit: b70046f

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/backend/src/api/__tests__/M2MTokenApi.test.ts (1)

47-51: Strengthen tests: assert that the removed “secret” field is not present.

Add a guard to catch regressions where secret might inadvertently reappear in responses.

       expect(response.id).toBe(m2mId);
       expect(response.token).toBe(m2mToken);
+      expect('secret' in response).toBe(false);
       expect(response.scopes).toEqual(['mch_1xxxxx', 'mch_2xxxxx']);
       expect(response.claims).toEqual({ foo: 'bar' });

Repeat the assertion in the other response checks within these ranges.

Also applies to: 73-77, 230-234, 256-260, 307-311, 333-337

🧹 Nitpick comments (3)
.changeset/chatty-kings-raise.md (1)

5-21: Augment migration notes with deprecation timeline and verifySecret behavior.

The Before/After snippet is clear. Consider adding:

  • A short migration note (how to upgrade, deprecation timeline if any).
  • Explicitly state that deprecated verifySecret continues to work but the response now exposes token (not secret).
  • Link to docs that reflect the change.

This helps downstream teams assess risk and migrate smoothly.

packages/backend/src/api/__tests__/M2MTokenApi.test.ts (2)

74-74: Rename test variable for clarity: m2mSecret → m2mToken.

Now that the response field is token, keep test data naming aligned to avoid confusion.

Apply this diff to rename the variable and its usages in the relevant assertions and payloads:

-  const m2mSecret = 'mt_secret_xxxxx';
+  const m2mToken = 'mt_secret_xxxxx';
@@
-    token: m2mSecret,
+    token: m2mToken,
@@
-      expect(response.token).toBe(m2mSecret);
+      expect(response.token).toBe(m2mToken);
@@
-      const response = await apiClient.m2mTokens.verifyToken({
-        token: m2mSecret,
+      const response = await apiClient.m2mTokens.verifyToken({
+        token: m2mToken,
       });
@@
-      expect(response.token).toBe(m2mSecret);
+      expect(response.token).toBe(m2mToken);
@@
-      const response = await apiClient.m2mTokens.verifyToken({
-        token: m2mSecret,
+      const response = await apiClient.m2mTokens.verifyToken({
+        token: m2mToken,
       });
@@
-      expect(response.token).toBe(m2mSecret);
+      expect(response.token).toBe(m2mToken);
@@
-      const response = await apiClient.m2mTokens.verifySecret({
-        secret: m2mSecret,
+      const response = await apiClient.m2mTokens.verifySecret({
+        secret: m2mToken,
       });
@@
-      expect(response.token).toBe(m2mSecret);
+      expect(response.token).toBe(m2mToken);
@@
-      const response = await apiClient.m2mTokens.verifySecret({
-        secret: m2mSecret,
+      const response = await apiClient.m2mTokens.verifySecret({
+        secret: m2mToken,
       });
@@
-      expect(response.token).toBe(m2mSecret);
+      expect(response.token).toBe(m2mToken);

Also applies to: 231-231, 257-257, 308-308, 334-334


286-361: Deprecated path coverage looks correct.

verifySecret remains callable for backward compatibility while returning token in the response. Good coverage. Consider adding a short comment in the test noting that verifySecret is deprecated and slated for removal, to guide future cleanups.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2db7431 and b70046f.

📒 Files selected for processing (4)
  • .changeset/chatty-kings-raise.md (1 hunks)
  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts (7 hunks)
  • packages/backend/src/api/resources/JSON.ts (0 hunks)
  • packages/backend/src/api/resources/M2MToken.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/api/resources/M2MToken.ts
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/chatty-kings-raise.md
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
**/__tests__/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
**/*

⚙️ CodeRabbit Configuration File

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Files:

  • packages/backend/src/api/__tests__/M2MTokenApi.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build Packages
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
.changeset/chatty-kings-raise.md (1)

2-2: Confirm semver: field rename on a public response type is likely major, not minor.

Replacing a property on a public JSON shape (result.secret → result.token) is a breaking change for consumers. Please confirm if this should be a major bump for @clerk/backend, or if there is guaranteed backward compatibility in place (e.g., both fields previously existed, or a compatibility layer).

Do you want me to update the changeset to major and add stronger migration notes?

packages/backend/src/api/__tests__/M2MTokenApi.test.ts (2)

151-153: LGTM: revoked responses no longer expose token.

Asserting token to be undefined after revocation is correct and aligns with the new response shape.

Also applies to: 179-181


1-363: Audit remaining secret references across the codebase

I ran the grep from the original comment and found multiple secret properties that don’t reference machineSecretKey, secretKey or the deprecated verifySecret method. Please review and update or remove these as appropriate:

• packages/backend/src/tokens/verify.ts (line 230): secret: string parameter
• packages/backend/src/api/endpoints/M2MTokenApi.ts (line 44): secret: string in request params
• packages/backend/src/api/resources/MachineSecretKey.ts (lines 3–9): class property and fromJSON mapping
• packages/backend/src/api/tests/MachineApi.test.ts (line 171): expect(response.secret)
• packages/backend/src/api/endpoints/APIKeysApi.ts (line 62) & packages/backend/src/api/resources/APIKey.ts (lines 20–40): secret in response type and model
• packages/backend/src/jwt/cryptoKeys.ts (line 6): pemToBuffer(secret: string)
• packages/backend/src/api/resources/JSON.ts: multiple secret fields in DTO definitions
• Other spots (e.g., AccountlessApplication, OAuthApplication, ExternalAccount, TestingToken, etc.)

Run:

rg '\b(secret\??:\s*string|\.secret\b)' packages/backend/src \
  | rg -v 'verifySecret|machineSecretKey|secretKey|clientSecret'

to see the full list of hits. Verify each and ensure only the intended secret fields remain.

@wobsoriano wobsoriano enabled auto-merge (squash) August 13, 2025 22:09
@wobsoriano wobsoriano merged commit d400782 into main Aug 13, 2025
39 checks passed
@wobsoriano wobsoriano deleted the rob/remove-secret-from-m2m branch August 13, 2025 22:17
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.

4 participants