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
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.tsSteps to reproduce / impact
Math.randomis 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) orcrypto.getRandomValuesfor all transaction-related IDs and hashes.Acceptance criteria
Math.random()call involved in generating transaction IDs, hashes, audit IDs, and alert IDs with a CSPRNG.Math.random().toString(...).substr(2, N)chain to a length-normalised hex helper backed bycrypto.getRandomValues.