-
Notifications
You must be signed in to change notification settings - Fork 419
chore(backend): Remove secret in favor of token in m2m response
#6542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: b70046f The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 WalkthroughWalkthroughThe 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this 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
📒 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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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 remainingsecretreferences across the codebaseI ran the grep from the original comment and found multiple
secretproperties that don’t referencemachineSecretKey,secretKeyor the deprecatedverifySecretmethod. Please review and update or remove these as appropriate:• packages/backend/src/tokens/verify.ts (line 230):
secret: stringparameter
• packages/backend/src/api/endpoints/M2MTokenApi.ts (line 44):secret: stringin request params
• packages/backend/src/api/resources/MachineSecretKey.ts (lines 3–9): class property andfromJSONmapping
• 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):secretin response type and model
• packages/backend/src/jwt/cryptoKeys.ts (line 6):pemToBuffer(secret: string)
• packages/backend/src/api/resources/JSON.ts: multiplesecretfields 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.
Description
Follow up to #6536, we decided to just remove the
secretfrom the response before we do the breaking change in the workers BAPI.See https://clerkinc.slack.com/archives/C083Q5HRJM9/p1755117726714289
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Refactor
Documentation
Tests
Chores