Skip to content

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Dec 9, 2025

Description

Addressing issue with a codemod producing unexpected output

--- a/src/lib/errors.ts
+++ b/src/lib/errors.ts
@@ -25,7 +25,7 @@ export class AppError extends Error {
    * @param code - Machine-readable error code for categorization
    * @param statusCode - HTTP status code (default: 500)
    */
-  constructor(
+  function Object() { [native code] }(
     message: string,
     public readonly code: string,
     public readonly statusCode: number = 500

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

  • Bug Fixes
    • Enhanced security in the upgrade tool to prevent prototype pollution and ensure only intended identifiers are renamed.
  • Tests
    • Added a fixture to ensure constructors are not renamed and made transformer tests use a deterministic fallback when no transform is produced.
  • Chores
    • Released a patch entry documenting the update.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: 23191c7

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

This PR includes changesets to release 1 package
Name Type
@clerk/upgrade 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 Dec 9, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Skipped Skipped Dec 9, 2025 7:20pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Walkthrough

Patch release for @clerk/upgrade updates a codemod that aligns experimental/unstable prefixes: mappings are now immutable and renaming is restricted to explicit mappings to avoid prototype pollution. Tests adjusted to ensure no constructor renames and transformer fallback when no output is produced.

Changes

Cohort / File(s) Summary
Changeset & Release
.changeset/cute-buttons-repair.md
Declares patch release for @clerk/upgrade; documents update to codemod and security note about avoiding prototype pollution.
Codemod Security Enhancement
packages/upgrade/src/codemods/transform-align-experimental-unstable-prefixes.cjs
Replaced plain mapping with Object.freeze immutable SPECIFIC_RENAMES; tightened rename logic to only proceed when a mapping exists (uses Object.hasOwn); identifier traversal now filters to mapped names before renaming.
Tests & Fixtures
packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js, packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
Added fixture ensuring class constructors (extending Error) are not renamed; test changed to fallback to trimmed original source when transformer returns falsy (deterministic default).
Manifest
package.json
Release-related manifest change referenced by changeset (no API signature changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the new SPECIFIC_RENAMES contents for completeness.
  • Verify Object.hasOwn checks cover all renaming entry points (imports, exports, JSX attrs, identifiers).
  • Confirm tests correctly cover constructor edge-case and transformer-falsy fallback behavior.

Poem

A rabbit hops through code at night, 🐇
Freezing names to keep things right,
I guard each rename, one by one,
No prototype trickery — not a single one! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(upgrade): Make rename map prototype-safe' directly describes the core fix preventing prototype pollution in the rename mapping logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/codemod-prototype-pollution

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a4c1936 and 23191c7.

📒 Files selected for processing (2)
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js (1 hunks)
  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
packages/**/src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
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
Implement proper logging with different levels

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use real Clerk instances for integration tests

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use Prettier for code formatting across all packages

Files:

  • packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js
  • packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js
🧬 Code graph analysis (1)
packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js (3)
packages/upgrade/src/codemods/index.js (1)
  • result (61-61)
packages/upgrade/src/runner.js (1)
  • result (46-46)
packages/upgrade/src/codemods/transform-align-experimental-unstable-prefixes.cjs (1)
  • source (252-252)
⏰ 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). (29)
  • GitHub Check: Unit Tests (**)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Static analysis
  • GitHub Check: Unit Tests (shared, clerk-js, RQ)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/upgrade/src/codemods/__tests__/__fixtures__/transform-align-experimental-unstable-prefixes.fixtures.js (1)

74-98: LGTM! Test fixture correctly validates constructor preservation.

The new fixture appropriately tests that class constructors are not renamed by the codemod. The identical source and output confirm no transformation should occur for this pattern, which aligns with the PR objective to prevent prototype pollution issues.

packages/upgrade/src/codemods/__tests__/transform-align-experimental-unstable-prefixes.test.js (1)

9-9: The fallback is appropriate and does not mask transformer failures.

The transformer is designed to return undefined when no changes are made (when dirty remains false). This is documented in the JSDoc and is an intentional part of the API contract. The fallback || source.trim() correctly handles this documented behavior. For fixtures like "Does not rename class constructors" where the source equals the expected output, the transformer returns undefined, and the test correctly uses the original source as the result. This is not hiding errors; it's properly handling the intended no-op case.


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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 9, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: 23191c7

@jacekradko jacekradko enabled auto-merge (squash) December 9, 2025 19:26
@jacekradko jacekradko merged commit 1b37f2a into main Dec 9, 2025
43 checks passed
@jacekradko jacekradko deleted the fix/codemod-prototype-pollution branch December 9, 2025 19:28
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