Skip to content

fix(backend): Clock skew of 0 should not fall back#8359

Merged
dominic-clerk merged 3 commits intomainfrom
dc-clock-skew-zero
Apr 21, 2026
Merged

fix(backend): Clock skew of 0 should not fall back#8359
dominic-clerk merged 3 commits intomainfrom
dc-clock-skew-zero

Conversation

@dominic-clerk
Copy link
Copy Markdown
Contributor

@dominic-clerk dominic-clerk commented Apr 20, 2026

Description

Because 0 is falsy the current code fell back to the default value when the clock skew was configured to 0. This changes the syntax to fall back on null-ish values which 0 is not.

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:

Because 0 is falsy the current code fell back to the default value when
the clock skew was configured to 0. This changes the syntax to fall back
on null-ish values which 0 is not.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: b6571c6

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

This PR includes changesets to release 10 packages
Name Type
@clerk/backend Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router 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
Copy Markdown

vercel bot commented Apr 20, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Apr 20, 2026 5:29pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 20, 2026

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: b6571c6

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 983c696a-327b-4b84-9997-b441bc296e15

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa73e2 and b6571c6.

📒 Files selected for processing (2)
  • packages/backend/src/jwt/__tests__/verifyJwt.test.ts
  • packages/backend/src/jwt/verifyJwt.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/backend/src/jwt/verifyJwt.ts

📝 Walkthrough

Walkthrough

Replaced the previous clockSkew fallback in packages/backend/src/jwt/verifyJwt.ts so that clockSkewInMs is used when it is a finite numeric value (including 0); the default DEFAULT_CLOCK_SKEW_IN_MS is used only when clockSkewInMs is not a finite number (e.g., undefined, NaN, Infinity). Added tests in packages/backend/src/jwt/__tests__/verifyJwt.test.ts covering expiry behavior for clockSkewInMs values 0, omitted (default), NaN, and Infinity (including advancing system time in one test). Added a changeset .changeset/wacky-dryers-hammer.md documenting a patch bump for @clerk/backend and the 0 clock skew behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main bug fix: changing clock skew fallback logic to preserve the value 0 instead of treating it as falsy.
Description check ✅ Passed The description is directly related to the changeset, explaining the bug (0 being falsy causing unwanted fallback) and the fix (using nullish checking instead of logical OR).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/backend/src/jwt/verifyJwt.ts`:
- Line 134: The resolved clockSkew value currently uses nullish coalescing but
can remain NaN; before calling assertExpirationClaim, assertActivationClaim, and
assertIssuedAtClaim validate that clockSkew (the const clockSkew variable) is a
finite number (e.g., Number.isFinite(clockSkew)), and if not replace it with
DEFAULT_CLOCK_SKEW_IN_MS or throw a descriptive error; update the code around
the clockSkew assignment so callers passing NaN cannot bypass claim checks by
ensuring a finite skew is passed into
assertExpirationClaim/assertActivationClaim/assertIssuedAtClaim.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 478f1c59-4092-4cbe-828b-319201b9cd77

📥 Commits

Reviewing files that changed from the base of the PR and between d7758e3 and 0cdc524.

📒 Files selected for processing (2)
  • .changeset/wacky-dryers-hammer.md
  • packages/backend/src/jwt/verifyJwt.ts

Comment thread packages/backend/src/jwt/verifyJwt.ts Outdated
Copy link
Copy Markdown
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

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

Good enhancement, but we should add tests for this

Copy link
Copy Markdown
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

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

thanks for the tests!

@dominic-clerk dominic-clerk merged commit abaa339 into main Apr 21, 2026
42 checks passed
@dominic-clerk dominic-clerk deleted the dc-clock-skew-zero branch April 21, 2026 05:51
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.

3 participants