Skip to content

Missing let/const Declarations Create Implicit Globals Causing Silent Data Corruption #60

@rishab11250

Description

@rishab11250

Severity

Critical — Silently corrupts leaderboard data without any error

Location

scripts/sync-leaderboard.js:100, 104, 145, 149, 190, 194

Description

Variables are assigned without declaration keywords. The file lacks "use strict",
so these become properties on the global object:

dailyData = JSON.parse(JSON.stringify(overallData));   // implicit global
previousData = [];                                      // implicit global
weeklyData = JSON.parse(JSON.stringify(overallData));   // implicit global
monthlyData = JSON.parse(JSON.stringify(overallData));  // implicit global

If code paths run in parallel (Promise.all, async), shared global state causes
silent data corruption — wrong scores, swapped rankings, duplicate entries —
without any error being thrown.

Why It Matters

  • Silent corruption is worse than a crash — users see incorrect rankings
  • The sync script is the backbone of the entire application
  • Three parallel blocks (daily/weekly/monthly) share the same implicit globals
  • "use strict" would make this an immediate runtime error

Fix

"use strict";
let dailyData = JSON.parse(JSON.stringify(overallData));
let previousData = [];
let weeklyData = JSON.parse(JSON.stringify(overallData));
let monthlyData = JSON.parse(JSON.stringify(overallData));

Metadata

Metadata

Assignees

Labels

BackendTask mainly involving backendlevel:beginnerIndicates the difficultytype:bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions