Skip to content

fix(core): harden token amount validation#2340

Open
FidelCoder wants to merge 1 commit into
x402-foundation:mainfrom
FidelCoder:fix/convert-token-amount-redos
Open

fix(core): harden token amount validation#2340
FidelCoder wants to merge 1 commit into
x402-foundation:mainfrom
FidelCoder:fix/convert-token-amount-redos

Conversation

@FidelCoder
Copy link
Copy Markdown

Summary

Fixes #2090.

Replaces the decimal validation regex in convertToTokenAmount() with a linear validator to avoid ReDoS-style backtracking on long invalid input.

Changes

  • Preserve valid integer, decimal, trailing-decimal, and negative amount behavior.
  • Keep rejecting scientific notation and malformed numeric strings.
  • Add regression coverage for long adversarial invalid input.

Tests

  • git diff --check
  • Not run: pnpm --filter @x402/core test -- test/unit/utils/utils.test.ts because local Node is v18.19.1 and pnpm requires Node v22.13+
  • Not run: pnpm --filter @x402/core lint:check because local Node is v18.19.1 and pnpm requires Node v22.13+
  • Not run: pnpm --filter @x402/core format:check because local Node is v18.19.1 and pnpm requires Node v22.13+
  • Not run: pnpm --filter @x402/core build because local Node is v18.19.1 and pnpm requires Node v22.13+

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@FidelCoder is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added typescript sdk Changes to core v2 packages labels May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden convertToTokenAmount() input validation regex against ReDoS-style backtracking

1 participant