Skip to content

fix: prevent public key validation ReDoS - #1417

Merged
dannyhw merged 2 commits into
mainfrom
dannyhw/fix-public-key-redos
Jul 28, 2026
Merged

fix: prevent public key validation ReDoS#1417
dannyhw merged 2 commits into
mainfrom
dannyhw/fix-public-key-redos

Conversation

@dannyhw

@dannyhw dannyhw commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • simplify public-key delimiter validation to remove ambiguous overlapping regex quantifiers
  • add a regression test covering a large malformed near-match
  • exercise resolver validation with an existing real 4096-bit RSA fixture, CRLF PEM formatting, a truncated key, and a genuine PKCS#1 variant
  • add a patch changeset for @callstack/repack

Root cause

The existing \s*[\s\S]+?\s* expression allowed the JavaScript regex engine to partition an internal whitespace run in many ways before failing to find the PEM footer. Because ScriptLocator.publicKey can come from resolver-provided runtime metadata and had no length bound, malformed input could block the JavaScript thread with polynomial backtracking.

This addresses code-scanning alert #10 (js/polynomial-redos).

Compatibility and impact

The replacement is language-equivalent to the previous validator: both accept any non-empty content between the existing BEGIN PUBLIC KEY and END PUBLIC KEY markers after trimming. The public API, normalization, errors, native verification, and accepted input set are unchanged. Matching malformed near-misses is now linear.

No migration or user action is required.

Test plan

  • pnpm --filter @callstack/repack test -- --watchman=false ScriptManager.test.ts
  • pnpm --filter @callstack/repack typecheck
  • pnpm biome check packages/repack/src/modules/ScriptManager/normalizePublicKey.ts packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts
  • commit hook: repository-wide Biome check (457 files)

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8bfbf89

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

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init 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

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
repack-website Ready Ready Preview, Comment Jul 27, 2026 10:36pm

Request Review

@dannyhw
dannyhw marked this pull request as ready for review July 27, 2026 22:32
@dannyhw

dannyhw commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

@MikitasK can you take a look?

@dannyhw
dannyhw marked this pull request as draft July 27, 2026 22:36
@dannyhw
dannyhw marked this pull request as ready for review July 27, 2026 22:37

@MikitasK MikitasK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM ✅
reviewed these changes against #826 & #1382 and haven't found any regressions in multiple-public-keys contract 👌

@dannyhw
dannyhw merged commit 376c996 into main Jul 28, 2026
10 checks passed
@dannyhw
dannyhw deleted the dannyhw/fix-public-key-redos branch July 28, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants