Title: M2MToken.fromJwtPayload drops custom claims by forcing claims to null · Issue #8680 · clerk/javascript · GitHub
Open Graph Title: M2MToken.fromJwtPayload drops custom claims by forcing claims to null · Issue #8680 · clerk/javascript
X Title: M2MToken.fromJwtPayload drops custom claims by forcing claims to null · Issue #8680 · clerk/javascript
Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk support via email or Discord (if you hav...
Open Graph Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
X Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
Opengraph URL: https://github.com/clerk/javascript/issues/8680
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"M2MToken.fromJwtPayload drops custom claims by forcing claims to null","articleBody":"### Preliminary Checks\n\n- [x] I have reviewed the documentation: https://clerk.com/docs\n\n- [x] I have searched for existing issues: https://github.com/clerk/javascript/issues\n\n- [x] I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)\n\n- [x] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.\n\n\n### Reproduction\n\nhttps://github.com/rubenqba/clerk-m2m-jwt-claims-issue\n\n### Publishable key\n\npk_test_Y3V0ZS1jcmF5ZmlzaC02Mi5jbGVyay5hY2NvdW50cy5kZXYk\n\n### Description\n\n**Steps to reproduce:**\n\n1. Create a machine-to-machine token in JWT format with custom claims, for example `permissions`.\n2. Verify the token with `@clerk/backend` using `client.m2m.verify({ token })`.\n3. Inspect the returned `M2MToken` object.\n4. Compare the verified result with the original JWT payload.\n\n**Expected behavior:**\n\nThe returned `M2MToken` should preserve the custom claims present in the JWT payload, or the SDK/documentation should explicitly state that custom claims are intentionally discarded for JWT-format M2M tokens.\n\n**Actual behavior:**\n\nThe returned `M2MToken` always has `claims = null` in the JWT verification path, even when the JWT itself clearly includes custom claims.\n\nThis confirms that the issue is not in token issuance, but in the transformation path inside `M2MToken.fromJwtPayload()`.\n\n**Evidence in source code:**\n\nThe issue appears to be in the Backend SDK transformation logic:\n\n- [packages/backend/src/api/resources/M2MToken.ts](https://github.com/clerk/javascript/blob/b07afc4b3e8a43232fe6cee4fb19a8c62d4bb09b/packages/backend/src/api/resources/M2MToken.ts#L54)\n- `M2MToken.fromJwtPayload()`\n\nThat method currently maps the JWT payload into an `M2MToken` and explicitly sets `claims` to `null`.\n\nThe JWT verification path appears to go through:\n\n- [packages/backend/src/api/endpoints/M2MTokenApi.ts](https://github.com/clerk/javascript/blob/b07afc4b3e8a43232fe6cee4fb19a8c62d4bb09b/packages/backend/src/api/endpoints/M2MTokenApi.ts#L194)\n\nFor JWT-format M2M tokens, verification succeeds, but the returned object loses custom claims during the `M2MToken.fromJwtPayload()` transformation.\n\nI also verified that the JWT itself does include the custom claims. Example token payload visible [here](https://jwt.io/#token=eyJhbGciOiJSUzI1NiIsImtpZCI6Imluc18yekVjSXlGc2NHUDE3UlNLNXFnajl3SUp1aUIiLCJ0eXAiOiJKV1QifQ.eyJwZXJtaXNzaW9ucyI6WyJyZWFkOnVzZXJzIiwicmVhZDpvcmRlcnMiXSwiaXNzIjoiaHR0cHM6Ly9jdXRlLWNyYXlmaXNoLTYyLmNsZXJrLmFjY291bnRzLmRldiIsInN1YiI6Im1jaF8zRUhRS2t5VG1jYUNPeHJmZFVWYmFXelRmVWYiLCJhdWQiOlsibWNoXzNFSGpJNHN1QlRMbDQyYXhtNUppcXlVUDJoZCJdLCJzY29wZXMiOiJtY2hfM0VIakk0c3VCVExsNDJheG01SmlxeVVQMmhkIiwianRpIjoibXRfNmEwZGRiNzIzNjE1OWMwOGQwZWM3ZmU0OTQxY2VhMDgiLCJpYXQiOjE3Nzk5MjAxNzksImV4cCI6MTc3OTkyMDE4OX0.NdThLJwvPRGbyHzky9YDdXUaccj-uHvmBYTkM6pG7XsWhTASksfBB0LMlFDGQobtmoVlh5rOG-R3C59_AsTp-ynqpwidpLt4j4BRW0SuEPdlVCU1haWaZXFO2eX3JcF0JQ1BW0G_B1DjY5sunmqWvf4MGUCUX70wDpyKs_WXpZgZoyH8yeIjowY8PddqDIVwLXChzmUvZ-0y8gQsUT0nyUxuTs82TjKKUmLmYDgJbFWJ1FsgWzGPFUT90vpKP2Wg1M8p_BGxAunG4cIXPYXdnmorB0Gz1259CKQaEnrALHV53TThWqinLiZ3F60Q9LZL-muWZgHuJG5IEwokLcpv_w):\n\nThat token payload includes:\n\n- `permissions`\n- `iss`\n- `sub`\n- `aud`\n- `scopes`\n- `jti`\n- `iat`\n- `exp`\n\nSo the loss of claims happens after decoding/verifying the JWT, during SDK mapping.\n\n**Impact:**\n\n- Applications cannot rely on `M2MToken.claims` when using JWT-format M2M tokens.\n- Authorization flows based on custom claims break silently.\n- This creates inconsistent behavior between the JWT payload and the verified SDK object.\n- It is especially confusing because verification succeeds, but claim data is dropped.\n\n**Related PRs:**\n\nFrom the implementation history, it looks like this behavior appears to have been introduced when JWT support for M2M verification was added:\n\n- https://github.com/clerk/javascript/pull/7883\n- https://github.com/clerk/javascript/pull/7955\n\n\n### Environment\n\n```Shell\nSystem:\n OS: macOS 26.5\n CPU: (10) arm64 Apple M5\n Memory: 82.28 MB / 24.00 GB\n Shell: 5.9 - /bin/zsh\n Binaries:\n Node: 24.15.0 - $HOME/.local/state/fnm_multishells/71323_1779899590505/bin/node\n npm: 11.12.1 - $HOME/.local/state/fnm_multishells/71323_1779899590505/bin/npm\n pnpm: 11.3.0 - $HOME/Library/pnpm/pnpm\n Browsers:\n Chrome: 148.0.7778.181\n Safari: 26.5\n npmPackages:\n @eslint/js: ^10.0.1 => 10.0.1 \n @typescript-eslint/eslint-plugin: ^8.59.4 => 8.59.4 \n @typescript-eslint/parser: ^8.59.4 => 8.59.4 \n @typescript-eslint/utils: ^8.59.4 => 8.59.4 \n eslint: ^10.4.0 => 10.4.0 \n husky: ^9.1.7 => 9.1.7 \n lint-staged: ^17.0.5 => 17.0.5 \n prettier: ^3.8.3 => 3.8.3 \n turbo: ^2.9.14 => 2.9.14 \n typescript: ^6.0.3 => 6.0.3 \n typescript-eslint: ^8.59.4 => 8.59.4 \n zod: ^4.4.3 => 4.4.3\n```","author":{"url":"https://github.com/rubenqba","@type":"Person","name":"rubenqba"},"datePublished":"2026-05-27T23:51:11Z","url":"https://github.com/clerk/javascript/issues/8680"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fd1a0450-b3a4-53ca-cc60-c53f14286283 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 89F4:370E32:122164A:18BFB47:6AFB6B61 |
| html-safe-nonce | 8250100d6d5b55772861e2ebcbfbeb99ea4549e8043d344e7c2022b501377a9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUY0OjM3MEUzMjoxMjIxNjRBOjE4QkZCNDc6NkFGQjZCNjEiLCJ2aXNpdG9yX2lkIjoiNTQ0NzUyMjA0NjU1NDM2ODg2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 72764795d40a3ceb6a259edda77a7540d239f6fdffa1d2289dd9f61c928f9298 |
| hovercard-subject-tag | issue:4536551611 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clerk/javascript/8680/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f2e3fb95382359713851e2350db564d61bb3611b9a4ef2a0f48ca37e2c0eabb0/clerk/javascript/issues/8680 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f2e3fb95382359713851e2350db564d61bb3611b9a4ef2a0f48ca37e2c0eabb0/clerk/javascript/issues/8680 |
| og:image:alt | Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rubenqba |
| hostname | github.com |
| expected-hostname | github.com |
| None | cca289ecd54650fcf3c0b037a58b97186dee2cc4406819d87fab93728fd83700 |
| turbo-cache-control | no-preview |
| go-import | github.com/clerk/javascript git https://github.com/clerk/javascript.git |
| octolytics-dimension-user_id | 49538330 |
| octolytics-dimension-user_login | clerk |
| octolytics-dimension-repository_id | 438331492 |
| octolytics-dimension-repository_nwo | clerk/javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 438331492 |
| octolytics-dimension-repository_network_root_nwo | clerk/javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 88808b1fae5ab8a526a73e7ce5542a10eb9d6971 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width