Skip to content

bug: replace Math.random() with CSPRNG for transaction IDs and hashes #419

Description

@nanaf6203-bit

Summary

Non-cryptographic Math.random() is used to generate transaction hashes, transaction IDs, audit IDs, and alert IDs in several places where unguessable IDs are required.

Affected area

  • tests/e2e/property-purchase-flow.spec.ts (Math.random().toString(16).substring(2, 66) for tx hash)
  • src/components/dashboard/PropertyCard.tsx (mockTxHash)
  • src/components/dashboard/DataRefreshWrapper.tsx (random failure branching)
  • src/hooks/useRewardDistribution.ts (mockTxHash)
  • src/lib/batchTransaction.ts (blockNumber, success ratio, fake tx hash)
  • src/lib/secondaryMarketService.ts (tx hash and IDs)
  • src/lib/notificationService.ts, src/lib/kyc.ts, src/utils/structuredLogger.ts, src/utils/audit/transactionAudit.ts, src/utils/errorMonitoringService.ts, src/utils/security/auditLogger.ts, src/utils/security/transactionMonitor.ts

Steps to reproduce / impact

Math.random is not cryptographically secure. An attacker who can guess the seed or run the same PRNG state can collide IDs, impersonate transactions in tests, or defeat rate-limited ID-based logic. The same PRNG is also used to fake transaction hashes that downstream code might treat as canonical.

Expected behaviour

Use crypto.randomUUID() (already used in some places, e.g. src/utils/security/transactionSecurity.ts) or crypto.getRandomValues for all transaction-related IDs and hashes.

Acceptance criteria

  • Replace every Math.random() call involved in generating transaction IDs, hashes, audit IDs, and alert IDs with a CSPRNG.
  • Convert every Math.random().toString(...).substr(2, N) chain to a length-normalised hex helper backed by crypto.getRandomValues.
  • Add unit tests proving randomness is not trivial to predict (length, hex-only, unique).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't working correctlypriority/p1P1 — high priority, fix soonsecuritySecurity issue or hardening opportunity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions