Skip to content

HIGH: OracleService generates and writes mock/random IoT data to immutable blockchain in production #412

@Pcmhacker-piro

Description

@Pcmhacker-piro

Description

The OracleService.handleIoTRequest() method responds to IoTDataRequested blockchain events by calling generateMockIoTData(), which produces fabricated random temperature and humidity readings using a weighted random number generator — completely disconnected from any real IoT sensor. This fake data is then submitted to the blockchain via fulfillIoTData() and stored permanently. The oracle service auto-starts in production (see server.js lines 256-260).

Affected Code

backend/services/oracleService.js, lines 131-179:

  • handleIoTRequest() (line 131) — triggered by real blockchain events
  • generateMockIoTData() (line 155) — produces fake temp/humidity with Math.random()
  • fulfillIoTData() (line 181) — writes fake data to the immutable ledger
  • The mock data sets isSpoiled flag when temp > 80°F or < 32°F based on fake readings

Impact

  • Fake sensor data is permanently written to the immutable blockchain, corrupting supply chain integrity.
  • Batches can be falsely marked as isSpoiled, causing real financial loss and triggering unnecessary recalls.
  • The entire IoT verification feature becomes a liability rather than a trust mechanism.

Suggested Fix

  1. Remove generateMockIoTData() entirely — it should never run outside a local test environment.
  2. Add an explicit if (process.env.NODE_ENV === "production") throw new Error(...) guard.
  3. Implement real IoT sensor integration or disable the oracle auto-start in production unless explicitly enabled with a separate ORACLE_ENABLED=true flag.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions